NAME=imul 1 arg
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
(pi bytes;wx $0;pi 1;pie 1)
.(pi 49f7e9)
EOF
EXPECT=<<EOF
imul r9
0x00000000 64,64,r9,~,64,rax,~,*,>>,rdx,=,r9,rax,*=,64,64,rax,~,>>,rdx,-,?{,1,1,}{,0,0,},cf,:=,of,:=
EOF
RUN

NAME=imul 2 arg
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
(pi bytes;wx $0;pi 1;pie 1)
.(pi 0fafc1)
EOF
EXPECT=<<EOF
imul eax, ecx
0x00000000 32,eax,~,32,ecx,~,*,DUP,eax,=,eax,-,?{,1,1,}{,0,0,},cf,:=,of,:=
EOF
RUN

NAME=imul 3 arg
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
(pi bytes;wx $0;pi 1;pie 1)
.(pi 4969c367666633)
EOF
EXPECT=<<EOF
imul rax, r11, 0x33666667
0x00000000 64,862348903,~,64,r11,~,*,DUP,rax,=,rax,-,?{,1,1,}{,0,0,},cf,:=,of,:=
EOF
RUN

NAME=esil x86-64 pd deinit
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
aei
aeim
wa mov rax, 11
e asm.emu=true
ar rax=33
e scr.null=true
pd 2000
e scr.null=false
ar rax
EOF
EXPECT=<<EOF
0x00000021
EOF
RUN

NAME=esil x86-64 pd deinit
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
aei
aeim
wa mov rax, 11
e asm.emu=false
ar rax=33
e scr.null=true
pd 2000
e scr.null=false
ar rax
EOF
EXPECT=<<EOF
0x00000021
EOF
RUN

NAME=esil x86-64 pd deinit
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
aei
aeim
wa mov rax, 11
e asm.emu=true
ar rax=33
e scr.null=true
pi 2000
e scr.null=false
ar rax
EOF
EXPECT=<<EOF
0x00000021
EOF
RUN

NAME=esil x86-64 imul
FILE=-
CMDS=<<EOF
e asm.bits=64
e asm.arch=x86
e analysis.arch=x86
wx 69c389000000
ao~opcode,esil
EOF
EXPECT=<<EOF
opcode: imul eax, ebx, 0x89
esilcost: 0
esil: 32,137,~,32,ebx,~,*,DUP,eax,=,eax,-,?{,1,1,}{,0,0,},cf,:=,of,:=
EOF
RUN

NAME=esil x86-64 imul emu
FILE=-
CMDS=<<EOF
e asm.bits=64
e asm.arch=x86
e analysis.arch=x86
wx 48c7c004000000
wx 48c7c305000000 @ 7
wx 69c303000000 @ 14
3aes
ar rax
EOF
EXPECT=<<EOF
0x0000000f
EOF
RUN

NAME=esil x86-64 two steps
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 48c7c004000000
wx 48c7c305000000 @ 7
pi 2
2aes
ar rax
ar rbx
EOF
EXPECT=<<EOF
mov rax, 4
mov rbx, 5
0x00000004
0x00000005
EOF
RUN

NAME=esil x86-64 aesu
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 48c7c004000000
wx 48c7c305000000 @ 7
pi 2
aesu 14
ar rax
ar rbx
EOF
EXPECT=<<EOF
mov rax, 4
mov rbx, 5
0x00000004
0x00000005
EOF
RUN

NAME=esil x86-64 aesu
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
wx 48c7c004000000
wx 48c7c305000000 @ 7
pi 2
aesu 14
ar rax
ar rbx
EOF
EXPECT=<<EOF
mov rax, 4
mov rbx, 5
0x00000004
0x00000005
EOF
RUN

NAME=esil x86-64
FILE=-
CMDS=<<EOF
?e
e asm.arch=x86
e asm.bits=64
wx 488d7768
ao~opcode,esil
EOF
EXPECT=<<EOF

opcode: lea rsi, [rdi + 0x68]
esilcost: 0
esil: 0x68,rdi,+,rsi,=
EOF
RUN

NAME=esil x86-64
FILE=-
CMDS=<<EOF
?e
e asm.arch=x86
e asm.bits=64
wx 488dbdc0fbffff
ao~opcode,esil
EOF
EXPECT=<<EOF

opcode: lea rdi, [rbp - 0x440]
esilcost: 0
esil: 0x440,rbp,-,rdi,=
EOF
RUN

NAME=esil x86-64
FILE=-
CMDS=<<EOF
?e
e asm.arch=x86
e asm.bits=64
wx c705dd40000001000000
ao~opcode,esil
EOF
EXPECT=<<EOF

