#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 exfat_user_input {
  int dummy;
};
struct exfat_blk_dev {
  int dummy;
};

/* Variables and functions */
int exfat_write_boot_sector(struct exfat_blk_dev *, struct exfat_user_input *,
                            unsigned int *, int);
int exfat_write_checksum_sector(struct exfat_blk_dev *, unsigned int, int);
int exfat_write_extended_boot_sectors(struct exfat_blk_dev *, unsigned int *,
                                      int);
int exfat_write_oem_sector(struct exfat_blk_dev *, unsigned int *, int);
int exfat_create_volume_boot_record(struct exfat_blk_dev *bd,
                                    struct exfat_user_input *ui,
                                    bool is_backup) {
  unsigned int checksum = 0;
  int ret;
  ret = exfat_write_boot_sector(bd, ui, &checksum, is_backup);
  if (ret)
    return ret;
  ret = exfat_write_extended_boot_sectors(bd, &checksum, is_backup);
  if (ret)
    return ret;
  ret = exfat_write_oem_sector(bd, &checksum, is_backup);
  if (ret)
    return ret;
  return exfat_write_checksum_sector(bd, checksum, is_backup);
}


x86 assembly (clang, -O0):
<exfat_create_volume_boot_record>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
lea    -0x20(%rbp),%rdx
call   1030 <exfat_write_boot_sector@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1186 <exfat_create_volume_boot_record+0x46>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <exfat_create_volume_boot_record+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1050 <exfat_write_extended_boot_sectors@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11ae <exfat_create_volume_boot_record+0x6e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <exfat_create_volume_boot_record+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1040 <exfat_write_oem_sector@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11d6 <exfat_create_volume_boot_record+0x96>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <exfat_create_volume_boot_record+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1060 <exfat_write_checksum_sector@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exfat_create_volume_boot_record>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %ebp,%ecx
call   1030 <exfat_write_boot_sector@plt>
test   %eax,%eax
jne    1194 <exfat_create_volume_boot_record+0x54>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1050 <exfat_write_extended_boot_sectors@plt>
test   %eax,%eax
jne    1194 <exfat_create_volume_boot_record+0x54>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <exfat_write_oem_sector@plt>
test   %eax,%eax
jne    1194 <exfat_create_volume_boot_record+0x54>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <exfat_write_checksum_sector@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.exfat_blk_dev = type { i32 }
%struct.exfat_user_input = type { i32 }
define i32 @exfat_create_volume_boot_record(%struct.exfat_blk_dev* %0, %struct.exfat_user_input* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.exfat_blk_dev*
%6 = alloca %struct.exfat_user_input*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.exfat_blk_dev* %0, %struct.exfat_blk_dev** %5
store %struct.exfat_user_input* %1, %struct.exfat_user_input** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%10 = load %struct.exfat_blk_dev*, %struct.exfat_blk_dev** %5
%11 = load %struct.exfat_user_input*, %struct.exfat_user_input** %6
%12 = load i32, i32* %7
%13 = call i32 @exfat_write_boot_sector(%struct.exfat_blk_dev* %10, %struct.exfat_user_input* %11, i32* %8, i32 %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i32, i32* %9
store i32 %17, i32* %4
br label %39
18: ; preds = %3
%19 = load %struct.exfat_blk_dev*, %struct.exfat_blk_dev** %5
%20 = load i32, i32* %7
%21 = call i32 @exfat_write_extended_boot_sectors(%struct.exfat_blk_dev* %19, i32* %8, i32 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i32, i32* %9
store i32 %25, i32* %4
br label %39
26: ; preds = %18
%27 = load %struct.exfat_blk_dev*, %struct.exfat_blk_dev** %5
%28 = load i32, i32* %7
%29 = call i32 @exfat_write_oem_sector(%struct.exfat_blk_dev* %27, i32* %8, i32 %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = load i32, i32* %9
store i32 %33, i32* %4
br label %39
34: ; preds = %26
%35 = load %struct.exfat_blk_dev*, %struct.exfat_blk_dev** %5
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = call i32 @exfat_write_checksum_sector(%struct.exfat_blk_dev* %35, i32 %36, i32 %37)
store i32 %38, i32* %4
br label %39
39: ; preds = %34, %32, %24, %16
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
%struct.exfat_blk_dev = type { i32 }
%struct.exfat_user_input = type { i32 }
define i32 @exfat_create_volume_boot_record(%struct.exfat_blk_dev* %0, %struct.exfat_user_input* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = call i32 @exfat_write_boot_sector(%struct.exfat_blk_dev* %0, %struct.exfat_user_input* %1, i32* %4, i32 %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = call i32 @exfat_write_extended_boot_sectors(%struct.exfat_blk_dev* %0, i32* %4, i32 %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = call i32 @exfat_write_oem_sector(%struct.exfat_blk_dev* %0, i32* %4, i32 %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %4
%16 = call i32 @exfat_write_checksum_sector(%struct.exfat_blk_dev* %0, i32 %15, i32 %2)
br label %17
17: ; preds = %11, %8, %3, %14
%18 = phi i32 [ %16, %14 ], [ %6, %3 ], [ %9, %8 ], [ %12, %11 ]
ret i32 %18
}