#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_call(char *);
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();
    }
    gen_call("ccgchar");
  } else if (typeobj == ((1 << 2) + 1)) {
    if (reg & 1 << 2) {
      gen_swap();
    }
    output_line("ld l,(hl)");
    output_line("ld h,0");
  } else {
    output_line("ld a,(hl)");
    output_line("inc hl");
    output_line("ld h,(hl)");
    output_line("ld l,a");
  }
}


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    1175 <gen_get_indirect+0x45>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1164 <gen_get_indirect+0x34>
mov    $0x0,%al
call   1030 <gen_swap@plt>
lea    0xe95(%rip),%rdi
call   1050 <gen_call@plt>
jmp    11ea <gen_get_indirect+0xba>
movsbl -0x1(%rbp),%eax
cmp    $0x5,%eax
jne    11b5 <gen_get_indirect+0x85>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1198 <gen_get_indirect+0x68>
mov    $0x0,%al
call   1030 <gen_swap@plt>
lea    0xe69(%rip),%rdi
call   1040 <output_line@plt>
lea    0xe67(%rip),%rdi
call   1040 <output_line@plt>
jmp    11e5 <gen_get_indirect+0xb5>
lea    0xe5d(%rip),%rdi
call   1040 <output_line@plt>
lea    0xe5b(%rip),%rdi
call   1040 <output_line@plt>
lea    0xe56(%rip),%rdi
call   1040 <output_line@plt>
lea    0xe54(%rip),%rdi
call   1040 <output_line@plt>
jmp    11ea <gen_get_indirect+0xba>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_get_indirect>:
push   %rax
cmp    $0x5,%dil
je     1157 <gen_get_indirect+0x27>
cmp    $0x4,%dil
jne    117d <gen_get_indirect+0x4d>
test   $0x4,%sil
je     114a <gen_get_indirect+0x1a>
xor    %eax,%eax
call   1030 <gen_swap@plt>
lea    0xeaf(%rip),%rdi
pop    %rax
jmp    1050 <gen_call@plt>
test   $0x4,%sil
je     1164 <gen_get_indirect+0x34>
xor    %eax,%eax
call   1030 <gen_swap@plt>
lea    0xe9d(%rip),%rdi
call   1040 <output_line@plt>
lea    0xe9b(%rip),%rdi
pop    %rax
jmp    1040 <output_line@plt>
lea    0xe95(%rip),%rdi
call   1040 <output_line@plt>
lea    0xe93(%rip),%rdi
call   1040 <output_line@plt>
lea    0xe8e(%rip),%rdi
call   1040 <output_line@plt>
lea    0xe8c(%rip),%rdi
pop    %rax
jmp    1040 <output_line@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"ccgchar\00"
@.str.1 = [10 x i8] c"ld l,(hl)\00"
@.str.2 = [7 x i8] c"ld h,0\00"
@.str.3 = [10 x i8] c"ld a,(hl)\00"
@.str.4 = [7 x i8] c"inc hl\00"
@.str.5 = [10 x i8] c"ld h,(hl)\00"
@.str.6 = [7 x i8] c"ld l,a\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 @gen_call(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %35
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 %29
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 ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %34
29: ; preds = %16
%30 = call i32 @output_line(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @output_line(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %34
34: ; preds = %29, %26
br label %35
35: ; preds = %34, %14
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"ccgchar\00"
@.str.1 = [10 x i8] c"ld l,(hl)\00"
@.str.2 = [7 x i8] c"ld h,0\00"
@.str.3 = [10 x i8] c"ld a,(hl)\00"
@.str.4 = [7 x i8] c"inc hl\00"
@.str.5 = [10 x i8] c"ld h,(hl)\00"
@.str.6 = [7 x i8] c"ld l,a\00"
define void @gen_get_indirect(i8 signext %0, i32 %1) {
switch i8 %0, label %18 [
i8 4, label %3
i8 5, label %10
]
3: ; preds = %2
%4 = and i32 %1, 4
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 (...) @gen_swap()
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @gen_call(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %23
10: ; preds = %2
%11 = and i32 %1, 4
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 (...) @gen_swap()
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @output_line(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %23
18: ; preds = %2
%19 = tail call i32 @output_line(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @output_line(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%22 = tail call i32 @output_line(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %23
23: ; preds = %15, %18, %8
ret void
}