opcode: mov dword [rip + 0x40dd], 1
esilcost: 12
esil: 1,0x40dd,rip,+,=[4]
EOF
RUN

NAME=eax/rax
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
e asm.bytes=true
wa mov eax, 4
e asm.esil=true
pd 1
EOF
EXPECT=<<EOF
            0x00000000      b804000000     4,rax,=
EOF
RUN

NAME=reg size bitmask
FILE=-
CMDS=<<EOF
e io.va=true
e esil.debug=true
e asm.arch=x86
e asm.bits=64
aei
aeim
aer rsp=0x00108000
.dr*
aer rdi=0xFFFFFFFFFFFFFFFF
ae rdi,rsp,=[8]
?v [rsp]
?v [rsp+4]
?v [rsp+8]
EOF
EXPECT=<<EOF
0xffffffffffffffff
0xffffffff
0x0
EOF
RUN

NAME=mem read
FILE=-
CMDS=<<EOF
e io.va=true
e esil.debug=true
e asm.arch=x86
e asm.bits=64
aei
aeim
aer rsp=0x00108000
.aer*
aer rdi=0xFFFFFFFFFFFFFFFF
ae rdi,rsp,=[8]
.aer*
ae rsp,[8],rax,=
.aer*
?v rax
EOF
EXPECT=<<EOF
0xffffffffffffffff
EOF
RUN

NAME=movsxd rax, dword [rdx + rax*4]
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
"wx 48630482"
ao~esil
EOF
EXPECT=<<EOF
esilcost: 4
esil: 32,rax,4,*,rdx,+,[4],~,rax,=
EOF
RUN

NAME=lea rax, [rdi + r13*8]
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
"wx 4a8d04ef"
ao~esil,opcode
EOF
EXPECT=<<EOF
opcode: lea rax, [rdi + r13*8]
esilcost: 0
esil: r13,8,*,rdi,+,rax,=
EOF
RUN

NAME=lea rbx, [rax + rdx]
FILE=-
CMDS=<<EOF
e asm.arch=x86
e asm.bits=64
"wx 488d1c10"
ao~opcode,esil
EOF
EXPECT=<<EOF
opcode: lea rbx, [rax + rdx]
esilcost: 0
esil: rdx,rax,+,rbx,=
EOF
RUN

NAME=ldrh instruction
FILE=-
CMDS=<<EOF
e asm.arch=arm
e asm.bits=32
wx b030dfe10101010141424344
aes
dr?r3
EOF
EXPECT=<<EOF
0x00004241
EOF
RUN


NAME=x86-64 linux syscall
FILE=bins/elf/syscall_x86
CMDS=<<EOF
e asm.bytes=0
e asm.lines.bb=0
e emu.str=1
e asm.cmt.col=30
pd 5~write
EOF
EXPECT=<<EOF
  0x004000f1      syscall     ; 1 = write (1, "Hello, world!.", 14)
EOF
RUN

NAME=x86-64 linux syscall emulation
FILE=bins/elf/syscall_x86
CMDS=<<EOF
s entry0
dr rip=$$
4aes
s. f1
as
EOF
EXPECT=<<EOF
1 = write (1, "Hello, world!.", 14)
EOF
RUN

NAME=x86-64 linux syscall emulation
FILE=bins/elf/syscall_x86
CMDS=<<EOF
s entry0
dr rip=$$
4ds
s. f1
as
EOF
EXPECT=<<EOF
1 = write (1, "Hello, world!.", 14)
EOF
RUN

NAME=cmd.esil.intr set
FILE=-
CMDS=<<EOF
e asm.bits=64
e asm.arch=x86
e analysis.arch=x86
wx b8010000000f34b801000000cd80ebfe
e cmd.esil.intr="?e SYSCALL"
10aes
EOF
EXPECT=<<EOF
SYSCALL 128 0
EOF
RUN

NAME=test_sf
FILE=-
CMDS=<<EOF
e asm.arch=x86;e asm.bits=64;s 0;aei;aer rip=0;wa test eax, eax;aer eax=-1;aes
aer 1~sf
EOF
EXPECT=<<EOF
sf = 0x00000001
EOF
RUN

NAME=neg
FILE=-
CMDS=<<EOF
wx f6dbf6df66f7dbf7db48f7db
e asm.arch=x86
e asm.bits=64
aei
aer rbx=0x300020100
aes 1; aer rbx; aer cf
aes 1; aer rbx; aer cf
aes 1; aer rbx; aer cf
aes 1; aer rbx; aer cf
aes 1; aer rbx; aer cf
EOF
EXPECT=<<EOF
0x300020100
0x00000000
0x30002ff00
0x00000001
0x300020100
0x00000001
0x3fffdff00
0x00000001
0xfffffffc00020100
0x00000001
EOF
RUN
