#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*/ add_opcode(int, int);
int begin_function(char *);
int /*<<< orphan*/ print_bus_read_(char *, char *, char *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void rte(int opcode) {
  char func_name[(100)];
  int func_id;
  if (opcode != 0x4E73)
    return;
  sprintf(func_name, "rte_%04X", opcode);
  func_id = begin_function(func_name);
  printf("\tif (!SUPERVISOR) PRIVILEGE_EXCEPTION;\n");
  print_bus_read_(func_name, "", "REG_A(7)", "OP", 1);
  print_bus_read_(func_name, "_pc", "REG_A(7)+2", "PC", 2);
  printf("\tREG_A(7) += 6;\n");
  printf("\tSAVE_CURRENT_STACK;\n");
  printf("\tSR = OP & M68K_FLAG_ALL;\n");
  printf("\tGET_CURRENT_STACK;\n");
  printf("\tFETCH_OPCODE;\n}\n\n");
  add_opcode(func_id, opcode);
}


x86 assembly (clang, -O0):
<rte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x4e73,-0x4(%rbp)
je     1170 <rte+0x20>
jmp    122a <rte+0xda>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe82(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1070 <begin_function@plt>
mov    %eax,-0x74(%rbp)
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xf12(%rip),%rsi
lea    0xe84(%rip),%rdx
lea    0xe86(%rip),%rcx
mov    $0x1,%r8d
call   1040 <print_bus_read_@plt>
lea    -0x70(%rbp),%rdi
lea    0xe73(%rip),%rsi
lea    0xe70(%rip),%rdx
lea    0xe74(%rip),%rcx
mov    $0x2,%r8d
call   1040 <print_bus_read_@plt>
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x74(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1050 <add_opcode@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rte>:
cmp    $0x4e73,%edi
jne    1223 <rte+0xd3>
push   %rbp
push   %rbx
sub    $0x68,%rsp
lea    0xe97(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x4e73,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <begin_function@plt>
mov    %eax,%ebp
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0xf1c(%rip),%rsi
lea    0xe6c(%rip),%rdx
lea    0xe6e(%rip),%rcx
mov    %rbx,%rdi
mov    $0x1,%r8d
call   1040 <print_bus_read_@plt>
lea    0xe5c(%rip),%rsi
lea    0xe59(%rip),%rdx
lea    0xe5d(%rip),%rcx
mov    %rbx,%rdi
mov    $0x2,%r8d
call   1040 <print_bus_read_@plt>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    $0x4e73,%esi
call   1050 <add_opcode@plt>
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"rte_%04X\00"
@.str.1 = [40 x i8] c"\09if (!SUPERVISOR) PRIVILEGE_EXCEPTION;\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [9 x i8] c"REG_A(7)\00"
@.str.4 = [3 x i8] c"OP\00"
@.str.5 = [4 x i8] c"_pc\00"
@.str.6 = [11 x i8] c"REG_A(7)+2\00"
@.str.7 = [3 x i8] c"PC\00"
@.str.8 = [17 x i8] c"\09REG_A(7) += 6;\0A\00"
@.str.9 = [22 x i8] c"\09SAVE_CURRENT_STACK;\0A\00"
@.str.10 = [27 x i8] c"\09SR = OP & M68K_FLAG_ALL;\0A\00"
@.str.11 = [21 x i8] c"\09GET_CURRENT_STACK;\0A\00"
@.str.12 = [19 x i8] c"\09FETCH_OPCODE;\0A}\0A\0A\00"
define void @rte(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 20083
br i1 %6, label %7, label %8
7: ; preds = %1
br label %27
8: ; preds = %1
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* %2
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%13 = call i32 @begin_function(i8* %12)
store i32 %13, i32* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = call i32 @print_bus_read_(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 1)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = call i32 @print_bus_read_(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2)
%19 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%20 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%21 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = call i32 @add_opcode(i32 %24, i32 %25)
br label %27
27: ; preds = %8, %7
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"rte_%04X\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [9 x i8] c"REG_A(7)\00"
@.str.4 = [3 x i8] c"OP\00"
@.str.5 = [4 x i8] c"_pc\00"
@.str.6 = [11 x i8] c"REG_A(7)+2\00"
@.str.7 = [3 x i8] c"PC\00"
@str = [39 x i8] c"\09if (!SUPERVISOR) PRIVILEGE_EXCEPTION;\00"
@str.13 = [16 x i8] c"\09REG_A(7) += 6;\00"
@str.14 = [21 x i8] c"\09SAVE_CURRENT_STACK;\00"
@str.15 = [26 x i8] c"\09SR = OP & M68K_FLAG_ALL;\00"
@str.16 = [20 x i8] c"\09GET_CURRENT_STACK;\00"
@str.17 = [18 x i8] c"\09FETCH_OPCODE;\0A}\0A\00"
define void @rte(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, 20083
br i1 %4, label %5, label %17
5: ; preds = %1
%6 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 20083)
%7 = call i32 @begin_function(i8* %3)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%9 = call i32 @print_bus_read_(i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 1)
%10 = call i32 @print_bus_read_(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.13, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.14, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.15, i64 0, i64 0))
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.16, i64 0, i64 0))
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.17, i64 0, i64 0))
%16 = call i32 @add_opcode(i32 %7, i32 20083)
br label %17
17: ; preds = %1, %5
ret void
}