#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*/ cgen_pop();
int /*<<< orphan*/ print_instr(char *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
void cgen_binop(char op) {
  print_instr("lw $t0 4($sp)");
  cgen_pop();
  char str[100] = "\0";
  switch (op) {
  case '+':
    sprintf(str, "add");
    break;
  case '-':
    sprintf(str, "sub");
    break;
  case '*':
    sprintf(str, "mul");
    break;
  case '&':
    sprintf(str, "and");
    break;
  case '|':
    sprintf(str, "or");
    break;
  }
  strcat(str, " $a0 $t0 $a0");
  print_instr(str);
}


x86 assembly (clang, -O0):
<cgen_binop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
lea    0xea8(%rip),%rdi
call   1030 <print_instr@plt>
xor    %eax,%eax
call   1060 <cgen_pop@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,-0x20(%rbp)
movaps %xmm0,-0x30(%rbp)
movaps %xmm0,-0x40(%rbp)
movaps %xmm0,-0x50(%rbp)
movaps %xmm0,-0x60(%rbp)
movaps %xmm0,-0x70(%rbp)
movl   $0x0,-0x10(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0x74(%rbp)
sub    $0x26,%eax
je     121e <cgen_binop+0xde>
jmp    119b <cgen_binop+0x5b>
mov    -0x74(%rbp),%eax
sub    $0x2a,%eax
je     1209 <cgen_binop+0xc9>
jmp    11ac <cgen_binop+0x6c>
mov    -0x74(%rbp),%eax
sub    $0x2b,%eax
je     11df <cgen_binop+0x9f>
jmp    11bd <cgen_binop+0x7d>
mov    -0x74(%rbp),%eax
sub    $0x2d,%eax
je     11f4 <cgen_binop+0xb4>
jmp    11ce <cgen_binop+0x8e>
mov    -0x74(%rbp),%eax
sub    $0x7c,%eax
je     1233 <cgen_binop+0xf3>
jmp    1243 <cgen_binop+0x103>
lea    -0x70(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1243 <cgen_binop+0x103>
lea    -0x70(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1243 <cgen_binop+0x103>
lea    -0x70(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1243 <cgen_binop+0x103>
lea    -0x70(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1243 <cgen_binop+0x103>
lea    -0x70(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1040 <strcat@plt>
lea    -0x70(%rbp),%rdi
call   1030 <print_instr@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgen_binop>:
push   %rbx
sub    $0x70,%rsp
mov    %edi,%ebx
lea    0xee2(%rip),%rdi
call   1030 <print_instr@plt>
xor    %eax,%eax
call   1050 <cgen_pop@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    -0x26(%rbx),%eax
cmp    $0x7,%eax
ja     1193 <cgen_binop+0x63>
lea    0xe7f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x646e61,(%rsp)
jmp    11be <cgen_binop+0x8e>
cmp    $0x7c,%ebx
jne    11be <cgen_binop+0x8e>
movb   $0x0,0x2(%rsp)
movw   $0x726f,(%rsp)
jmp    11be <cgen_binop+0x8e>
movl   $0x6c756d,(%rsp)
jmp    11be <cgen_binop+0x8e>
movl   $0x646461,(%rsp)
jmp    11be <cgen_binop+0x8e>
movl   $0x627573,(%rsp)
lea    0xe6c(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rdi
call   1030 <print_instr@plt>
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"lw $t0 4($sp)\00"
@.str.1 = [4 x i8] c"add\00"
@.str.2 = [4 x i8] c"sub\00"
@.str.3 = [4 x i8] c"mul\00"
@.str.4 = [4 x i8] c"and\00"
@.str.5 = [3 x i8] c"or\00"
@.str.6 = [13 x i8] c" $a0 $t0 $a0\00"
define void @cgen_binop(i8 signext %0) {
%2 = alloca i8
%3 = alloca [100 x i8]
store i8 %0, i8* %2
%4 = call i32 @print_instr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @cgen_pop()
%6 = bitcast [100 x i8]* %3 to i8*
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
switch i32 %8, label %24 [
i32 43, label %9
i32 45, label %12
i32 42, label %15
i32 38, label %18
i32 124, label %21
]
9: ; preds = %1
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %24
12: ; preds = %1
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%14 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %24
15: ; preds = %1
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %24
18: ; preds = %1
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%20 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %24
21: ; preds = %1
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%23 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %1, %21, %18, %15, %12, %9
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%28 = call i32 @print_instr(i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"lw $t0 4($sp)\00"
@.str.5 = [3 x i8] c"or\00"
@.str.6 = [13 x i8] c" $a0 $t0 $a0\00"
define void @cgen_binop(i8 signext %0) {
%2 = alloca [100 x i8]
%3 = tail call i32 @print_instr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (...) @cgen_pop()
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = sext i8 %0 to i32
switch i32 %6, label %16 [
i32 43, label %7
i32 45, label %9
i32 42, label %11
i32 38, label %13
i32 124, label %15
]
7: ; preds = %1
%8 = bitcast [100 x i8]* %2 to i32*
store i32 6579297, i32* %8
br label %16
9: ; preds = %1
%10 = bitcast [100 x i8]* %2 to i32*
store i32 6452595, i32* %10
br label %16
11: ; preds = %1
%12 = bitcast [100 x i8]* %2 to i32*
store i32 7107949, i32* %12
br label %16
13: ; preds = %1
%14 = bitcast [100 x i8]* %2 to i32*
store i32 6581857, i32* %14
br label %16
15: ; preds = %1
br label %16
16: ; preds = %1, %15, %13, %11, %9, %7
%17 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 @print_instr(i8* %5)
ret void
}