#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*/ output_line(char *);
void gen_get_indirect(char typeobj, int reg) {
  if (typeobj == (1 << 2) || typeobj == ((1 << 2) + 1)) {
    if (reg & 1 << 2)
      output_line("ldb ,x");
    else {
      output_line("tfr d,u");
      output_line("ldb ,u");
    }
    if (typeobj == (1 << 2))
      output_line("sex");
  } else {
    if (reg & 1 << 2)
      output_line("ldd ,x");
    else {
      output_line("exg d,x");
      output_line("ldx ,x");
      output_line("exg d,x");
    }
  }
}


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
je     113b <gen_get_indirect+0x2b>
movsbl -0x1(%rbp),%eax
cmp    $0x5,%eax
jne    1191 <gen_get_indirect+0x81>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     115b <gen_get_indirect+0x4b>
lea    0xeaf(%rip),%rdi
call   1030 <output_line@plt>
jmp    1173 <gen_get_indirect+0x63>
lea    0xea5(%rip),%rdi
call   1030 <output_line@plt>
lea    0xea1(%rip),%rdi
call   1030 <output_line@plt>
movsbl -0x1(%rbp),%eax
cmp    $0x4,%eax
jne    118c <gen_get_indirect+0x7c>
lea    0xe8f(%rip),%rdi
call   1030 <output_line@plt>
jmp    11da <gen_get_indirect+0xca>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11b1 <gen_get_indirect+0xa1>
lea    0xe73(%rip),%rdi
call   1030 <output_line@plt>
jmp    11d5 <gen_get_indirect+0xc5>
lea    0xe69(%rip),%rdi
call   1030 <output_line@plt>
lea    0xe65(%rip),%rdi
call   1030 <output_line@plt>
lea    0xe51(%rip),%rdi
call   1030 <output_line@plt>
jmp    11da <gen_get_indirect+0xca>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_get_indirect>:
push   %rbx
mov    %edi,%ebx
mov    %ebx,%eax
and    $0xfe,%al
cmp    $0x4,%al
jne    1136 <gen_get_indirect+0x26>
test   $0x4,%sil
jne    1159 <gen_get_indirect+0x49>
lea    0xedf(%rip),%rdi
call   1030 <output_line@plt>
lea    0xedb(%rip),%rdi
jmp    1160 <gen_get_indirect+0x50>
test   $0x4,%sil
jne    1173 <gen_get_indirect+0x63>
lea    0xede(%rip),%rbx
mov    %rbx,%rdi
call   1030 <output_line@plt>
lea    0xed7(%rip),%rdi
call   1030 <output_line@plt>
jmp    117a <gen_get_indirect+0x6a>
lea    0xea0(%rip),%rdi
call   1030 <output_line@plt>
cmp    $0x4,%bl
jne    1183 <gen_get_indirect+0x73>
lea    0xea5(%rip),%rbx
jmp    117a <gen_get_indirect+0x6a>
lea    0xea0(%rip),%rbx
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <output_line@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"ldb ,x\00"
@.str.1 = [8 x i8] c"tfr d,u\00"
@.str.2 = [7 x i8] c"ldb ,u\00"
@.str.3 = [4 x i8] c"sex\00"
@.str.4 = [7 x i8] c"ldd ,x\00"
@.str.5 = [8 x i8] c"exg d,x\00"
@.str.6 = [7 x i8] c"ldx ,x\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 %12, label %8
8: ; preds = %2
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 5
br i1 %11, label %12, label %28
12: ; preds = %8, %2
%13 = load i32, i32* %4
%14 = and i32 %13, 4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %21
18: ; preds = %12
%19 = call i32 @output_line(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %18, %16
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 4
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @output_line(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
br label %39
28: ; preds = %8
%29 = load i32, i32* %4
%30 = and i32 %29, 4
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %38
34: ; preds = %28
%35 = call i32 @output_line(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%37 = call i32 @output_line(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %34, %32
br label %39
39: ; preds = %38, %27
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"ldb ,x\00"
@.str.1 = [8 x i8] c"tfr d,u\00"
@.str.2 = [7 x i8] c"ldb ,u\00"
@.str.3 = [4 x i8] c"sex\00"
@.str.4 = [7 x i8] c"ldd ,x\00"
@.str.5 = [8 x i8] c"exg d,x\00"
@.str.6 = [7 x i8] c"ldx ,x\00"
define void @gen_get_indirect(i8 signext %0, i32 %1) {
%3 = icmp eq i8 %0, 4
%4 = and i8 %0, -2
%5 = icmp eq i8 %4, 4
%6 = and i32 %1, 4
%7 = icmp eq i32 %6, 0
br i1 %5, label %8, label %14
8: ; preds = %2
br i1 %7, label %9, label %11
9: ; preds = %8
%10 = tail call i32 @output_line(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %8, %9
%12 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %8 ]
%13 = tail call i32 @output_line(i8* %12)
br i1 %3, label %18, label %21
14: ; preds = %2
br i1 %7, label %15, label %18
15: ; preds = %14
%16 = tail call i32 @output_line(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%17 = tail call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %18
18: ; preds = %14, %11, %15
%19 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %15 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), %14 ]
%20 = tail call i32 @output_line(i8* %19)
br label %21
21: ; preds = %18, %11
ret void
}