#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_decl {
  int dummy;
};
struct ic_ast {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
struct ic_decl *ic_ast_get(struct ic_ast *, unsigned int);
unsigned int ic_ast_length(struct ic_ast *);
int /*<<< orphan*/ ic_decl_print(int /*<<< orphan*/ *, struct ic_decl *,
                                 unsigned int *);
int /*<<< orphan*/ puts(char *);
void ic_ast_print(FILE *fd, struct ic_ast *ast) {
  unsigned int i = 0;
  unsigned int len = 0;
  struct ic_decl *decl = 0;
  unsigned int indent_level = 0;
  if (!ast) {
    puts("ic_ast_print: ast was null");
    return;
  }
  len = ic_ast_length(ast);
  for (i = 0; i < len; ++i) {
    decl = ic_ast_get(ast, i);
    if (!decl) {
      puts("ic_ast_print: call to ic_ast_get failed");
      return;
    }
    ic_decl_print(fd, decl, &indent_level);
    if (i < (len - 1)) {
      fputs("\n", fd);
    }
  }
}


x86 assembly (clang, -O0):
<ic_ast_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <ic_ast_print+0x49>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
jmp    1229 <ic_ast_print+0xd9>
mov    -0x10(%rbp),%rdi
call   1060 <ic_ast_length@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1229 <ic_ast_print+0xd9>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <ic_ast_get@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e4 <ic_ast_print+0x94>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
jmp    1229 <ic_ast_print+0xd9>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1030 <ic_decl_print@plt>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    1216 <ic_ast_print+0xc6>
mov    -0x8(%rbp),%rsi
lea    0xe32(%rip),%rdi
call   1070 <fputs@plt>
jmp    121b <ic_ast_print+0xcb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ac <ic_ast_print+0x5c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ic_ast_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
test   %rsi,%rsi
je     11c9 <ic_ast_print+0x79>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1060 <ic_ast_length@plt>
test   %eax,%eax
je     11ef <ic_ast_print+0x9f>
mov    %eax,%r15d
lea    -0x1(%r15),%r13d
xor    %ebp,%ebp
lea    0x4(%rsp),%r12
jmp    1198 <ic_ast_print+0x48>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%r15d
je     11ef <ic_ast_print+0x9f>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <ic_ast_get@plt>
test   %rax,%rax
je     11e3 <ic_ast_print+0x93>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
call   1030 <ic_decl_print@plt>
cmp    %r13d,%ebp
jae    1190 <ic_ast_print+0x40>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
jmp    1190 <ic_ast_print+0x40>
lea    0xe30(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>
lea    0xe31(%rip),%rdi
call   1040 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ic_ast = type { i32 }
%struct.ic_decl = type { i32 }
@.str = [27 x i8] c"ic_ast_print: ast was null\00"
@.str.1 = [40 x i8] c"ic_ast_print: call to ic_ast_get failed\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @ic_ast_print(i32* %0, %struct.ic_ast* %1) {
%3 = alloca i32*
%4 = alloca %struct.ic_ast*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.ic_decl*
%8 = alloca i32
store i32* %0, i32** %3
store %struct.ic_ast* %1, %struct.ic_ast** %4
store i32 0, i32* %5
store i32 0, i32* %6
store %struct.ic_decl* null, %struct.ic_decl** %7
store i32 0, i32* %8
%9 = load %struct.ic_ast*, %struct.ic_ast** %4
%10 = icmp ne %struct.ic_ast* %9, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %43
13: ; preds = %2
%14 = load %struct.ic_ast*, %struct.ic_ast** %4
%15 = call i32 @ic_ast_length(%struct.ic_ast* %14)
store i32 %15, i32* %6
store i32 0, i32* %5
br label %16
16: ; preds = %40, %13
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = load %struct.ic_ast*, %struct.ic_ast** %4
%22 = load i32, i32* %5
%23 = call %struct.ic_decl* @ic_ast_get(%struct.ic_ast* %21, i32 %22)
store %struct.ic_decl* %23, %struct.ic_decl** %7
%24 = load %struct.ic_decl*, %struct.ic_decl** %7
%25 = icmp ne %struct.ic_decl* %24, null
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %43
28: ; preds = %20
%29 = load i32*, i32** %3
%30 = load %struct.ic_decl*, %struct.ic_decl** %7
%31 = call i32 @ic_decl_print(i32* %29, %struct.ic_decl* %30, i32* %8)
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = sub i32 %33, 1
%35 = icmp ult i32 %32, %34
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i32*, i32** %3
%38 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32* %37)
br label %39
39: ; preds = %36, %28
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add i32 %41, 1
store i32 %42, i32* %5
br label %16
43: ; preds = %11, %26, %16
ret void
}

LLVM IR (-O2):
%struct.ic_ast = type { i32 }
%struct.ic_decl = type { i32 }
@.str = [27 x i8] c"ic_ast_print: ast was null\00"
@.str.1 = [40 x i8] c"ic_ast_print: call to ic_ast_get failed\00"
define void @ic_ast_print(i32* %0, %struct.ic_ast* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp eq %struct.ic_ast* %1, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %27
8: ; preds = %2
%9 = tail call i32 @ic_ast_length(%struct.ic_ast* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %27, label %11
11: ; preds = %8
%12 = add i32 %9, -1
br label %13
13: ; preds = %11, %24
%14 = phi i32 [ 0, %11 ], [ %25, %24 ]
%15 = call %struct.ic_decl* @ic_ast_get(%struct.ic_ast* %1, i32 %14)
%16 = icmp eq %struct.ic_decl* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %27
19: ; preds = %13
%20 = call i32 @ic_decl_print(i32* %0, %struct.ic_decl* %15, i32* %3)
%21 = icmp ult i32 %14, %12
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @fputc(i32 10, i32* %0)
br label %24
24: ; preds = %19, %22
%25 = add nuw i32 %14, 1
%26 = icmp eq i32 %25, %9
br i1 %26, label %27, label %13
27: ; preds = %24, %8, %17, %6
ret void
}