#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;
};

/* Variables and functions */
int /*<<< orphan*/ ic_type_ref_destroy(struct ic_type_ref *, int);
struct ic_type_ref *ic_type_ref_new();
int /*<<< orphan*/ ic_type_ref_set_symbol(struct ic_type_ref *, char *,
                                          unsigned int);
int /*<<< orphan*/ puts(char *);
struct ic_type_ref *ic_type_ref_symbol_new(char *type_str,
                                           unsigned int type_len) {
  struct ic_type_ref *type = 0;
  if (!type_str) {
    puts("ic_type_ref_symbol_new: type_str was null");
    return 0;
  }
  type = ic_type_ref_new();
  if (!type) {
    puts("ic_type_ref_symbol_new: call to ic_type_new failed");
    return 0;
  }
  if (!ic_type_ref_set_symbol(type, type_str, type_len)) {
    puts("ic_type_ref_symbol_new: call to ic_type_set_symbol failed");
    ic_type_ref_destroy(type, 1);
    return 0;
  }
  return type;
}


x86 assembly (clang, -O0):
<ic_type_ref_symbol_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117b <ic_type_ref_symbol_new+0x3b>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f2 <ic_type_ref_symbol_new+0xb2>
mov    $0x0,%al
call   1060 <ic_type_ref_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11aa <ic_type_ref_symbol_new+0x6a>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f2 <ic_type_ref_symbol_new+0xb2>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <ic_type_ref_set_symbol@plt>
cmp    $0x0,%eax
jne    11ea <ic_type_ref_symbol_new+0xaa>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1050 <ic_type_ref_destroy@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f2 <ic_type_ref_symbol_new+0xb2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ic_type_ref_symbol_new>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     118b <ic_type_ref_symbol_new+0x4b>
mov    %esi,%r14d
mov    %rdi,%rbp
xor    %eax,%eax
call   1060 <ic_type_ref_new@plt>
test   %rax,%rax
je     1194 <ic_type_ref_symbol_new+0x54>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <ic_type_ref_set_symbol@plt>
test   %eax,%eax
jne    11a2 <ic_type_ref_symbol_new+0x62>
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <ic_type_ref_destroy@plt>
jmp    11a0 <ic_type_ref_symbol_new+0x60>
lea    0xe6e(%rip),%rdi
jmp    119b <ic_type_ref_symbol_new+0x5b>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ic_type_ref = type { i32 }
@.str = [42 x i8] c"ic_type_ref_symbol_new: type_str was null\00"
@.str.1 = [51 x i8] c"ic_type_ref_symbol_new: call to ic_type_new failed\00"
@.str.2 = [58 x i8] c"ic_type_ref_symbol_new: call to ic_type_set_symbol failed\00"
define %struct.ic_type_ref* @ic_type_ref_symbol_new(i8* %0, i32 %1) {
%3 = alloca %struct.ic_type_ref*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.ic_type_ref*
store i8* %0, i8** %4
store i32 %1, i32* %5
store %struct.ic_type_ref* null, %struct.ic_type_ref** %6
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store %struct.ic_type_ref* null, %struct.ic_type_ref** %3
br label %29
11: ; preds = %2
%12 = call %struct.ic_type_ref* (...) @ic_type_ref_new()
store %struct.ic_type_ref* %12, %struct.ic_type_ref** %6
%13 = load %struct.ic_type_ref*, %struct.ic_type_ref** %6
%14 = icmp ne %struct.ic_type_ref* %13, null
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
store %struct.ic_type_ref* null, %struct.ic_type_ref** %3
br label %29
17: ; preds = %11
%18 = load %struct.ic_type_ref*, %struct.ic_type_ref** %6
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = call i32 @ic_type_ref_set_symbol(%struct.ic_type_ref* %18, i8* %19, i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %17
%24 = call i32 @puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
%25 = load %struct.ic_type_ref*, %struct.ic_type_ref** %6
%26 = call i32 @ic_type_ref_destroy(%struct.ic_type_ref* %25, i32 1)
store %struct.ic_type_ref* null, %struct.ic_type_ref** %3
br label %29
27: ; preds = %17
%28 = load %struct.ic_type_ref*, %struct.ic_type_ref** %6
store %struct.ic_type_ref* %28, %struct.ic_type_ref** %3
br label %29
29: ; preds = %27, %23, %15, %9
%30 = load %struct.ic_type_ref*, %struct.ic_type_ref** %3
ret %struct.ic_type_ref* %30
}

LLVM IR (-O2):
%struct.ic_type_ref = type { i32 }
@.str = [42 x i8] c"ic_type_ref_symbol_new: type_str was null\00"
@.str.1 = [51 x i8] c"ic_type_ref_symbol_new: call to ic_type_new failed\00"
@.str.2 = [58 x i8] c"ic_type_ref_symbol_new: call to ic_type_set_symbol failed\00"
define %struct.ic_type_ref* @ic_type_ref_symbol_new(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %17
6: ; preds = %2
%7 = tail call %struct.ic_type_ref* (...) @ic_type_ref_new()
%8 = icmp eq %struct.ic_type_ref* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %17
11: ; preds = %6
%12 = tail call i32 @ic_type_ref_set_symbol(%struct.ic_type_ref* %7, i8* %0, i32 %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @ic_type_ref_destroy(%struct.ic_type_ref* %7, i32 1)
br label %17
17: ; preds = %11, %14, %9, %4
%18 = phi %struct.ic_type_ref* [ null, %14 ], [ null, %9 ], [ null, %4 ], [ %7, %11 ]
ret %struct.ic_type_ref* %18
}