#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*/ gen_swap();
int /*<<< orphan*/ output_line(char *);
void gen_get_indirect(char typeobj, int reg) {
  if (typeobj == (1 << 2)) {
    if (reg & 1 << 2) {
      gen_swap();
    }
    output_line("loadsb r1 (r1)");
  } else if (typeobj == ((1 << 2) + 1)) {
    if (reg & 1 << 2) {
      gen_swap();
    }
    output_line("loadub r1 (r1)");
  } else {
    output_line("load r1 (r1)");
  }
}


x86 assembly (clang, -O0):
<gen_get_indirect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x4,%eax
jne    1165 <gen_get_indirect+0x45>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1154 <gen_get_indirect+0x34>
mov    $0x0,%al
call   1030 <gen_swap@plt>
lea    0xea5(%rip),%rdi
call   1040 <output_line@plt>
jmp    11aa <gen_get_indirect+0x8a>
movsbl -0x1(%rbp),%eax
cmp    $0x5,%eax
jne    1199 <gen_get_indirect+0x79>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1188 <gen_get_indirect+0x68>
mov    $0x0,%al
call   1030 <gen_swap@plt>
lea    0xe80(%rip),%rdi
call   1040 <output_line@plt>
jmp    11a5 <gen_get_indirect+0x85>
lea    0xe7e(%rip),%rdi
call   1040 <output_line@plt>
jmp    11aa <gen_get_indirect+0x8a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_get_indirect>:
push   %rbx
cmp    $0x5,%dil
je     113c <gen_get_indirect+0x1c>
cmp    $0x4,%dil
jne    1152 <gen_get_indirect+0x32>
lea    0xecc(%rip),%rbx
test   $0x4,%sil
jne    1149 <gen_get_indirect+0x29>
jmp    1159 <gen_get_indirect+0x39>
lea    0xecc(%rip),%rbx
test   $0x4,%sil
je     1159 <gen_get_indirect+0x39>
xor    %eax,%eax
call   1030 <gen_swap@plt>
jmp    1159 <gen_get_indirect+0x39>
lea    0xec5(%rip),%rbx
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <output_line@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"loadsb r1 (r1)\00"
@.str.1 = [15 x i8] c"loadub r1 (r1)\00"
@.str.2 = [13 x i8] c"load r1 (r1)\00"
define void @gen_get_indirect(i8 signext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i32
store i8 %0, i8* %3
store i32 %1, i32* %4
%5 = load i8, i8* %3
%6 = sext i8 %5 to i32
%7 = icmp eq i32 %6, 4
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = load i32, i32* %4
%10 = and i32 %9, 4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 (...) @gen_swap()
br label %14
14: ; preds = %12, %8
%15 = call i32 @output_line(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %31
16: ; preds = %2
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 5
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32, i32* %4
%22 = and i32 %21, 4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 (...) @gen_swap()
br label %26
26: ; preds = %24, %20
%27 = call i32 @output_line(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %30
28: ; preds = %16
%29 = call i32 @output_line(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
br label %31
31: ; preds = %30, %14
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"loadsb r1 (r1)\00"
@.str.1 = [15 x i8] c"loadub r1 (r1)\00"
@.str.2 = [13 x i8] c"load r1 (r1)\00"
define void @gen_get_indirect(i8 signext %0, i32 %1) {
switch i8 %0, label %12 [
i8 4, label %3
i8 5, label %6
]
3: ; preds = %2
%4 = and i32 %1, 4
%5 = icmp eq i32 %4, 0
br i1 %5, label %12, label %9
6: ; preds = %2
%7 = and i32 %1, 4
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6, %3
%10 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %6 ]
%11 = tail call i32 (...) @gen_swap()
br label %12
12: ; preds = %9, %2, %6, %3
%13 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %2 ], [ %10, %9 ]
%14 = tail call i32 @output_line(i8* %13)
ret void
}