#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 /*<<< orphan*/ ea_alterable_na(int);
scalar_t__ is_checking(int);
int /*<<< orphan*/ printf(char *, int, ...);
int addi_handler(int opcode) {
  int op_size = (opcode >> 6) & 3;
  if (!ea_alterable_na(opcode) || op_size == 3)
    return -1;
  if (is_checking(opcode))
    return 0;
  printf("\t{\n\t\tuint%d_t result = (uint%d_t)(EV + OP);\n", 8 << op_size,
         8 << op_size);
  printf("\t\tSET_C_FLAG((uint%d_t)result < (uint%d_t)OP?1:0);\n", 8 << op_size,
         8 << op_size);
  printf("\t\tSET_X_FLAG((uint%d_t)result < (uint%d_t)OP?1:0);\n", 8 << op_size,
         8 << op_size);
  printf("\t\tSET_V_FLAG%d(EV, OP, result);\n", 8 << op_size);
  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):
<addi_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x6,%eax
and    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <ea_alterable_na@plt>
cmp    $0x0,%eax
je     1162 <addi_handler+0x32>
cmpl   $0x3,-0xc(%rbp)
jne    116e <addi_handler+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <addi_handler+0x111>
mov    -0x8(%rbp),%edi
call   1030 <is_checking@plt>
cmp    $0x0,%rax
je     118c <addi_handler+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    1241 <addi_handler+0x111>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0xc(%rbp),%ecx
mov    $0x8,%edx
shl    %cl,%edx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0xc(%rbp),%ecx
mov    $0x8,%edx
shl    %cl,%edx
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0xc(%rbp),%ecx
mov    $0x8,%edx
shl    %cl,%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addi_handler>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    %edi,%ebx
shr    $0x6,%ebx
and    $0x3,%ebx
call   1050 <ea_alterable_na@plt>
mov    $0xffffffff,%r14d
cmp    $0x3,%ebx
je     11db <addi_handler+0xab>
test   %eax,%eax
je     11db <addi_handler+0xab>
mov    %ebp,%edi
call   1030 <is_checking@plt>
xor    %r14d,%r14d
test   %rax,%rax
jne    11db <addi_handler+0xab>
mov    $0x8,%ebp
mov    %ebx,%ecx
shl    %cl,%ebp
lea    0xe87(%rip),%rdi
xor    %r14d,%r14d
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec1(%rip),%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee3(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xefd(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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