#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 vendor_cmd_int_wvalue(struct bladerf *, int, int, int *);
int usb_set_firmware_loopback(struct bladerf *dev, bool enable) {
  int result;
  int status;
  status = vendor_cmd_int_wvalue(dev, 113, enable, &result);
  if (status != 0) {
    return status;
  }
  status = change_setting(dev, 0);
  if (status == 0) {
    status = change_setting(dev, 1);
  }
  return status;
}


x86 assembly (clang, -O0):
<usb_set_firmware_loopback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x71,%esi
lea    -0x18(%rbp),%rcx
call   1040 <vendor_cmd_int_wvalue@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     115c <usb_set_firmware_loopback+0x3c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118b <usb_set_firmware_loopback+0x6b>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <change_setting@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1185 <usb_set_firmware_loopback+0x65>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <change_setting@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usb_set_firmware_loopback>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%edx
mov    %rdi,%rbx
lea    0xc(%rsp),%rcx
mov    $0x71,%esi
call   1040 <vendor_cmd_int_wvalue@plt>
test   %eax,%eax
jne    1158 <usb_set_firmware_loopback+0x38>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <change_setting@plt>
test   %eax,%eax
jne    1158 <usb_set_firmware_loopback+0x38>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <change_setting@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

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