#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int print_bus_wait_(char const *, char *, char *);
int /*<<< orphan*/ printf(char *, char const *, char const *);
int /*<<< orphan*/ stderr;
int print_bus_read(const char *prefix, const char *address, const char *lval,
                   int size) {
  const char *func_name;
  int r;
  func_name = prefix;
  r = print_bus_wait_(func_name, "_wait", "_read");
  if (r < 0)
    return r;
  switch (size) {
  case 0:
    printf("\t%s = READ_8(%s);\n", lval, address);
    break;
  case 1:
    printf("\t%s = READ_16(%s);\n", lval, address);
    break;
  case 2:
    printf("\t%s = READ_16(%s)<<16;\n", lval, address);
    if (print_bus_wait_(func_name, "_wait2", "_read2") < 0)
      fprintf(stderr, "Error: %s_read2 already exists\n", prefix);
    printf("\t%s |= READ_16(%s + 2);\n", lval, address);
    break;
  default:
    fprintf(stderr, "Error: invalid bus read size %d in %s\n", size, prefix);
    break;
  }
  return r;
}


x86 assembly (clang, -O0):
<print_bus_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xea6(%rip),%rsi
lea    0xea5(%rip),%rdx
call   1050 <print_bus_wait_@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    117e <print_bus_read+0x4e>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <print_bus_read+0x141>
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     11b3 <print_bus_read+0x83>
jmp    1191 <print_bus_read+0x61>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     11cc <print_bus_read+0x9c>
jmp    11a2 <print_bus_read+0x72>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
je     11e5 <print_bus_read+0xb5>
jmp    124d <print_bus_read+0x11d>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
jmp    126b <print_bus_read+0x13b>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe44(%rip),%rdi
call   1030 <printf@plt>
jmp    126b <print_bus_read+0x13b>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe47(%rip),%rsi
lea    0xe47(%rip),%rdx
call   1050 <print_bus_wait_@plt>
cmp    $0x0,%eax
jge    1234 <print_bus_read+0x104>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    126b <print_bus_read+0x13b>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bus_read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeb6(%rip),%rsi
lea    0xeb5(%rip),%rdx
call   1050 <print_bus_wait_@plt>
mov    %eax,%r12d
test   %eax,%eax
js     11f7 <print_bus_read+0xc7>
cmp    $0x2,%ebp
je     1178 <print_bus_read+0x48>
cmp    $0x1,%ebp
je     11c7 <print_bus_read+0x97>
test   %ebp,%ebp
jne    11db <print_bus_read+0xab>
lea    0xe96(%rip),%rdi
jmp    11ce <print_bus_read+0x9e>
lea    0xeb4(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
lea    0xeba(%rip),%rsi
lea    0xeba(%rip),%rdx
mov    %rbx,%rdi
call   1050 <print_bus_wait_@plt>
test   %eax,%eax
jns    11be <print_bus_read+0x8e>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xeb4(%rip),%rdi
jmp    11ce <print_bus_read+0x9e>
lea    0xe51(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
jmp    11f7 <print_bus_read+0xc7>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"_wait\00"
@.str.1 = [6 x i8] c"_read\00"
@.str.2 = [19 x i8] c"\09%s = READ_8(%s);\0A\00"
@.str.3 = [20 x i8] c"\09%s = READ_16(%s);\0A\00"
@.str.4 = [24 x i8] c"\09%s = READ_16(%s)<<16;\0A\00"
@.str.5 = [7 x i8] c"_wait2\00"
@.str.6 = [7 x i8] c"_read2\00"
@stderr = global i32 0
@.str.7 = [32 x i8] c"Error: %s_read2 already exists\0A\00"
@.str.8 = [25 x i8] c"\09%s |= READ_16(%s + 2);\0A\00"
@.str.9 = [39 x i8] c"Error: invalid bus read size %d in %s\0A\00"
define i32 @print_bus_read(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = call i32 @print_bus_wait_(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %11
%15 = load i32, i32* %11
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %11
store i32 %18, i32* %5
br label %51
19: ; preds = %4
%20 = load i32, i32* %9
switch i32 %20, label %44 [
i32 0, label %21
i32 1, label %25
i32 2, label %29
]
21: ; preds = %19
%22 = load i8*, i8** %8
%23 = load i8*, i8** %7
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %22, i8* %23)
br label %49
25: ; preds = %19
%26 = load i8*, i8** %8
%27 = load i8*, i8** %7
%28 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %26, i8* %27)
br label %49
29: ; preds = %19
%30 = load i8*, i8** %8
%31 = load i8*, i8** %7
%32 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %30, i8* %31)
%33 = load i8*, i8** %10
%34 = call i32 @print_bus_wait_(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %29
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %6
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %36, %29
%41 = load i8*, i8** %8
%42 = load i8*, i8** %7
%43 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %41, i8* %42)
br label %49
44: ; preds = %19
%45 = load i32, i32* @stderr
%46 = load i32, i32* %9
%47 = load i8*, i8** %6
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %46, i8* %47)
br label %49
49: ; preds = %44, %40, %25, %21
%50 = load i32, i32* %11
store i32 %50, i32* %5
br label %51
51: ; preds = %49, %17
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
@.str = [6 x i8] c"_wait\00"
@.str.1 = [6 x i8] c"_read\00"
@.str.2 = [19 x i8] c"\09%s = READ_8(%s);\0A\00"
@.str.3 = [20 x i8] c"\09%s = READ_16(%s);\0A\00"
@.str.4 = [24 x i8] c"\09%s = READ_16(%s)<<16;\0A\00"
@.str.5 = [7 x i8] c"_wait2\00"
@.str.6 = [7 x i8] c"_read2\00"
@stderr = global i32 0
@.str.7 = [32 x i8] c"Error: %s_read2 already exists\0A\00"
@.str.8 = [25 x i8] c"\09%s |= READ_16(%s + 2);\0A\00"
@.str.9 = [39 x i8] c"Error: invalid bus read size %d in %s\0A\00"
define i32 @print_bus_read(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i32 @print_bus_wait_(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp slt i32 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %4
switch i32 %3, label %21 [
i32 0, label %8
i32 1, label %10
i32 2, label %12
]
8: ; preds = %7
%9 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %1)
br label %24
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %1)
br label %24
12: ; preds = %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* %1)
%14 = tail call i32 @print_bus_wait_(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %16, %12
%20 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %2, i8* %1)
br label %24
21: ; preds = %7
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %3, i8* %0)
br label %24
24: ; preds = %8, %10, %19, %21, %4
ret i32 %5
}