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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int change_setting(struct bladerf *, int);
int read_page(struct bladerf *, int, scalar_t__ const, int /*<<< orphan*/ *);
int restore_post_flash_setting(struct bladerf *);
int usb_read_flash_pages(struct bladerf *dev, uint8_t *buf, uint32_t page_u32,
                         uint32_t count_u32) {
  int status;
  size_t n_read;
  uint16_t i;
  const uint16_t page = (uint16_t)page_u32;
  const uint16_t count = (uint16_t)count_u32;
  assert(page == page_u32);
  assert(count == count_u32);
  status = change_setting(dev, 2);
  if (status != 0) {
    return status;
  }
  do {
    do {
    } while (0);
  } while (0);
  for (n_read = i = 0; i < count; i++) {
    do {
      do {
      } while (0);
    } while (0);
    status = read_page(dev, 100, page + i, buf + n_read);
    if (status != 0) {
      goto error;
    }
    n_read += 256;
  }
  do {
    do {
    } while (0);
  } while (0);
error:
  status = restore_post_flash_setting(dev);
  return status;
}


x86 assembly (clang, -O0):
<usb_read_flash_pages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x50(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1030 <change_setting@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11b8 <usb_read_flash_pages+0x78>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127f <usb_read_flash_pages+0x13f>
jmp    11bd <usb_read_flash_pages+0x7d>
jmp    11c2 <usb_read_flash_pages+0x82>
jmp    11c7 <usb_read_flash_pages+0x87>
jmp    11cc <usb_read_flash_pages+0x8c>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x50(%rbp),%rax
jge    1254 <usb_read_flash_pages+0x114>
jmp    11ef <usb_read_flash_pages+0xaf>
jmp    11f4 <usb_read_flash_pages+0xb4>
jmp    11f9 <usb_read_flash_pages+0xb9>
jmp    11fe <usb_read_flash_pages+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
add    -0x40(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    $0x64,%esi
call   1050 <read_page@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1235 <usb_read_flash_pages+0xf5>
jmp    126d <usb_read_flash_pages+0x12d>
mov    -0x38(%rbp),%rax
add    $0x100,%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11dc <usb_read_flash_pages+0x9c>
jmp    1259 <usb_read_flash_pages+0x119>
jmp    125e <usb_read_flash_pages+0x11e>
jmp    1263 <usb_read_flash_pages+0x123>
jmp    1268 <usb_read_flash_pages+0x128>
jmp    126d <usb_read_flash_pages+0x12d>
mov    -0x10(%rbp),%rdi
call   1060 <restore_post_flash_setting@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_read_flash_pages>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x1,%edi
call   1040 <assert@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
mov    %r15,%rdi
mov    $0x2,%esi
call   1030 <change_setting@plt>
test   %eax,%eax
je     1185 <usb_read_flash_pages+0x45>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
test   %r14,%r14
jle    11b8 <usb_read_flash_pages+0x78>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <read_page@plt>
test   %eax,%eax
jne    11b8 <usb_read_flash_pages+0x78>
add    $0x1,%r12
add    $0x400,%rbx
add    $0xffffffffffffffff,%r14
jne    1190 <usb_read_flash_pages+0x50>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <restore_post_flash_setting@plt>

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

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