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

/* Variables and functions */
int get_vtune(struct bladerf *, scalar_t__, int, scalar_t__ *);
int write_vcocap(struct bladerf *, scalar_t__, scalar_t__, scalar_t__);
int vtune_norm_to_high(struct bladerf *dev, uint8_t base, uint8_t vcocap,
                       uint8_t vcocap_reg_state, uint8_t *vtune_high_limit) {
  int status;
  unsigned int i;
  uint8_t vtune = 0xff;
  for (i = 0; i < 20; i++) {
    if (vcocap == 0) {
      *vtune_high_limit = 0;
      do {
        do {
        } while (0);
      } while (0);
      return 0;
    }
    vcocap--;
    status = write_vcocap(dev, base, vcocap, vcocap_reg_state);
    if (status != 0) {
      return status;
    }
    status = get_vtune(dev, base, 25, &vtune);
    if (status != 0) {
      return status;
    }
    if (vtune == 0x02) {
      *vtune_high_limit = vcocap;
      do {
        do {
        } while (0);
      } while (0);
      return 0;
    }
  }
  do {
    do {
    } while (0);
  } while (0);
  return (-1);
}


x86 assembly (clang, -O0):
<vtune_norm_to_high>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0xff,-0x40(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x14,-0x38(%rbp)
jae    1231 <vtune_norm_to_high+0x111>
cmpq   $0x0,-0x20(%rbp)
jne    1186 <vtune_norm_to_high+0x66>
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
jmp    1170 <vtune_norm_to_high+0x50>
jmp    1175 <vtune_norm_to_high+0x55>
jmp    117a <vtune_norm_to_high+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    124c <vtune_norm_to_high+0x12c>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <write_vcocap@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11bf <vtune_norm_to_high+0x9f>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <vtune_norm_to_high+0x12c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x19,%edx
lea    -0x40(%rbp),%rcx
call   1030 <get_vtune@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11ed <vtune_norm_to_high+0xcd>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <vtune_norm_to_high+0x12c>
cmpq   $0x2,-0x40(%rbp)
jne    121e <vtune_norm_to_high+0xfe>
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
jmp    1208 <vtune_norm_to_high+0xe8>
jmp    120d <vtune_norm_to_high+0xed>
jmp    1212 <vtune_norm_to_high+0xf2>
movl   $0x0,-0x4(%rbp)
jmp    124c <vtune_norm_to_high+0x12c>
jmp    1223 <vtune_norm_to_high+0x103>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    114b <vtune_norm_to_high+0x2b>
jmp    1236 <vtune_norm_to_high+0x116>
jmp    123b <vtune_norm_to_high+0x11b>
jmp    1240 <vtune_norm_to_high+0x120>
jmp    1245 <vtune_norm_to_high+0x125>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vtune_norm_to_high>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
movq   $0xff,0x8(%rsp)
add    $0xffffffffffffffff,%rbx
mov    $0x14,%r14d
lea    0x8(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffffffffffff,%rbx
je     11ab <vtune_norm_to_high+0x8b>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1040 <write_vcocap@plt>
test   %eax,%eax
jne    11b7 <vtune_norm_to_high+0x97>
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x19,%edx
mov    %rbp,%rcx
call   1030 <get_vtune@plt>
test   %eax,%eax
jne    11b7 <vtune_norm_to_high+0x97>
cmpq   $0x2,0x8(%rsp)
je     11ad <vtune_norm_to_high+0x8d>
add    $0xffffffffffffffff,%rbx
add    $0xffffffff,%r14d
jne    1160 <vtune_norm_to_high+0x40>
mov    $0xffffffff,%eax
jmp    11b7 <vtune_norm_to_high+0x97>
xor    %ebx,%ebx
mov    0x10(%rsp),%rax
mov    %rbx,(%rax)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bladerf = type { i32 }
define i32 @vtune_norm_to_high(%struct.bladerf* %0, i64 %1, i64 %2, i64 %3, i64* %4) {
%6 = alloca i32
%7 = alloca %struct.bladerf*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
store %struct.bladerf* %0, %struct.bladerf** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store i64* %4, i64** %11
store i64 255, i64* %14
store i32 0, i32* %13
br label %15
15: ; preds = %58, %5
%16 = load i32, i32* %13
%17 = icmp ult i32 %16, 20
br i1 %17, label %18, label %61
18: ; preds = %15
%19 = load i64, i64* %9
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i64*, i64** %11
store i64 0, i64* %22
br label %23
23: ; preds = %21
br label %24
24: ; preds = %23
br label %25
25: ; preds = %24
br label %26
26: ; preds = %25
store i32 0, i32* %6
br label %66
27: ; preds = %18
%28 = load i64, i64* %9
%29 = add nsw i64 %28, -1
store i64 %29, i64* %9
%30 = load %struct.bladerf*, %struct.bladerf** %7
%31 = load i64, i64* %8
%32 = load i64, i64* %9
%33 = load i64, i64* %10
%34 = call i32 @write_vcocap(%struct.bladerf* %30, i64 %31, i64 %32, i64 %33)
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = load i32, i32* %12
store i32 %38, i32* %6
br label %66
39: ; preds = %27
%40 = load %struct.bladerf*, %struct.bladerf** %7
%41 = load i64, i64* %8
%42 = call i32 @get_vtune(%struct.bladerf* %40, i64 %41, i32 25, i64* %14)
store i32 %42, i32* %12
%43 = load i32, i32* %12
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = load i32, i32* %12
store i32 %46, i32* %6
br label %66
47: ; preds = %39
%48 = load i64, i64* %14
%49 = icmp eq i64 %48, 2
br i1 %49, label %50, label %57
50: ; preds = %47
%51 = load i64, i64* %9
%52 = load i64*, i64** %11
store i64 %51, i64* %52
br label %53
53: ; preds = %50
br label %54
54: ; preds = %53
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
store i32 0, i32* %6
br label %66
57: ; preds = %47
br label %58
58: ; preds = %57
%59 = load i32, i32* %13
%60 = add i32 %59, 1
store i32 %60, i32* %13
br label %15
61: ; preds = %15
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63
br label %65
65: ; preds = %64
store i32 -1, i32* %6
br label %66
66: ; preds = %65, %56, %45, %37, %26
%67 = load i32, i32* %6
ret i32 %67
}

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @vtune_norm_to_high(%struct.bladerf* %0, i64 %1, i64 %2, i64 %3, i64* nocapture writeonly %4) {
%6 = alloca i64
%7 = bitcast i64* %6 to i8*
store i64 255, i64* %6
br label %11
8: ; preds = %22
%9 = add nuw nsw i32 %12, 1
%10 = icmp eq i32 %9, 20
br i1 %10, label %27, label %11
11: ; preds = %5, %8
%12 = phi i32 [ 0, %5 ], [ %9, %8 ]
%13 = phi i64 [ %2, %5 ], [ %16, %8 ]
%14 = icmp eq i64 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %11
%16 = add nsw i64 %13, -1
%17 = call i32 @write_vcocap(%struct.bladerf* %0, i64 %1, i64 %16, i64 %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = call i32 @get_vtune(%struct.bladerf* %0, i64 %1, i32 25, i64* %6)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i64, i64* %6
%24 = icmp eq i64 %23, 2
br i1 %24, label %25, label %8
25: ; preds = %22, %11
%26 = phi i64 [ 0, %11 ], [ %16, %22 ]
store i64 %26, i64* %4
br label %27
27: ; preds = %8, %19, %15, %25
%28 = phi i32 [ 0, %25 ], [ -1, %8 ], [ %20, %19 ], [ %17, %15 ]
ret i32 %28
}