#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 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_otp(struct bladerf *dev, char *otp) {
  int status, restore_status;
  const uint16_t dummy_page = 0;
  status = change_setting(dev, 2);
  if (status) {
    return status;
  }
  status = read_page(dev, 103, dummy_page, (uint8_t *)otp);
  restore_status = restore_post_flash_setting(dev);
  return status == 0 ? restore_status : status;
}


x86 assembly (clang, -O0):
<usb_get_otp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1030 <change_setting@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     116d <usb_get_otp+0x3d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <usb_get_otp+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x67,%esi
xor    %edx,%edx
call   1040 <read_page@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <restore_post_flash_setting@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11a5 <usb_get_otp+0x75>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11ab <usb_get_otp+0x7b>
mov    -0x1c(%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_otp>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2,%esi
call   1030 <change_setting@plt>
test   %eax,%eax
jne    1169 <usb_get_otp+0x39>
mov    %rbx,%rdi
mov    $0x67,%esi
xor    %edx,%edx
mov    %r14,%rcx
call   1040 <read_page@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <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_otp(%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* %8
%9 = load %struct.bladerf*, %struct.bladerf** %4
%10 = call i32 @change_setting(%struct.bladerf* %9, i32 2)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %6
store i32 %14, i32* %3
br label %30
15: ; preds = %2
%16 = load %struct.bladerf*, %struct.bladerf** %4
%17 = load i8*, i8** %5
%18 = bitcast i8* %17 to i32*
%19 = call i32 @read_page(%struct.bladerf* %16, i32 103, i32 0, i32* %18)
store i32 %19, i32* %6
%20 = load %struct.bladerf*, %struct.bladerf** %4
%21 = call i32 @restore_post_flash_setting(%struct.bladerf* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = load i32, i32* %7
br label %28
26: ; preds = %15
%27 = load i32, i32* %6
br label %28
28: ; preds = %26, %24
%29 = phi i32 [ %25, %24 ], [ %27, %26 ]
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %13
%31 = load i32, i32* %3
ret i32 %31
}

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