// File: Lupo-CalPoly[P]cpe315-thumbsim/execute.cpp
// Function: setCarryOverflow(int, int, OFType)
void setCarryOverflow (int num1, int num2, OFType oftype) {
  switch (oftype) {
    case OF_ADD:
      if (((unsigned long long int)num1 + (unsigned long long int)num2) ==
          ((unsigned int)num1 + (unsigned int)num2)) {
        flags.C = 0;
      }
      else {
        flags.C = 1;
      }
      if (((long long int)num1 + (long long int)num2) ==
          ((int)num1 + (int)num2)) {
        flags.V = 0;
      }
      else {
        flags.V = 1;
      }
      break;
    case OF_SUB:
      if (num1 >= num2) {
        flags.C = 1;
      }
      else if ((long long int)((unsigned long long int)num1 - (unsigned long long int)num2) ==
          (int)((unsigned int)num1 - (unsigned int)num2)) {
        flags.C = 0;
      }
      else {
        flags.C = 1;
      }
      if (((num1==0) && (num2==0)) ||
          (((long long int)num1 - (long long int)num2) ==
           ((int)num1 - (int)num2))) {
        flags.V = 0;
      }
      else {
        flags.V = 1;
      }
      break;
    case OF_SHIFT:
      // C flag unaffected for shifts by zero
      if (num2 != 0) {
        if (((unsigned long long int)num1 << (unsigned long long int)num2) ==
            ((unsigned int)num1 << (unsigned int)num2)) {
          flags.C = 0;
        }
        else {
          flags.C = 1;
        }
      }
      // Shift doesn't set overflow
      break;
    default:
      cerr << "Bad OverFlow Type encountered." << __LINE__ << __FILE__ << endl;
      exit(1);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
testl %eax, %eax
je 0xbfc8
jmp 0xbfad
movl -0x10(%rbp), %eax
subl $0x1, %eax
je 0xc01e
jmp 0xbfb7
movl -0x10(%rbp), %eax
subl $0x2, %eax
je 0xc091
jmp 0xc0c7
movslq -0x4(%rbp), %rax
movslq -0x8(%rbp), %rcx
addq %rcx, %rax
movl -0x4(%rbp), %ecx
addl -0x8(%rbp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0xbfe9
movb $0x0, 0x92fb(%rip)      # 0x152e2
jmp 0xbff0
movb $0x1, 0x92f2(%rip)      # 0x152e2
movslq -0x4(%rbp), %rax
movslq -0x8(%rbp), %rcx
addq %rcx, %rax
movl -0x4(%rbp), %ecx
addl -0x8(%rbp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0xc012
movb $0x0, 0x92d3(%rip)      # 0x152e3
jmp 0xc019
movb $0x1, 0x92ca(%rip)      # 0x152e3
jmp 0xc10f
movl -0x4(%rbp), %eax
cmpl -0x8(%rbp), %eax
jl 0xc02f
movb $0x1, 0x92b5(%rip)      # 0x152e2
jmp 0xc05a
movslq -0x4(%rbp), %rax
movslq -0x8(%rbp), %rcx
subq %rcx, %rax
movl -0x4(%rbp), %ecx
subl -0x8(%rbp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0xc051
movb $0x0, 0x9293(%rip)      # 0x152e2
jmp 0xc058
movb $0x1, 0x928a(%rip)      # 0x152e2
jmp 0xc05a
cmpl $0x0, -0x4(%rbp)
jne 0xc066
cmpl $0x0, -0x8(%rbp)
je 0xc07f
movslq -0x4(%rbp), %rax
movslq -0x8(%rbp), %rcx
subq %rcx, %rax
movl -0x4(%rbp), %ecx
subl -0x8(%rbp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0xc088
movb $0x0, 0x925d(%rip)      # 0x152e3
jmp 0xc08f
movb $0x1, 0x9254(%rip)      # 0x152e3
jmp 0xc10f
cmpl $0x0, -0x8(%rbp)
je 0xc0c5
movslq -0x4(%rbp), %rax
movslq -0x8(%rbp), %rcx
shlq %cl, %rax
movl -0x4(%rbp), %edx
movl -0x8(%rbp), %ecx
shll %cl, %edx
movl %edx, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0xc0bc
movb $0x0, 0x9228(%rip)      # 0x152e2
jmp 0xc0c3
movb $0x1, 0x921f(%rip)      # 0x152e2
jmp 0xc0c5
jmp 0xc10f
movq 0x8f22(%rip), %rdi      # 0x14ff0
leaq 0x247b(%rip), %rsi      # 0xe550
callq 0x21d0
movq %rax, %rdi
movl $0x57, %esi
callq 0x2360
movq %rax, %rdi
leaq 0x247e(%rip), %rsi      # 0xe56f
callq 0x21d0
movq %rax, %rdi
movq 0x8eb0(%rip), %rsi      # 0x14fb0
callq 0x2200
movl $0x1, %edi
callq 0x2260
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)