#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int ea_mode(int);
int /*<<< orphan*/ printf(char *, int, ...);
int addq_handler(int opcode) {
  int value;
  int op_size = (opcode >> 6) & 3;
  value = (opcode >> 9) & 7;
  if (!value)
    value = 8;
  if (ea_mode(opcode) == 1)
    printf("\t{\n\t\tuint32_t result = (uint32_t)(EV + %d);\n", value);
  else {
    printf("\t{\n\t\tuint%d_t result = (uint%d_t)(EV + %d);\n", 8 << op_size,
           8 << op_size, value);
    printf("\t\tSET_C_FLAG((uint%d_t)result < (uint%d_t)%d?1:0);\n",
           8 << op_size, 8 << op_size, value);
    printf("\t\tSET_X_FLAG((uint%d_t)result < (uint%d_t)%d?1:0);\n",
           8 << op_size, 8 << op_size, value);
    printf("\t\tSET_V_FLAG%d(EV, %d, result);\n", 8 << op_size, value);
    printf("\t\tSET_N_FLAG%d(result);\n", 8 << op_size);
    printf("\t\tSET_Z_FLAG%d(result);\n", 8 << op_size);
  }
  return 0;
}


x86 assembly (clang, -O0):
<addq_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x6,%eax
and    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x9,%eax
and    $0x7,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1154 <addq_handler+0x34>
movl   $0x8,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <ea_mode@plt>
cmp    $0x1,%eax
jne    117b <addq_handler+0x5b>
mov    -0x8(%rbp),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <addq_handler+0x115>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0xc(%rbp),%ecx
mov    $0x8,%edx
shl    %cl,%edx
mov    -0x8(%rbp),%ecx
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0xc(%rbp),%ecx
mov    $0x8,%edx
shl    %cl,%edx
mov    -0x8(%rbp),%ecx
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0xc(%rbp),%ecx
mov    $0x8,%edx
shl    %cl,%edx
mov    -0x8(%rbp),%ecx
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0x8(%rbp),%edx
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addq_handler>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    %edi,%ebp
shr    $0x9,%ebp
and    $0x7,%ebp
mov    $0x8,%r14d
cmove  %r14d,%ebp
call   1040 <ea_mode@plt>
cmp    $0x1,%eax
jne    114d <addq_handler+0x2d>
lea    0xeb7(%rip),%rdi
mov    %ebp,%esi
jmp    11c5 <addq_handler+0xa5>
shr    $0x6,%bl
mov    %ebx,%ecx
shl    %cl,%r14d
lea    0xed1(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf06(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf24(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf32(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf3a(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"\09{\0A\09\09uint32_t result = (uint32_t)(EV + %d);\0A\00"
@.str.1 = [45 x i8] c"\09{\0A\09\09uint%d_t result = (uint%d_t)(EV + %d);\0A\00"
@.str.2 = [52 x i8] c"\09\09SET_C_FLAG((uint%d_t)result < (uint%d_t)%d?1:0);\0A\00"
@.str.3 = [52 x i8] c"\09\09SET_X_FLAG((uint%d_t)result < (uint%d_t)%d?1:0);\0A\00"
@.str.4 = [33 x i8] c"\09\09SET_V_FLAG%d(EV, %d, result);\0A\00"
@.str.5 = [25 x i8] c"\09\09SET_N_FLAG%d(result);\0A\00"
@.str.6 = [25 x i8] c"\09\09SET_Z_FLAG%d(result);\0A\00"
define i32 @addq_handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = ashr i32 %5, 6
%7 = and i32 %6, 3
store i32 %7, i32* %4
%8 = load i32, i32* %2
%9 = ashr i32 %8, 9
%10 = and i32 %9, 7
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %1
store i32 8, i32* %3
br label %14
14: ; preds = %13, %1
%15 = load i32, i32* %2
%16 = call i32 @ea_mode(i32 %15)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %3
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %50
21: ; preds = %14
%22 = load i32, i32* %4
%23 = shl i32 8, %22
%24 = load i32, i32* %4
%25 = shl i32 8, %24
%26 = load i32, i32* %3
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %25, i32 %26)
%28 = load i32, i32* %4
%29 = shl i32 8, %28
%30 = load i32, i32* %4
%31 = shl i32 8, %30
%32 = load i32, i32* %3
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %31, i32 %32)
%34 = load i32, i32* %4
%35 = shl i32 8, %34
%36 = load i32, i32* %4
%37 = shl i32 8, %36
%38 = load i32, i32* %3
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %37, i32 %38)
%40 = load i32, i32* %4
%41 = shl i32 8, %40
%42 = load i32, i32* %3
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32, i32* %4
%45 = shl i32 8, %44
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %4
%48 = shl i32 8, %47
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %21, %18
ret i32 0
}

LLVM IR (-O2):
@.str = [45 x i8] c"\09{\0A\09\09uint32_t result = (uint32_t)(EV + %d);\0A\00"
@.str.1 = [45 x i8] c"\09{\0A\09\09uint%d_t result = (uint%d_t)(EV + %d);\0A\00"
@.str.2 = [52 x i8] c"\09\09SET_C_FLAG((uint%d_t)result < (uint%d_t)%d?1:0);\0A\00"
@.str.3 = [52 x i8] c"\09\09SET_X_FLAG((uint%d_t)result < (uint%d_t)%d?1:0);\0A\00"
@.str.4 = [33 x i8] c"\09\09SET_V_FLAG%d(EV, %d, result);\0A\00"
@.str.5 = [25 x i8] c"\09\09SET_N_FLAG%d(result);\0A\00"
@.str.6 = [25 x i8] c"\09\09SET_Z_FLAG%d(result);\0A\00"
define i32 @addq_handler(i32 %0) {
%2 = lshr i32 %0, 9
%3 = and i32 %2, 7
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i32 8, i32 %3
%6 = tail call i32 @ea_mode(i32 %0)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %20
10: ; preds = %1
%11 = lshr i32 %0, 6
%12 = and i32 %11, 3
%13 = shl nuw nsw i32 8, %12
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %13, i32 %5)
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %13, i32 %5)
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %13, i32 %5)
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %13, i32 %5)
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %13)
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %13)
br label %20
20: ; preds = %10, %8
ret i32 0
}