#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 bladerf {
  int dummy;
};

/* Variables and functions */
int change_setting(struct bladerf *, int);
int usb_is_fpga_configured(struct bladerf *);
int restore_post_flash_setting(struct bladerf *dev) {
  int fpga_loaded = usb_is_fpga_configured(dev);
  int status;
  if (fpga_loaded < 0) {
    status = fpga_loaded;
    do {
      do {
      } while (0);
    } while (0);
  } else if (fpga_loaded) {
    status = change_setting(dev, 1);
  } else {
    status = change_setting(dev, 3);
  }
  if (status < 0) {
    do {
      do {
      } while (0);
    } while (0);
  }
  return status;
}


x86 assembly (clang, -O0):
<restore_post_flash_setting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <usb_is_fpga_configured@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    115c <restore_post_flash_setting+0x3c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    114d <restore_post_flash_setting+0x2d>
jmp    1152 <restore_post_flash_setting+0x32>
jmp    1157 <restore_post_flash_setting+0x37>
jmp    1192 <restore_post_flash_setting+0x72>
cmpl   $0x0,-0xc(%rbp)
je     117c <restore_post_flash_setting+0x5c>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1030 <change_setting@plt>
mov    %eax,-0x10(%rbp)
jmp    118d <restore_post_flash_setting+0x6d>
mov    -0x8(%rbp),%rdi
mov    $0x3,%esi
call   1030 <change_setting@plt>
mov    %eax,-0x10(%rbp)
jmp    1192 <restore_post_flash_setting+0x72>
cmpl   $0x0,-0x10(%rbp)
jge    11b5 <restore_post_flash_setting+0x95>
jmp    11a1 <restore_post_flash_setting+0x81>
jmp    11a6 <restore_post_flash_setting+0x86>
jmp    11ab <restore_post_flash_setting+0x8b>
jmp    11b0 <restore_post_flash_setting+0x90>
jmp    11b5 <restore_post_flash_setting+0x95>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<restore_post_flash_setting>:
push   %rbx
mov    %rdi,%rbx
call   1040 <usb_is_fpga_configured@plt>
test   %eax,%eax
js     1142 <restore_post_flash_setting+0x22>
sete   %al
movzbl %al,%eax
lea    (%rax,%rax,1),%esi
add    $0x1,%esi
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <change_setting@plt>
pop    %rbx
ret

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

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