// File: /workspace/github_cpp_makefile_star2_O2/7shi[P]8086run/v1/main.cpp
// Function: shift(Operand*, int, unsigned char*)
inline void shift(Operand *opr, int c, uint8_t *p) {
    int val, m = opr->w ? 0x8000 : 0x80;
    switch ((p[1] >> 3) & 7) {
        case 0: // rol
            val = opr->u();
            for (int i = 0; i < c; ++i)
                val = (val << 1) | (CF = val & m);
            OF = CF ^ bool(val & m);
            *opr = val;
            break;
        case 1: // ror
            val = opr->u();
            for (int i = 0; i < c; ++i)
                val = (val >> 1) | ((CF = val & 1) ? m : 0);
            OF = CF ^ bool(val & (m >> 1));
            *opr = val;
            break;
        case 2: // rcl
            val = opr->u();
            for (int i = 0; i < c; ++i) {
                val = (val << 1) | CF;
                CF = val & (m << 1);
            }
            OF = CF ^ bool(val & m);
            *opr = val;
            break;
        case 3: // rcr
            val = opr->u();
            for (int i = 0; i < c; ++i) {
                bool f1 = val & 1, f2 = val & m;
                val = (val >> 1) | (CF ? m : 0);
                OF = CF ^ f2;
                CF = f1;
            }
            *opr = val;
            break;
        case 4: // shl/sal
            if (c > 0) {
                val = opr->u();
                for (int i = 0; i < c; ++i) {
                    val <<= 1;
                }
                *opr = opr->setf(val);
                CF = val & (m << 1);
                OF = CF != bool(val & m);
            }
            break;
        case 5: // shr
            if (c > 0) {
                val = opr->u();
                for (int i = 1; i < c; ++i) {
                    val >>= 1;
                }
                *opr = opr->setf(val >> 1);
                CF = val & 1;
                OF = val & m;
            }
            break;
        case 7: // sar
            if (c > 0) {
                val = **opr;
                for (int i = 1; i < c; ++i) {
                    val >>= 1;
                }
                *opr = opr->setf(val >> 1);
                CF = val & 1;
                OF = false;
            }
            break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
cmpb $0x0, 0x4(%rdi)
movl $0x8000, %eax           # imm = 0x8000
movl $0x80, %r15d
cmovnel %eax, %r15d
movzbl 0x1(%rdx), %eax
shrl $0x3, %eax
andl $0x7, %eax
leaq 0xd00(%rip), %rcx       # 0x5548
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x4aa2
xorl %ecx, %ecx
testl %ebp, %ebp
cmovgl %ebp, %ecx
testl %r15d, %eax
setne %dl
subl $0x1, %ecx
jb 0x4984
xorl %esi, %esi
testl %r15d, %eax
setne %sil
movb %dl, 0x12399a(%rip)     # 0x128218
leal (%rsi,%rax,2), %eax
jmp 0x4860
movq %rbx, %rdi
callq 0x4aa2
movb 0x123987(%rip), %dl     # 0x128218
xorl %ecx, %ecx
testl %ebp, %ebp
cmovgl %ebp, %ecx
subl $0x1, %ecx
jb 0x48b2
movzbl %dl, %edx
testl %r15d, %eax
leal (%rdx,%rax,2), %eax
setne %dl
setne 0x123968(%rip)          # 0x128218
jmp 0x4898
testl %r15d, %eax
setne %cl
cmpb %cl, %dl
jmp 0x498a
movq %rbx, %rdi
callq 0x4aa2
movb 0x12394b(%rip), %cl     # 0x128218
xorl %edx, %edx
testl %ebp, %ebp
cmovlel %edx, %ebp
subl $0x1, %ebp
jb 0x49ae
movl %eax, %edx
andb $0x1, %dl
testl %r15d, %eax
setne %sil
sarl %eax
testb $0x1, %cl
movl $0x0, %edi
cmovnel %r15d, %edi
orl %edi, %eax
cmpb %sil, %cl
setne 0x12390d(%rip)          # 0x128210
movb %dl, 0x12390f(%rip)     # 0x128218
movl %edx, %ecx
jmp 0x48d4
testl %ebp, %ebp
jle 0x4a56
movq %rbx, %rdi
callq 0x4436
decl %ebp
movl %eax, %r14d
sarl %eax
subl $0x1, %ebp
jae 0x491f
movq %rbx, %rdi
movl %eax, %esi
callq 0x447e
movq %rbx, %rdi
movl %eax, %esi
callq 0x4492
andb $0x1, %r14b
movb %r14b, 0x1238d0(%rip)   # 0x128218
movb $0x0, 0x1238c1(%rip)    # 0x128210
jmp 0x4a56
movq %rbx, %rdi
callq 0x4aa2
xorl %ecx, %ecx
testl %ebp, %ebp
cmovgl %ebp, %ecx
subl $0x1, %ecx
jb 0x4998
movl %eax, %edx
sarl %edx
movl %eax, %esi
andl $0x1, %esi
negl %esi
andb $0x1, %al
movb %al, 0x12389d(%rip)     # 0x128218
andl %r15d, %esi
orl %edx, %esi
movl %esi, %eax
jmp 0x4963
cmpb %dl, 0x12388e(%rip)     # 0x128218
setne 0x12387f(%rip)          # 0x128210
movq %rbx, %rdi
movl %eax, %esi
jmp 0x49b3
shrl %r15d
testl %r15d, %eax
setne %cl
cmpb %cl, 0x123871(%rip)     # 0x128218
setne 0x123862(%rip)          # 0x128210
movq %rbx, %rdi
movl %eax, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4492
testl %ebp, %ebp
jle 0x4a56
movq %rbx, %rdi
callq 0x4aa2
movl %eax, %r14d
subl $0x1, %ebp
jb 0x4a22
addl %r14d, %r14d
jmp 0x49d5
testl %ebp, %ebp
jle 0x4a56
movq %rbx, %rdi
callq 0x4aa2
decl %ebp
movl %eax, %r14d
sarl %eax
subl $0x1, %ebp
jae 0x49ed
movq %rbx, %rdi
movl %eax, %esi
callq 0x447e
movq %rbx, %rdi
movl %eax, %esi
callq 0x4492
movl %r14d, %eax
andb $0x1, %al
movb %al, 0x123802(%rip)     # 0x128218
testl %r15d, %r14d
setne 0x1237f0(%rip)          # 0x128210
jmp 0x4a56
movq %rbx, %rdi
movl %r14d, %esi
callq 0x447e
movq %rbx, %rdi
movl %eax, %esi
callq 0x4492
leal (%r15,%r15), %eax
testl %eax, %r14d
setne %al
setne 0x1237d0(%rip)          # 0x128218
testl %r15d, %r14d
setne %cl
xorb %al, %cl
movb %cl, 0x1237ba(%rip)     # 0x128210
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop