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

/* Variables and functions */
int /*<<< orphan*/ free(struct ic_ast *);
struct ic_decl *ic_ast_get(struct ic_ast *, unsigned int);
unsigned int ic_ast_length(struct ic_ast *);
int /*<<< orphan*/ ic_decl_destroy(struct ic_decl *, int);
int /*<<< orphan*/ puts(char *);
unsigned int ic_ast_destroy(struct ic_ast *ast, unsigned int free_ast) {
  unsigned int i = 0;
  unsigned int len = 0;
  struct ic_decl *decl = 0;
  if (!ast) {
    puts("ic_ast_destroy");
    return 0;
  }
  len = ic_ast_length(ast);
  for (i = 0; i < len; ++i) {
    decl = ic_ast_get(ast, i);
    if (!decl) {
      puts("ic_ast_destroy: call to ic_ast_get failed");
      return 0;
    }
    if (!ic_decl_destroy(decl, 1)) {
      puts("ic_ast_destroy: call to ic_decl_destroy failed");
      return 0;
    }
  }
  if (free_ast) {
    free(ast);
  }
  return 1;
}


x86 assembly (clang, -O0):
<ic_ast_destroy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1198 <ic_ast_destroy+0x48>
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1246 <ic_ast_destroy+0xf6>
mov    -0x10(%rbp),%rdi
call   1060 <ic_ast_length@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    122c <ic_ast_destroy+0xdc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <ic_ast_get@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ea <ic_ast_destroy+0x9a>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1246 <ic_ast_destroy+0xf6>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1070 <ic_decl_destroy@plt>
cmp    $0x0,%eax
jne    1219 <ic_ast_destroy+0xc9>
lea    0xe31(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1246 <ic_ast_destroy+0xf6>
jmp    121e <ic_ast_destroy+0xce>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ab <ic_ast_destroy+0x5b>
cmpl   $0x0,-0x14(%rbp)
je     123f <ic_ast_destroy+0xef>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ic_ast_destroy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11ac <ic_ast_destroy+0x5c>
mov    %esi,%r14d
mov    %rdi,%rbx
call   1060 <ic_ast_length@plt>
test   %eax,%eax
je     1198 <ic_ast_destroy+0x48>
mov    %eax,%r15d
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <ic_ast_get@plt>
test   %rax,%rax
je     11b5 <ic_ast_destroy+0x65>
mov    %rax,%rdi
mov    $0x1,%esi
call   1070 <ic_decl_destroy@plt>
test   %eax,%eax
je     11be <ic_ast_destroy+0x6e>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1170 <ic_ast_destroy+0x20>
mov    $0x1,%ebp
test   %r14d,%r14d
je     11cc <ic_ast_destroy+0x7c>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11cc <ic_ast_destroy+0x7c>
lea    0xe4d(%rip),%rdi
jmp    11c5 <ic_ast_destroy+0x75>
lea    0xe53(%rip),%rdi
jmp    11c5 <ic_ast_destroy+0x75>
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ic_ast = type { i32 }
%struct.ic_decl = type { i32 }
@.str = [15 x i8] c"ic_ast_destroy\00"
@.str.1 = [42 x i8] c"ic_ast_destroy: call to ic_ast_get failed\00"
@.str.2 = [47 x i8] c"ic_ast_destroy: call to ic_decl_destroy failed\00"
define i32 @ic_ast_destroy(%struct.ic_ast* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.ic_ast*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ic_decl*
store %struct.ic_ast* %0, %struct.ic_ast** %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store %struct.ic_decl* null, %struct.ic_decl** %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 ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %45
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* %7
store i32 0, i32* %6
br label %16
16: ; preds = %35, %13
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load %struct.ic_ast*, %struct.ic_ast** %4
%22 = load i32, i32* %6
%23 = call %struct.ic_decl* @ic_ast_get(%struct.ic_ast* %21, i32 %22)
store %struct.ic_decl* %23, %struct.ic_decl** %8
%24 = load %struct.ic_decl*, %struct.ic_decl** %8
%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 ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %45
28: ; preds = %20
%29 = load %struct.ic_decl*, %struct.ic_decl** %8
%30 = call i32 @ic_decl_destroy(%struct.ic_decl* %29, i32 1)
%31 = icmp ne i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %45
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add i32 %36, 1
store i32 %37, i32* %6
br label %16
38: ; preds = %16
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load %struct.ic_ast*, %struct.ic_ast** %4
%43 = call i32 @free(%struct.ic_ast* %42)
br label %44
44: ; preds = %41, %38
store i32 1, i32* %3
br label %45
45: ; preds = %44, %32, %26, %11
%46 = load i32, i32* %3
ret i32 %46
}

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