#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 sb_image_ctx {
  int dummy;
};

/* Variables and functions */
int sb_fixup_sections_and_tags(struct sb_image_ctx *);
int sb_load_cmdfile(struct sb_image_ctx *);
int sb_postfill_image_header(struct sb_image_ctx *);
int sb_prefill_image_header(struct sb_image_ctx *);
int sb_build_tree_from_cfg(struct sb_image_ctx *ictx) {
  int ret;
  ret = sb_load_cmdfile(ictx);
  if (ret)
    return ret;
  ret = sb_prefill_image_header(ictx);
  if (ret)
    return ret;
  ret = sb_postfill_image_header(ictx);
  if (ret)
    return ret;
  ret = sb_fixup_sections_and_tags(ictx);
  if (ret)
    return ret;
  return 0;
}


x86 assembly (clang, -O0):
<sb_build_tree_from_cfg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sb_load_cmdfile@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     116d <sb_build_tree_from_cfg+0x2d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d7 <sb_build_tree_from_cfg+0x97>
mov    -0x10(%rbp),%rdi
call   1030 <sb_prefill_image_header@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     118e <sb_build_tree_from_cfg+0x4e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d7 <sb_build_tree_from_cfg+0x97>
mov    -0x10(%rbp),%rdi
call   1050 <sb_postfill_image_header@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11af <sb_build_tree_from_cfg+0x6f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d7 <sb_build_tree_from_cfg+0x97>
mov    -0x10(%rbp),%rdi
call   1040 <sb_fixup_sections_and_tags@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d0 <sb_build_tree_from_cfg+0x90>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d7 <sb_build_tree_from_cfg+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sb_build_tree_from_cfg>:
push   %rbx
mov    %rdi,%rbx
call   1060 <sb_load_cmdfile@plt>
test   %eax,%eax
jne    1165 <sb_build_tree_from_cfg+0x25>
mov    %rbx,%rdi
call   1030 <sb_prefill_image_header@plt>
test   %eax,%eax
jne    1165 <sb_build_tree_from_cfg+0x25>
mov    %rbx,%rdi
call   1050 <sb_postfill_image_header@plt>
test   %eax,%eax
je     1167 <sb_build_tree_from_cfg+0x27>
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <sb_fixup_sections_and_tags@plt>

LLVM IR (-O0):
%struct.sb_image_ctx = type { i32 }
define i32 @sb_build_tree_from_cfg(%struct.sb_image_ctx* %0) {
%2 = alloca i32
%3 = alloca %struct.sb_image_ctx*
%4 = alloca i32
store %struct.sb_image_ctx* %0, %struct.sb_image_ctx** %3
%5 = load %struct.sb_image_ctx*, %struct.sb_image_ctx** %3
%6 = call i32 @sb_load_cmdfile(%struct.sb_image_ctx* %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* %4
store i32 %10, i32* %2
br label %33
11: ; preds = %1
%12 = load %struct.sb_image_ctx*, %struct.sb_image_ctx** %3
%13 = call i32 @sb_prefill_image_header(%struct.sb_image_ctx* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %33
18: ; preds = %11
%19 = load %struct.sb_image_ctx*, %struct.sb_image_ctx** %3
%20 = call i32 @sb_postfill_image_header(%struct.sb_image_ctx* %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %33
25: ; preds = %18
%26 = load %struct.sb_image_ctx*, %struct.sb_image_ctx** %3
%27 = call i32 @sb_fixup_sections_and_tags(%struct.sb_image_ctx* %26)
store i32 %27, i32* %4
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = load i32, i32* %4
store i32 %31, i32* %2
br label %33
32: ; preds = %25
store i32 0, i32* %2
br label %33
33: ; preds = %32, %30, %23, %16, %9
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
%struct.sb_image_ctx = type { i32 }
define i32 @sb_build_tree_from_cfg(%struct.sb_image_ctx* %0) {
%2 = tail call i32 @sb_load_cmdfile(%struct.sb_image_ctx* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = tail call i32 @sb_prefill_image_header(%struct.sb_image_ctx* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 @sb_postfill_image_header(%struct.sb_image_ctx* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @sb_fixup_sections_and_tags(%struct.sb_image_ctx* %0)
br label %12
12: ; preds = %10, %7, %4, %1
%13 = phi i32 [ %2, %1 ], [ %5, %4 ], [ %8, %7 ], [ %11, %10 ]
ret i32 %13
}