#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 /*<<< orphan*/ ea_alterable(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*/ print_bus_wait(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
int gen_move_from_sr(const char *mnemonic, int opcode) {
  char func_name[(100)];
  int func_id;
  int op_size;
  op_size = 1;
  if (!ea_alterable(opcode) || ea_mode(opcode) == 1)
    return invalid();
  sprintf(func_name, "%s_%04X", mnemonic, opcode);
  func_id = begin_function(func_name);
  if (ea_address(opcode)) {
    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");
    sprintf(func_name, "%s_fsr_common", mnemonic);
    if (print_bus_read_(func_name, "", "EA", "EV", op_size) < 0)
      return func_id;
  }
  if (ea_mode(opcode) < 2) {
    printf("\tSET_DN_REG%d(%d, SR);\n", 8 << op_size, opcode & 0xF);
    printf("\tFETCH_OPCODE;\n}\n\n");
  } else {
    printf("\tEV = SR;\n");
    switch (op_size) {
    case 0:
      print_bus_wait("done_wait_wb", "done_write_wb");
      break;
    case 1:
      print_bus_wait("done_wait_ww", "done_write_ww");
      break;
    case 2:
      print_bus_wait("done_wait_wl", "done_write_wl");
      break;
    }
  }
  return func_id;
}


x86 assembly (clang, -O0):
<gen_move_from_sr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x88(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <ea_alterable@plt>
cmp    $0x0,%eax
je     11de <gen_move_from_sr+0x3e>
mov    -0x14(%rbp),%edi
call   1080 <ea_mode@plt>
cmp    $0x1,%eax
jne    11ed <gen_move_from_sr+0x4d>
mov    $0x0,%al
call   10a0 <invalid@plt>
mov    %eax,-0x4(%rbp)
jmp    13c3 <gen_move_from_sr+0x223>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   10c0 <begin_function@plt>
mov    %eax,-0x84(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <ea_address@plt>
cmp    $0x0,%rax
je     1259 <gen_move_from_sr+0xb9>
lea    -0x80(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x88(%rbp),%edx
mov    $0x1,%ecx
call   1090 <get_ea@plt>
cmp    $0x0,%rax
jge    1254 <gen_move_from_sr+0xb4>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c3 <gen_move_from_sr+0x223>
jmp    1259 <gen_move_from_sr+0xb9>
mov    -0x14(%rbp),%edi
call   1060 <ea_address@plt>
cmp    $0x0,%rax
je     12de <gen_move_from_sr+0x13e>
cmpl   $0x0,-0x88(%rbp)
je     1286 <gen_move_from_sr+0xe6>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%r8d
lea    0xdb7(%rip),%rsi
lea    0xd80(%rip),%rdx
lea    0xd7c(%rip),%rcx
call   1070 <print_bus_read_@plt>
cmp    $0x0,%rax
jge    12d9 <gen_move_from_sr+0x139>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13c3 <gen_move_from_sr+0x223>
jmp    12de <gen_move_from_sr+0x13e>
mov    -0x14(%rbp),%edi
call   1080 <ea_mode@plt>
cmp    $0x2,%eax
jge    1323 <gen_move_from_sr+0x183>
mov    -0x88(%rbp),%ecx
mov    $0x8,%esi
shl    %cl,%esi
mov    -0x14(%rbp),%edx
and    $0xf,%edx
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13ba <gen_move_from_sr+0x21a>
lea    0xd3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x88(%rbp),%eax
mov    %eax,-0x8c(%rbp)
test   %eax,%eax
je     1372 <gen_move_from_sr+0x1d2>
jmp    134a <gen_move_from_sr+0x1aa>
mov    -0x8c(%rbp),%eax
sub    $0x1,%eax
je     138a <gen_move_from_sr+0x1ea>
jmp    135e <gen_move_from_sr+0x1be>
mov    -0x8c(%rbp),%eax
sub    $0x2,%eax
je     13a2 <gen_move_from_sr+0x202>
jmp    13b5 <gen_move_from_sr+0x215>
lea    0xcf8(%rip),%rdi
lea    0xcfe(%rip),%rsi
call   1030 <print_bus_wait@plt>
jmp    13b5 <gen_move_from_sr+0x215>
lea    0xcfb(%rip),%rdi
lea    0xd01(%rip),%rsi
call   1030 <print_bus_wait@plt>
jmp    13b5 <gen_move_from_sr+0x215>
lea    0xcfe(%rip),%rdi
lea    0xd04(%rip),%rsi
call   1030 <print_bus_wait@plt>
jmp    13ba <gen_move_from_sr+0x21a>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_move_from_sr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebx
mov    %rdi,%rbp
mov    %esi,%edi
call   1050 <ea_alterable@plt>
test   %eax,%eax
je     11d6 <gen_move_from_sr+0x26>
mov    %ebx,%edi
call   1090 <ea_mode@plt>
cmp    $0x1,%eax
jne    11e7 <gen_move_from_sr+0x37>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <invalid@plt>
lea    0xe12(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbp,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %r14,%rdi
call   10d0 <begin_function@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1070 <ea_address@plt>
test   %rax,%rax
je     1234 <gen_move_from_sr+0x84>
mov    %rsp,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   10a0 <get_ea@plt>
test   %rax,%rax
js     12de <gen_move_from_sr+0x12e>
mov    %ebx,%edi
call   1070 <ea_address@plt>
test   %rax,%rax
je     128b <gen_move_from_sr+0xdb>
lea    0xe24(%rip),%rdi
call   1040 <puts@plt>
lea    0xdb5(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
lea    0xdc9(%rip),%rsi
lea    0xda5(%rip),%rdx
lea    0xda1(%rip),%rcx
mov    %r15,%rdi
mov    $0x1,%r8d
call   1080 <print_bus_read_@plt>
test   %rax,%rax
js     12e4 <gen_move_from_sr+0x134>
mov    %ebx,%edi
call   1090 <ea_mode@plt>
cmp    $0x1,%eax
jg     12bd <gen_move_from_sr+0x10d>
and    $0xf,%ebx
lea    0xd7b(%rip),%rdi
mov    $0x10,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xda3(%rip),%rdi
call   1040 <puts@plt>
jmp    12e4 <gen_move_from_sr+0x134>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
lea    0xd64(%rip),%rdi
lea    0xd6a(%rip),%rsi
call   1030 <print_bus_wait@plt>
jmp    12e4 <gen_move_from_sr+0x134>
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 = [31 x i8] c"\09if (EA&1) ADDRESS_EXCEPTION;\0A\00"
@.str.2 = [14 x i8] c"%s_fsr_common\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"EA\00"
@.str.5 = [3 x i8] c"EV\00"
@.str.6 = [24 x i8] c"\09SET_DN_REG%d(%d, SR);\0A\00"
@.str.7 = [19 x i8] c"\09FETCH_OPCODE;\0A}\0A\0A\00"
@.str.8 = [11 x i8] c"\09EV = SR;\0A\00"
@.str.9 = [13 x i8] c"done_wait_wb\00"
@.str.10 = [14 x i8] c"done_write_wb\00"
@.str.11 = [13 x i8] c"done_wait_ww\00"
@.str.12 = [14 x i8] c"done_write_ww\00"
@.str.13 = [13 x i8] c"done_wait_wl\00"
@.str.14 = [14 x i8] c"done_write_wl\00"
define i32 @gen_move_from_sr(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 1, i32* %8
%9 = load i32, i32* %5
%10 = call i32 @ea_alterable(i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* %5
%14 = call i32 @ea_mode(i32 %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %12, %2
%17 = call i32 (...) @invalid()
store i32 %17, i32* %3
br label %79
18: ; preds = %12
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %21)
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%24 = call i32 @begin_function(i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %5
%26 = call i64 @ea_address(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %18
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %5
%31 = load i32, i32* %8
%32 = call i64 @get_ea(i8* %29, i32 %30, i32 %31, i32 1)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 -1, i32* %3
br label %79
35: ; preds = %28
br label %36
36: ; preds = %35, %18
%37 = load i32, i32* %5
%38 = call i64 @ea_address(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %56
40: ; preds = %36
%41 = load i32, i32* %8
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%47 = load i8*, i8** %4
%48 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%50 = load i32, i32* %8
%51 = call i64 @print_bus_read_(i8* %49, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %50)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = load i32, i32* %7
store i32 %54, i32* %3
br label %79
55: ; preds = %45
br label %56
56: ; preds = %55, %36
%57 = load i32, i32* %5
%58 = call i32 @ea_mode(i32 %57)
%59 = icmp slt i32 %58, 2
br i1 %59, label %60, label %67
60: ; preds = %56
%61 = load i32, i32* %8
%62 = shl i32 8, %61
%63 = load i32, i32* %5
%64 = and i32 %63, 15
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %62, i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
br label %77
67: ; preds = %56
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%69 = load i32, i32* %8
switch i32 %69, label %76 [
i32 0, label %70
i32 1, label %72
i32 2, label %74
]
70: ; preds = %67
%71 = call i32 @print_bus_wait(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
br label %76
72: ; preds = %67
%73 = call i32 @print_bus_wait(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %76
74: ; preds = %67
%75 = call i32 @print_bus_wait(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0))
br label %76
76: ; preds = %67, %74, %72, %70
br label %77
77: ; preds = %76, %60
%78 = load i32, i32* %7
store i32 %78, i32* %3
br label %79
79: ; preds = %77, %53, %34, %16
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s_%04X\00"
@.str.2 = [14 x i8] c"%s_fsr_common\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [3 x i8] c"EA\00"
@.str.5 = [3 x i8] c"EV\00"
@.str.6 = [24 x i8] c"\09SET_DN_REG%d(%d, SR);\0A\00"
@.str.11 = [13 x i8] c"done_wait_ww\00"
@.str.12 = [14 x i8] c"done_write_ww\00"
@str = [10 x i8] c"\09EV = SR;\00"
@str.15 = [18 x i8] c"\09FETCH_OPCODE;\0A}\0A\00"
@str.16 = [30 x i8] c"\09if (EA&1) ADDRESS_EXCEPTION;\00"
define i32 @gen_move_from_sr(i8* %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @ea_alterable(i32 %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @ea_mode(i32 %1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %7, %2
%11 = tail call i32 (...) @invalid()
br label %38
12: ; preds = %7
%13 = 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)
%14 = call i32 @begin_function(i8* %4)
%15 = call i64 @ea_address(i32 %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = call i64 @get_ea(i8* %4, i32 %1, i32 1, i32 1)
%19 = icmp slt i64 %18, 0
br i1 %19, label %38, label %20
20: ; preds = %17, %12
%21 = call i64 @ea_address(i32 %1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.16, i64 0, i64 0))
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%26 = call i64 @print_bus_read_(i8* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 1)
%27 = icmp slt i64 %26, 0
br i1 %27, label %38, label %28
28: ; preds = %23, %20
%29 = call i32 @ea_mode(i32 %1)
%30 = icmp slt i32 %29, 2
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = and i32 %1, 15
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 16, i32 %32)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.15, i64 0, i64 0))
br label %38
35: ; preds = %28
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%37 = call i32 @print_bus_wait(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %38
38: ; preds = %31, %35, %23, %17, %10
%39 = phi i32 [ %11, %10 ], [ -1, %17 ], [ %14, %23 ], [ %14, %35 ], [ %14, %31 ]
ret i32 %39
}