#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 */
typedef scalar_t__ uint32_t;
typedef scalar_t__ uint16_t;
struct bladerf {
  int dummy;
};

/* Variables and functions */
int change_setting(struct bladerf *, int);
int perform_erase(struct bladerf *, scalar_t__);
int restore_post_flash_setting(struct bladerf *);
int usb_erase_flash_blocks(struct bladerf *dev, uint32_t eb, uint16_t count) {
  int status, restore_status;
  uint16_t i;
  status = change_setting(dev, 2);
  if (status != 0) {
    return status;
  }
  do {
    do {
    } while (0);
  } while (0);
  for (i = 0; i < count; i++) {
    status = perform_erase(dev, eb + i);
    if (status == 0) {
      do {
        do {
        } while (0);
      } while (0);
    } else {
      do {
        do {
        } while (0);
      } while (0);
      goto error;
    }
  }
  do {
    do {
    } while (0);
  } while (0);
error:
  restore_status = restore_post_flash_setting(dev);
  return status != 0 ? status : restore_status;
}


x86 assembly (clang, -O0):
<usb_erase_flash_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1030 <change_setting@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     116a <usb_erase_flash_blocks+0x3a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <usb_erase_flash_blocks+0x110>
jmp    116f <usb_erase_flash_blocks+0x3f>
jmp    1174 <usb_erase_flash_blocks+0x44>
jmp    1179 <usb_erase_flash_blocks+0x49>
jmp    117e <usb_erase_flash_blocks+0x4e>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    11fa <usb_erase_flash_blocks+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    -0x30(%rbp),%rsi
call   1040 <perform_erase@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11cb <usb_erase_flash_blocks+0x9b>
jmp    11b7 <usb_erase_flash_blocks+0x87>
jmp    11bc <usb_erase_flash_blocks+0x8c>
jmp    11c1 <usb_erase_flash_blocks+0x91>
jmp    11c6 <usb_erase_flash_blocks+0x96>
jmp    11e4 <usb_erase_flash_blocks+0xb4>
jmp    11d0 <usb_erase_flash_blocks+0xa0>
jmp    11d5 <usb_erase_flash_blocks+0xa5>
jmp    11da <usb_erase_flash_blocks+0xaa>
jmp    11df <usb_erase_flash_blocks+0xaf>
jmp    1213 <usb_erase_flash_blocks+0xe3>
jmp    11e9 <usb_erase_flash_blocks+0xb9>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1186 <usb_erase_flash_blocks+0x56>
jmp    11ff <usb_erase_flash_blocks+0xcf>
jmp    1204 <usb_erase_flash_blocks+0xd4>
jmp    1209 <usb_erase_flash_blocks+0xd9>
jmp    120e <usb_erase_flash_blocks+0xde>
jmp    1213 <usb_erase_flash_blocks+0xe3>
mov    -0x10(%rbp),%rdi
call   1050 <restore_post_flash_setting@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1234 <usb_erase_flash_blocks+0x104>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    123a <usb_erase_flash_blocks+0x10a>
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_erase_flash_blocks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x2,%esi
call   1030 <change_setting@plt>
mov    %eax,%ebp
test   %eax,%eax
je     115d <usb_erase_flash_blocks+0x2d>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r15,%r15
jle    1189 <usb_erase_flash_blocks+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <perform_erase@plt>
test   %eax,%eax
jne    119b <usb_erase_flash_blocks+0x6b>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
jne    1170 <usb_erase_flash_blocks+0x40>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <restore_post_flash_setting@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <restore_post_flash_setting@plt>
jmp    1150 <usb_erase_flash_blocks+0x20>

LLVM IR (-O0):
%struct.bladerf = type { i32 }
define i32 @usb_erase_flash_blocks(%struct.bladerf* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.bladerf*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
store %struct.bladerf* %0, %struct.bladerf** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%11 = load %struct.bladerf*, %struct.bladerf** %5
%12 = call i32 @change_setting(%struct.bladerf* %11, i32 2)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %8
store i32 %16, i32* %4
br label %64
17: ; preds = %3
br label %18
18: ; preds = %17
br label %19
19: ; preds = %18
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20
store i64 0, i64* %10
br label %22
22: ; preds = %45, %21
%23 = load i64, i64* %10
%24 = load i64, i64* %7
%25 = icmp slt i64 %23, %24
br i1 %25, label %26, label %48
26: ; preds = %22
%27 = load %struct.bladerf*, %struct.bladerf** %5
%28 = load i64, i64* %6
%29 = load i64, i64* %10
%30 = add nsw i64 %28, %29
%31 = call i32 @perform_erase(%struct.bladerf* %27, i64 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %26
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
br label %44
39: ; preds = %26
br label %40
40: ; preds = %39
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
br label %53
44: ; preds = %38
br label %45
45: ; preds = %44
%46 = load i64, i64* %10
%47 = add nsw i64 %46, 1
store i64 %47, i64* %10
br label %22
48: ; preds = %22
br label %49
49: ; preds = %48
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52, %43
%54 = load %struct.bladerf*, %struct.bladerf** %5
%55 = call i32 @restore_post_flash_setting(%struct.bladerf* %54)
store i32 %55, i32* %9
%56 = load i32, i32* %8
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = load i32, i32* %8
br label %62
60: ; preds = %53
%61 = load i32, i32* %9
br label %62
62: ; preds = %60, %58
%63 = phi i32 [ %59, %58 ], [ %61, %60 ]
store i32 %63, i32* %4
br label %64
64: ; preds = %62, %15
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @usb_erase_flash_blocks(%struct.bladerf* %0, i64 %1, i64 %2) {
%4 = tail call i32 @change_setting(%struct.bladerf* %0, i32 2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = icmp sgt i64 %2, 0
br i1 %7, label %10, label %18
8: ; preds = %10
%9 = icmp eq i64 %15, %2
br i1 %9, label %18, label %10
10: ; preds = %6, %8
%11 = phi i64 [ %15, %8 ], [ 0, %6 ]
%12 = add nsw i64 %11, %1
%13 = tail call i32 @perform_erase(%struct.bladerf* %0, i64 %12)
%14 = icmp eq i32 %13, 0
%15 = add nuw nsw i64 %11, 1
br i1 %14, label %8, label %16
16: ; preds = %10
%17 = tail call i32 @restore_post_flash_setting(%struct.bladerf* %0)
br label %20
18: ; preds = %8, %6
%19 = tail call i32 @restore_post_flash_setting(%struct.bladerf* %0)
br label %20
20: ; preds = %18, %16, %3
%21 = phi i32 [ %4, %3 ], [ %19, %18 ], [ %13, %16 ]
ret i32 %21
}