#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 rts(int opcode) {
  char func_name[(100)];
  int func_id;
  if (opcode != 0x4E75)
    return;
  sprintf(func_name, "rts_%04X", opcode);
  func_id = begin_function(func_name);
  print_bus_read_(func_name, "", "REG_A(7)", "PC", 2);
  printf("\tREG_A(7) += 4;\n");
  printf("\tFETCH_OPCODE;\n}\n\n");
  add_opcode(func_id, opcode);
}


x86 assembly (clang, -O0):
<rts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x4e75,-0x4(%rbp)
je     1170 <rts+0x20>
jmp    11d6 <rts+0x86>
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    -0x70(%rbp),%rdi
lea    0xe9e(%rip),%rsi
lea    0xe68(%rip),%rdx
lea    0xe6a(%rip),%rcx
mov    $0x2,%r8d
call   1040 <print_bus_read_@plt>
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
lea    0xe60(%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):
<rts>:
cmp    $0x4e75,%edi
jne    11cc <rts+0x7c>
push   %rbp
push   %rbx
sub    $0x68,%rsp
lea    0xe9b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x4e75,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <begin_function@plt>
mov    %eax,%ebp
lea    0xeb0(%rip),%rsi
lea    0xe7c(%rip),%rdx
lea    0xe7e(%rip),%rcx
mov    %rbx,%rdi
mov    $0x2,%r8d
call   1040 <print_bus_read_@plt>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    $0x4e75,%esi
call   1050 <add_opcode@plt>
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"rts_%04X\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [9 x i8] c"REG_A(7)\00"
@.str.3 = [3 x i8] c"PC\00"
@.str.4 = [17 x i8] c"\09REG_A(7) += 4;\0A\00"
@.str.5 = [19 x i8] c"\09FETCH_OPCODE;\0A}\0A\0A\00"
define void @rts(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, 20085
br i1 %6, label %7, label %8
7: ; preds = %1
br label %21
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 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = call i32 @print_bus_read_(i8* %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = call i32 @add_opcode(i32 %18, i32 %19)
br label %21
21: ; preds = %8, %7
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"rts_%04X\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [9 x i8] c"REG_A(7)\00"
@.str.3 = [3 x i8] c"PC\00"
@str = [16 x i8] c"\09REG_A(7) += 4;\00"
@str.6 = [18 x i8] c"\09FETCH_OPCODE;\0A}\0A\00"
define void @rts(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, 20085
br i1 %4, label %5, label %12
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 20085)
%7 = call i32 @begin_function(i8* %3)
%8 = call i32 @print_bus_read_(i8* %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%11 = call i32 @add_opcode(i32 %7, i32 20085)
br label %12
12: ; preds = %1, %5
ret void
}