#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 begin_function(char *);
scalar_t__ ea_address(int);
int ea_mode(int);
scalar_t__ get_ea(char *, int, int, int);
int invalid();
scalar_t__ print_bus_read_(char *, char *, char *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
int gen_move_to_ccr(const char *mnemonic, int opcode) {
  char func_name[(100)];
  int func_id;
  int op_size;
  int op_dest;
  int sr;
  op_size = 1;
  sr = opcode & 0x200;
  if (ea_mode(opcode) == 1 || ea_mode(opcode) < 0)
    return invalid();
  sprintf(func_name, "%s_%04X", mnemonic, opcode);
  func_id = begin_function(func_name);
  if (sr)
    printf("\tif (!SUPERVISOR) PRIVILEGE_EXCEPTION;\n");
  if (get_ea(func_name, opcode, op_size, 1) < 0)
    return -1;
  if (ea_address(opcode)) {
    if (op_size)
      printf("\tif (EA&1) ADDRESS_EXCEPTION;\n");
    if (sr)
      sprintf(func_name, "%s_sr_common", mnemonic);
    else
      sprintf(func_name, "%s_tcr_common", mnemonic);
    if (print_bus_read_(func_name, "", "EA", "EV", op_size) < 0)
      return func_id;
  }
  if (sr)
    printf("\tSR = EV;\n");
  else
    printf("\tSET_DN_REG8(M68K_REG_SR, EV);\n");
  printf("\tSR &= M68K_FLAG_ALL;\n");
  printf("\tFETCH_OPCODE;\n}\n\n");
  return func_id;
}


x86 assembly (clang, -O0):
<gen_move_to_ccr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x88(%rbp)
mov    -0x14(%rbp),%eax
and    $0x200,%eax
mov    %eax,-0x90(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <ea_mode@plt>
cmp    $0x1,%eax
je     11cc <gen_move_to_ccr+0x4c>
mov    -0x14(%rbp),%edi
call   1060 <ea_mode@plt>
cmp    $0x0,%eax
jge    11db <gen_move_to_ccr+0x5b>
mov    $0x0,%al
call   1080 <invalid@plt>
mov    %eax,-0x4(%rbp)
jmp    133f <gen_move_to_ccr+0x1bf>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   10a0 <begin_function@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x90(%rbp)
je     121c <gen_move_to_ccr+0x9c>
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x88(%rbp),%edx
mov    $0x1,%ecx
call   1070 <get_ea@plt>
cmp    $0x0,%rax
jge    1249 <gen_move_to_ccr+0xc9>
movl   $0xffffffff,-0x4(%rbp)
jmp    133f <gen_move_to_ccr+0x1bf>
mov    -0x14(%rbp),%edi
call   1040 <ea_address@plt>
cmp    $0x0,%rax
je     12f4 <gen_move_to_ccr+0x174>
cmpl   $0x0,-0x88(%rbp)
je     1274 <gen_move_to_ccr+0xf4>
lea    0xdc1(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x90(%rbp)
je     129c <gen_move_to_ccr+0x11c>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    12b2 <gen_move_to_ccr+0x132>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%r8d
lea    0xe00(%rip),%rsi
lea    0xd9f(%rip),%rdx
lea    0xd9b(%rip),%rcx
call   1050 <print_bus_read_@plt>
cmp    $0x0,%rax
jge    12ef <gen_move_to_ccr+0x16f>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    133f <gen_move_to_ccr+0x1bf>
jmp    12f4 <gen_move_to_ccr+0x174>
cmpl   $0x0,-0x90(%rbp)
je     1312 <gen_move_to_ccr+0x192>
lea    0xd68(%rip),%rdi
call   1030 <printf@plt>
jmp    131e <gen_move_to_ccr+0x19e>
lea    0xd62(%rip),%rdi
call   1030 <printf@plt>
lea    0xd76(%rip),%rdi
call   1030 <printf@plt>
lea    0xd81(%rip),%rdi
call   1030 <printf@plt>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_move_to_ccr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
mov    %esi,%edi
call   1060 <ea_mode@plt>
cmp    $0x1,%eax
je     12a2 <gen_move_to_ccr+0x122>
mov    %ebx,%edi
call   1060 <ea_mode@plt>
test   %eax,%eax
js     12a2 <gen_move_to_ccr+0x122>
lea    0xe4b(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   10a0 <begin_function@plt>
mov    %eax,%r14d
test   $0x200,%ebx
je     11e6 <gen_move_to_ccr+0x66>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1070 <get_ea@plt>
test   %rax,%rax
js     12b3 <gen_move_to_ccr+0x133>
mov    %ebx,%edi
call   1040 <ea_address@plt>
test   %rax,%rax
je     126b <gen_move_to_ccr+0xeb>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
test   $0x200,%ebx
lea    0xded(%rip),%rax
lea    0xdd9(%rip),%rsi
cmove  %rax,%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xe25(%rip),%rsi
lea    0xdd2(%rip),%rdx
lea    0xdce(%rip),%rcx
mov    %rbp,%rdi
mov    $0x1,%r8d
call   1050 <print_bus_read_@plt>
test   %rax,%rax
js     12b9 <gen_move_to_ccr+0x139>
test   $0x200,%ebx
lea    0xdb1(%rip),%rax
lea    0xdf1(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
lea    0xdb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc3(%rip),%rdi
call   1030 <puts@plt>
jmp    12b9 <gen_move_to_ccr+0x139>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <invalid@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s_%04X\00"
@.str.1 = [40 x i8] c"\09if (!SUPERVISOR) PRIVILEGE_EXCEPTION;\0A\00"
@.str.2 = [31 x i8] c"\09if (EA&1) ADDRESS_EXCEPTION;\0A\00"
@.str.3 = [13 x i8] c"%s_sr_common\00"
@.str.4 = [14 x i8] c"%s_tcr_common\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [3 x i8] c"EA\00"
@.str.7 = [3 x i8] c"EV\00"
@.str.8 = [11 x i8] c"\09SR = EV;\0A\00"
@.str.9 = [32 x i8] c"\09SET_DN_REG8(M68K_REG_SR, EV);\0A\00"
@.str.10 = [23 x i8] c"\09SR &= M68K_FLAG_ALL;\0A\00"
@.str.11 = [19 x i8] c"\09FETCH_OPCODE;\0A}\0A\0A\00"
define i32 @gen_move_to_ccr(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 1, i32* %8
%11 = load i32, i32* %5
%12 = and i32 %11, 512
store i32 %12, i32* %10
%13 = load i32, i32* %5
%14 = call i32 @ea_mode(i32 %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %20, label %16
16: ; preds = %2
%17 = load i32, i32* %5
%18 = call i32 @ea_mode(i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16, %2
%21 = call i32 (...) @invalid()
store i32 %21, i32* %3
br label %79
22: ; preds = %16
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %25)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%28 = call i32 @begin_function(i8* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %22
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* %5
%36 = load i32, i32* %8
%37 = call i64 @get_ea(i8* %34, i32 %35, i32 %36, i32 1)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 -1, i32* %3
br label %79
40: ; preds = %33
%41 = load i32, i32* %5
%42 = call i64 @ea_address(i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %68
44: ; preds = %40
%45 = load i32, i32* %8
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
%50 = load i32, i32* %10
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%54 = load i8*, i8** %4
%55 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %54)
br label %60
56: ; preds = %49
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%58 = load i8*, i8** %4
%59 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %58)
br label %60
60: ; preds = %56, %52
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%62 = load i32, i32* %8
%63 = call i64 @print_bus_read_(i8* %61, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %62)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = load i32, i32* %7
store i32 %66, i32* %3
br label %79
67: ; preds = %60
br label %68
68: ; preds = %67, %40
%69 = load i32, i32* %10
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %75
73: ; preds = %68
%74 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %75
75: ; preds = %73, %71
%76 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0))
%77 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%78 = load i32, i32* %7
store i32 %78, i32* %3
br label %79
79: ; preds = %75, %65, %39, %20
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s_%04X\00"
@.str.3 = [13 x i8] c"%s_sr_common\00"
@.str.4 = [14 x i8] c"%s_tcr_common\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [3 x i8] c"EA\00"
@.str.7 = [3 x i8] c"EV\00"
@str = [31 x i8] c"\09SET_DN_REG8(M68K_REG_SR, EV);\00"
@str.12 = [22 x i8] c"\09SR &= M68K_FLAG_ALL;\00"
@str.13 = [18 x i8] c"\09FETCH_OPCODE;\0A}\0A\00"
@str.14 = [10 x i8] c"\09SR = EV;\00"
@str.15 = [30 x i8] c"\09if (EA&1) ADDRESS_EXCEPTION;\00"
@str.16 = [39 x i8] c"\09if (!SUPERVISOR) PRIVILEGE_EXCEPTION;\00"
define i32 @gen_move_to_ccr(i8* %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = and i32 %1, 512
%6 = tail call i32 @ea_mode(i32 %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @ea_mode(i32 %1)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = tail call i32 (...) @invalid()
br label %36
13: ; preds = %8
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%15 = call i32 @begin_function(i8* %4)
%16 = icmp eq i32 %5, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.16, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = call i64 @get_ea(i8* %4, i32 %1, i32 1, i32 1)
%21 = icmp slt i64 %20, 0
br i1 %21, label %36, label %22
22: ; preds = %19
%23 = call i64 @ea_address(i32 %1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %22
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.15, i64 0, i64 0))
%27 = select i1 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0)
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) %27, i8* %0)
%29 = call i64 @print_bus_read_(i8* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 1)
%30 = icmp slt i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %25, %22
%32 = select i1 %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.14, i64 0, i64 0)
%33 = call i32 @puts(i8* dereferenceable(1) %32)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.12, i64 0, i64 0))
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.13, i64 0, i64 0))
br label %36
36: ; preds = %25, %19, %31, %11
%37 = phi i32 [ %12, %11 ], [ %15, %31 ], [ -1, %19 ], [ %15, %25 ]
ret i32 %37
}