#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_build_image(struct sb_image_ctx *);
int sb_build_tree_from_cfg(struct sb_image_ctx *);
int sb_encrypt_image(struct sb_image_ctx *);
int /*<<< orphan*/ sb_free_image(struct sb_image_ctx *);
int mxsimage_generate(struct sb_image_ctx *ctx) {
  int ret;
  ret = sb_build_tree_from_cfg(ctx);
  if (ret)
    goto fail;
  ret = sb_encrypt_image(ctx);
  if (!ret)
    ret = sb_build_image(ctx);
fail:
  sb_free_image(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<mxsimage_generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <sb_build_tree_from_cfg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1167 <mxsimage_generate+0x27>
jmp    118e <mxsimage_generate+0x4e>
mov    -0x8(%rbp),%rdi
call   1060 <sb_encrypt_image@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1189 <mxsimage_generate+0x49>
mov    -0x8(%rbp),%rdi
call   1050 <sb_build_image@plt>
mov    %eax,-0xc(%rbp)
jmp    118e <mxsimage_generate+0x4e>
mov    -0x8(%rbp),%rdi
call   1040 <sb_free_image@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mxsimage_generate>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <sb_build_tree_from_cfg@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1169 <mxsimage_generate+0x29>
mov    %rbx,%rdi
call   1060 <sb_encrypt_image@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1169 <mxsimage_generate+0x29>
mov    %rbx,%rdi
call   1050 <sb_build_image@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <sb_free_image@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sb_image_ctx = type { i32 }
define i32 @mxsimage_generate(%struct.sb_image_ctx* %0) {
%2 = alloca %struct.sb_image_ctx*
%3 = alloca i32
store %struct.sb_image_ctx* %0, %struct.sb_image_ctx** %2
%4 = load %struct.sb_image_ctx*, %struct.sb_image_ctx** %2
%5 = call i32 @sb_build_tree_from_cfg(%struct.sb_image_ctx* %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %18
9: ; preds = %1
%10 = load %struct.sb_image_ctx*, %struct.sb_image_ctx** %2
%11 = call i32 @sb_encrypt_image(%struct.sb_image_ctx* %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load %struct.sb_image_ctx*, %struct.sb_image_ctx** %2
%16 = call i32 @sb_build_image(%struct.sb_image_ctx* %15)
store i32 %16, i32* %3
br label %17
17: ; preds = %14, %9
br label %18
18: ; preds = %17, %8
%19 = load %struct.sb_image_ctx*, %struct.sb_image_ctx** %2
%20 = call i32 @sb_free_image(%struct.sb_image_ctx* %19)
%21 = load i32, i32* %3
ret i32 %21
}

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