#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 set_tx_gain_combo(struct bladerf *, int, int);
int set_tx_gain(struct bladerf *dev, int gain) {
  int status;
  const int max_gain = ((-4) - (-35)) + 25;
  if (gain < 0) {
    gain = 0;
  }
  if (gain <= 25) {
    status = set_tx_gain_combo(dev, (-35), gain);
  } else if (gain <= max_gain) {
    status = set_tx_gain_combo(dev, (-35) + gain - 25, 25);
  } else {
    status = set_tx_gain_combo(dev, (-4), 25);
  }
  return status;
}


x86 assembly (clang, -O0):
<set_tx_gain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x38,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1137 <set_tx_gain+0x27>
movl   $0x0,-0xc(%rbp)
cmpl   $0x19,-0xc(%rbp)
jg     115a <set_tx_gain+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0xffffffdd,%esi
call   1030 <set_tx_gain_combo@plt>
mov    %eax,-0x10(%rbp)
jmp    11a1 <set_tx_gain+0x91>
cmpl   $0x38,-0xc(%rbp)
jg     1186 <set_tx_gain+0x76>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0xffffffdd,%esi
sub    $0x19,%esi
mov    $0x19,%edx
call   1030 <set_tx_gain_combo@plt>
mov    %eax,-0x10(%rbp)
jmp    119c <set_tx_gain+0x8c>
mov    -0x8(%rbp),%rdi
mov    $0xfffffffc,%esi
mov    $0x19,%edx
call   1030 <set_tx_gain_combo@plt>
mov    %eax,-0x10(%rbp)
jmp    11a1 <set_tx_gain+0x91>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_tx_gain>:
xor    %edx,%edx
test   %esi,%esi
cmovns %esi,%edx
cmp    $0x19,%edx
ja     1126 <set_tx_gain+0x16>
mov    $0xffffffdd,%esi
jmp    1030 <set_tx_gain_combo@plt>
cmp    $0x38,%edx
ja     113a <set_tx_gain+0x2a>
add    $0xffffffc4,%edx
mov    %edx,%esi
mov    $0x19,%edx
jmp    1030 <set_tx_gain_combo@plt>
mov    $0xfffffffc,%esi
mov    $0x19,%edx
jmp    1030 <set_tx_gain_combo@plt>

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

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @set_tx_gain(%struct.bladerf* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
%4 = select i1 %3, i32 %1, i32 0
%5 = icmp ult i32 %4, 26
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @set_tx_gain_combo(%struct.bladerf* %0, i32 -35, i32 %4)
br label %15
8: ; preds = %2
%9 = icmp ult i32 %4, 57
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = add nuw nsw i32 %4, -60
%12 = tail call i32 @set_tx_gain_combo(%struct.bladerf* %0, i32 %11, i32 25)
br label %15
13: ; preds = %8
%14 = tail call i32 @set_tx_gain_combo(%struct.bladerf* %0, i32 -4, i32 25)
br label %15
15: ; preds = %10, %13, %6
%16 = phi i32 [ %7, %6 ], [ %12, %10 ], [ %14, %13 ]
ret i32 %16
}