#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 */
struct ic_type_ref {
  int dummy;
};
struct ic_symbol {
  int dummy;
};

/* Variables and functions */
char *ic_symbol_contents(struct ic_symbol *);
struct ic_symbol *ic_type_ref_get_type_name(struct ic_type_ref *);
int /*<<< orphan*/ puts(char *);
char *ic_type_ref_get_type_name_ch(struct ic_type_ref *type) {
  char *str = 0;
  struct ic_symbol *sym = 0;
  if (!type) {
    puts("ic_type_ref_get_type_name_ch: type was null");
    return 0;
  }
  sym = ic_type_ref_get_type_name(type);
  if (!sym) {
    puts("ic_type_ref_get_type_name_ch: call to ic_type_ref_get_type_name "
         "failed");
    return 0;
  }
  str = ic_symbol_contents(sym);
  if (!str) {
    puts("ic_type_ref_get_type_name_ch: call to ic_symbol_contents failed");
    return 0;
  }
  return str;
}


x86 assembly (clang, -O0):
<ic_type_ref_get_type_name_ch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1170 <ic_type_ref_get_type_name_ch+0x40>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11da <ic_type_ref_get_type_name_ch+0xaa>
mov    -0x10(%rbp),%rdi
call   1050 <ic_type_ref_get_type_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a1 <ic_type_ref_get_type_name_ch+0x71>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11da <ic_type_ref_get_type_name_ch+0xaa>
mov    -0x20(%rbp),%rdi
call   1040 <ic_symbol_contents@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <ic_type_ref_get_type_name_ch+0xa2>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11da <ic_type_ref_get_type_name_ch+0xaa>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ic_type_ref_get_type_name_ch>:
push   %rax
test   %rdi,%rdi
je     114f <ic_type_ref_get_type_name_ch+0x1f>
call   1050 <ic_type_ref_get_type_name@plt>
test   %rax,%rax
je     1158 <ic_type_ref_get_type_name_ch+0x28>
mov    %rax,%rdi
call   1040 <ic_symbol_contents@plt>
test   %rax,%rax
je     1161 <ic_type_ref_get_type_name_ch+0x31>
pop    %rcx
ret
lea    0xeaa(%rip),%rdi
jmp    1168 <ic_type_ref_get_type_name_ch+0x38>
lea    0xecd(%rip),%rdi
jmp    1168 <ic_type_ref_get_type_name_ch+0x38>
lea    0xf0b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.ic_type_ref = type { i32 }
%struct.ic_symbol = type { i32 }
@.str = [44 x i8] c"ic_type_ref_get_type_name_ch: type was null\00"
@.str.1 = [71 x i8] c"ic_type_ref_get_type_name_ch: call to ic_type_ref_get_type_name failed\00"
@.str.2 = [64 x i8] c"ic_type_ref_get_type_name_ch: call to ic_symbol_contents failed\00"
define i8* @ic_type_ref_get_type_name_ch(%struct.ic_type_ref* %0) {
%2 = alloca i8*
%3 = alloca %struct.ic_type_ref*
%4 = alloca i8*
%5 = alloca %struct.ic_symbol*
store %struct.ic_type_ref* %0, %struct.ic_type_ref** %3
store i8* null, i8** %4
store %struct.ic_symbol* null, %struct.ic_symbol** %5
%6 = load %struct.ic_type_ref*, %struct.ic_type_ref** %3
%7 = icmp ne %struct.ic_type_ref* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %26
10: ; preds = %1
%11 = load %struct.ic_type_ref*, %struct.ic_type_ref** %3
%12 = call %struct.ic_symbol* @ic_type_ref_get_type_name(%struct.ic_type_ref* %11)
store %struct.ic_symbol* %12, %struct.ic_symbol** %5
%13 = load %struct.ic_symbol*, %struct.ic_symbol** %5
%14 = icmp ne %struct.ic_symbol* %13, null
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = call i32 @puts(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %26
17: ; preds = %10
%18 = load %struct.ic_symbol*, %struct.ic_symbol** %5
%19 = call i8* @ic_symbol_contents(%struct.ic_symbol* %18)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = call i32 @puts(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %26
24: ; preds = %17
%25 = load i8*, i8** %4
store i8* %25, i8** %2
br label %26
26: ; preds = %24, %22, %15, %8
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
%struct.ic_type_ref = type { i32 }
%struct.ic_symbol = type { i32 }
@.str = [44 x i8] c"ic_type_ref_get_type_name_ch: type was null\00"
@.str.1 = [71 x i8] c"ic_type_ref_get_type_name_ch: call to ic_type_ref_get_type_name failed\00"
@.str.2 = [64 x i8] c"ic_type_ref_get_type_name_ch: call to ic_symbol_contents failed\00"
define i8* @ic_type_ref_get_type_name_ch(%struct.ic_type_ref* %0) {
%2 = icmp eq %struct.ic_type_ref* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call %struct.ic_symbol* @ic_type_ref_get_type_name(%struct.ic_type_ref* %0)
%5 = icmp eq %struct.ic_symbol* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i8* @ic_symbol_contents(%struct.ic_symbol* %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6, %3, %1
%10 = phi i8* [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), %6 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
br label %12
12: ; preds = %9, %6
%13 = phi i8* [ %7, %6 ], [ null, %9 ]
ret i8* %13
}