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

/* Variables and functions */
int get_vtune(struct bladerf *, int, int, int *);
int write_vcocap(struct bladerf *, int, int, int);
int vtune_high_to_norm(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 >= 0x3f) {
      *vtune_high_limit = 0x3f;
      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 == 0x00) {
      *vtune_high_limit = vcocap - 1;
      do {
        do {
        } while (0);
      } while (0);
      do {
        do {
        } while (0);
      } while (0);
      return 0;
    }
  }
  do {
    do {
    } while (0);
  } while (0);
  return (-1);
}


x86 assembly (clang, -O0):
<vtune_high_to_norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0xff,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x14,-0x30(%rbp)
jae    1238 <vtune_high_to_norm+0x118>
cmpl   $0x3f,-0x18(%rbp)
jl     1180 <vtune_high_to_norm+0x60>
mov    -0x28(%rbp),%rax
movl   $0x3f,(%rax)
jmp    116a <vtune_high_to_norm+0x4a>
jmp    116f <vtune_high_to_norm+0x4f>
jmp    1174 <vtune_high_to_norm+0x54>
movl   $0x0,-0x4(%rbp)
jmp    1253 <vtune_high_to_norm+0x133>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <write_vcocap@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11b3 <vtune_high_to_norm+0x93>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <vtune_high_to_norm+0x133>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x19,%edx
lea    -0x34(%rbp),%rcx
call   1030 <get_vtune@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11e0 <vtune_high_to_norm+0xc0>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <vtune_high_to_norm+0x133>
cmpl   $0x0,-0x34(%rbp)
jne    1225 <vtune_high_to_norm+0x105>
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    11fb <vtune_high_to_norm+0xdb>
jmp    1200 <vtune_high_to_norm+0xe0>
jmp    1205 <vtune_high_to_norm+0xe5>
jmp    120a <vtune_high_to_norm+0xea>
jmp    120f <vtune_high_to_norm+0xef>
jmp    1214 <vtune_high_to_norm+0xf4>
jmp    1219 <vtune_high_to_norm+0xf9>
movl   $0x0,-0x4(%rbp)
jmp    1253 <vtune_high_to_norm+0x133>
jmp    122a <vtune_high_to_norm+0x10a>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1147 <vtune_high_to_norm+0x27>
jmp    123d <vtune_high_to_norm+0x11d>
jmp    1242 <vtune_high_to_norm+0x122>
jmp    1247 <vtune_high_to_norm+0x127>
jmp    124c <vtune_high_to_norm+0x12c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vtune_high_to_norm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %ecx,0xc(%rsp)
mov    %edx,%ebx
mov    %esi,%r12d
mov    %rdi,%rbp
movl   $0xff,0x8(%rsp)
cmp    $0x40,%edx
mov    $0x3f,%r13d
cmovge %edx,%r13d
mov    $0x14,%r15d
nopw   0x0(%rax,%rax,1)
cmp    %ebx,%r13d
je     11af <vtune_high_to_norm+0x8f>
lea    0x1(%rbx),%r14d
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
mov    0xc(%rsp),%ecx
call   1040 <write_vcocap@plt>
test   %eax,%eax
jne    11bd <vtune_high_to_norm+0x9d>
mov    %rbp,%rdi
mov    %r12d,%esi
mov    $0x19,%edx
lea    0x8(%rsp),%rcx
call   1030 <get_vtune@plt>
test   %eax,%eax
jne    11bd <vtune_high_to_norm+0x9d>
cmpl   $0x0,0x8(%rsp)
je     11b4 <vtune_high_to_norm+0x94>
mov    %r14d,%ebx
add    $0xffffffff,%r15d
jne    1160 <vtune_high_to_norm+0x40>
mov    $0xffffffff,%eax
jmp    11bd <vtune_high_to_norm+0x9d>
mov    $0x3f,%ebx
mov    0x10(%rsp),%rax
mov    %ebx,(%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_high_to_norm(%struct.bladerf* %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca %struct.bladerf*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store %struct.bladerf* %0, %struct.bladerf** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32* %4, i32** %11
store i32 255, i32* %14
store i32 0, i32* %13
br label %15
15: ; preds = %63, %5
%16 = load i32, i32* %13
%17 = icmp ult i32 %16, 20
br i1 %17, label %18, label %66
18: ; preds = %15
%19 = load i32, i32* %9
%20 = icmp sge i32 %19, 63
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32*, i32** %11
store i32 63, i32* %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 %71
27: ; preds = %18
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
%30 = load %struct.bladerf*, %struct.bladerf** %7
%31 = load i32, i32* %8
%32 = load i32, i32* %9
%33 = load i32, i32* %10
%34 = call i32 @write_vcocap(%struct.bladerf* %30, i32 %31, i32 %32, i32 %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 %71
39: ; preds = %27
%40 = load %struct.bladerf*, %struct.bladerf** %7
%41 = load i32, i32* %8
%42 = call i32 @get_vtune(%struct.bladerf* %40, i32 %41, i32 25, i32* %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 %71
47: ; preds = %39
%48 = load i32, i32* %14
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %62
50: ; preds = %47
%51 = load i32, i32* %9
%52 = sub nsw i32 %51, 1
%53 = load i32*, i32** %11
store i32 %52, i32* %53
br label %54
54: ; preds = %50
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
br label %57
57: ; preds = %56
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59
br label %61
61: ; preds = %60
store i32 0, i32* %6
br label %71
62: ; preds = %47
br label %63
63: ; preds = %62
%64 = load i32, i32* %13
%65 = add i32 %64, 1
store i32 %65, i32* %13
br label %15
66: ; preds = %15
br label %67
67: ; preds = %66
br label %68
68: ; preds = %67
br label %69
69: ; preds = %68
br label %70
70: ; preds = %69
store i32 -1, i32* %6
br label %71
71: ; preds = %70, %61, %45, %37, %26
%72 = load i32, i32* %6
ret i32 %72
}

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