#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_write(const char *prefix, const char *address, const char *val,
                    int size) {
  const char *func_name;
  int r;
  func_name = prefix;
  r = print_bus_wait_(func_name, "_wait", "_write");
  if (r < 0)
    return r;
  switch (size) {
  case 0:
    printf("\tWRITE_8(%s, %s);\n", address, val);
    break;
  case 1:
    printf("\tWRITE_16(%s, %s);\n", address, val);
    break;
  case 2:
    printf("\tWRITE_16(%s, (%s)>>16);\n", address, val);
    if (print_bus_wait_(func_name, "_wait2", "_write2") < 0)
      fprintf(stderr, "Error: %s_read2 already exists\n", prefix);
    printf("\tWRITE_16(%s + 2, %s);\n", address, val);
    break;
  default:
    fprintf(stderr, "Error: invalid bus write size %d in %s\n", size, prefix);
    break;
  }
  return r;
}


x86 assembly (clang, -O0):
<print_bus_write>:
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_write+0x4e>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <print_bus_write+0x141>
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
test   %eax,%eax
je     11b3 <print_bus_write+0x83>
jmp    1191 <print_bus_write+0x61>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
je     11cc <print_bus_write+0x9c>
jmp    11a2 <print_bus_write+0x72>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
je     11e5 <print_bus_write+0xb5>
jmp    124d <print_bus_write+0x11d>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    126b <print_bus_write+0x13b>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
jmp    126b <print_bus_write+0x13b>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe4a(%rip),%rsi
lea    0xe4a(%rip),%rdx
call   1050 <print_bus_wait_@plt>
cmp    $0x0,%eax
jge    1234 <print_bus_write+0x104>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe3a(%rip),%rdi
call   1030 <printf@plt>
jmp    126b <print_bus_write+0x13b>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe31(%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_write>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
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_write+0xc7>
cmp    $0x2,%ebp
je     1178 <print_bus_write+0x48>
cmp    $0x1,%ebp
je     11c7 <print_bus_write+0x97>
test   %ebp,%ebp
jne    11db <print_bus_write+0xab>
lea    0xe97(%rip),%rdi
jmp    11ce <print_bus_write+0x9e>
lea    0xeb5(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
lea    0xebd(%rip),%rsi
lea    0xebd(%rip),%rdx
mov    %rbx,%rdi
call   1050 <print_bus_wait_@plt>
test   %eax,%eax
jns    11be <print_bus_write+0x8e>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xeb8(%rip),%rdi
jmp    11ce <print_bus_write+0x9e>
lea    0xe52(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
jmp    11f7 <print_bus_write+0xc7>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%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 = [7 x i8] c"_write\00"
@.str.2 = [19 x i8] c"\09WRITE_8(%s, %s);\0A\00"
@.str.3 = [20 x i8] c"\09WRITE_16(%s, %s);\0A\00"
@.str.4 = [26 x i8] c"\09WRITE_16(%s, (%s)>>16);\0A\00"
@.str.5 = [7 x i8] c"_wait2\00"
@.str.6 = [8 x i8] c"_write2\00"
@stderr = global i32 0
@.str.7 = [32 x i8] c"Error: %s_read2 already exists\0A\00"
@.str.8 = [24 x i8] c"\09WRITE_16(%s + 2, %s);\0A\00"
@.str.9 = [40 x i8] c"Error: invalid bus write size %d in %s\0A\00"
define i32 @print_bus_write(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 ([7 x i8], [7 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** %7
%23 = load i8*, i8** %8
%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** %7
%27 = load i8*, i8** %8
%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** %7
%31 = load i8*, i8** %8
%32 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 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 ([8 x i8], [8 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** %7
%42 = load i8*, i8** %8
%43 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 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 ([40 x i8], [40 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 = [7 x i8] c"_write\00"
@.str.2 = [19 x i8] c"\09WRITE_8(%s, %s);\0A\00"
@.str.3 = [20 x i8] c"\09WRITE_16(%s, %s);\0A\00"
@.str.4 = [26 x i8] c"\09WRITE_16(%s, (%s)>>16);\0A\00"
@.str.5 = [7 x i8] c"_wait2\00"
@.str.6 = [8 x i8] c"_write2\00"
@stderr = global i32 0
@.str.7 = [32 x i8] c"Error: %s_read2 already exists\0A\00"
@.str.8 = [24 x i8] c"\09WRITE_16(%s + 2, %s);\0A\00"
@.str.9 = [40 x i8] c"Error: invalid bus write size %d in %s\0A\00"
define i32 @print_bus_write(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 ([7 x i8], [7 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* %1, i8* %2)
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* %1, i8* %2)
br label %24
12: ; preds = %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2)
%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 ([8 x i8], [8 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 ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %1, i8* %2)
br label %24
21: ; preds = %7
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([40 x i8], [40 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
}