#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 int /*<<< orphan*/ 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, int /*<<< orphan*/ const,
              int /*<<< orphan*/ *);
int restore_post_flash_setting(struct bladerf *);
int usb_get_cal(struct bladerf *dev, char *cal) {
  const uint16_t dummy_page = 0;
  int status, restore_status;
  assert(256 == 256);
  status = change_setting(dev, 2);
  if (status) {
    return status;
  }
  status = read_page(dev, 110, dummy_page, (uint8_t *)cal);
  restore_status = restore_post_flash_setting(dev);
  return status == 0 ? restore_status : status;
}


x86 assembly (clang, -O0):
<usb_get_cal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x1,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1030 <change_setting@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1187 <usb_get_cal+0x47>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <usb_get_cal+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x6e,%esi
xor    %edx,%edx
call   1050 <read_page@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <restore_post_flash_setting@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11bf <usb_get_cal+0x7f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11c5 <usb_get_cal+0x85>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_get_cal>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x1,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <change_setting@plt>
test   %eax,%eax
jne    1186 <usb_get_cal+0x46>
mov    %rbx,%rdi
mov    $0x6e,%esi
xor    %edx,%edx
mov    %r14,%rcx
call   1050 <read_page@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <restore_post_flash_setting@plt>
test   %ebp,%ebp
cmovne %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.bladerf = type { i32 }
define i32 @usb_get_cal(%struct.bladerf* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.bladerf*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.bladerf* %0, %struct.bladerf** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%9 = call i32 @assert(i32 1)
%10 = load %struct.bladerf*, %struct.bladerf** %4
%11 = call i32 @change_setting(%struct.bladerf* %10, i32 2)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %7
store i32 %15, i32* %3
br label %31
16: ; preds = %2
%17 = load %struct.bladerf*, %struct.bladerf** %4
%18 = load i8*, i8** %5
%19 = bitcast i8* %18 to i32*
%20 = call i32 @read_page(%struct.bladerf* %17, i32 110, i32 0, i32* %19)
store i32 %20, i32* %7
%21 = load %struct.bladerf*, %struct.bladerf** %4
%22 = call i32 @restore_post_flash_setting(%struct.bladerf* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = load i32, i32* %8
br label %29
27: ; preds = %16
%28 = load i32, i32* %7
br label %29
29: ; preds = %27, %25
%30 = phi i32 [ %26, %25 ], [ %28, %27 ]
store i32 %30, i32* %3
br label %31
31: ; preds = %29, %14
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @usb_get_cal(%struct.bladerf* %0, i8* %1) {
%3 = tail call i32 @assert(i32 1)
%4 = tail call i32 @change_setting(%struct.bladerf* %0, i32 2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = bitcast i8* %1 to i32*
%8 = tail call i32 @read_page(%struct.bladerf* %0, i32 110, i32 0, i32* %7)
%9 = tail call i32 @restore_post_flash_setting(%struct.bladerf* %0)
%10 = icmp eq i32 %8, 0
%11 = select i1 %10, i32 %9, i32 %8
br label %12
12: ; preds = %2, %6
%13 = phi i32 [ %11, %6 ], [ %4, %2 ]
ret i32 %13
}