#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;
};
typedef int int8_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int get_vtune(struct bladerf *, int, int, int *);
int write_vcocap(struct bladerf *, int, int, int);
int wait_for_vtune_value(struct bladerf *dev, uint8_t base,
                         uint8_t target_value, uint8_t *vcocap,
                         uint8_t vcocap_reg_state) {
  uint8_t vtune;
  unsigned int i;
  int status = 0;
  const unsigned int max_retries = 15;
  const uint8_t limit = (target_value == 0x02) ? 0 : 0x3f;
  int8_t inc = (target_value == 0x02) ? -1 : 1;
  assert(target_value == 0x02 || target_value == 0x01);
  for (i = 0; i < max_retries; i++) {
    status = get_vtune(dev, base, 0, &vtune);
    if (status != 0) {
      return status;
    }
    if (vtune == target_value) {
      do {
        do {
        } while (0);
      } while (0);
      return 0;
    } else {
      do {
        do {
        } while (0);
      } while (0);
      do {
        do {
        } while (0);
        do {
          do {
          } while (0);
        } while (0);
      } while (0);
    }
  }
  do {
    do {
    } while (0);
  } while (0);
  while (*vcocap != limit) {
    *vcocap += inc;
    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;
    } else if (vtune == target_value) {
      do {
        do {
        } while (0);
      } while (0);
      return 0;
    }
  }
  do {
    do {
    } while (0);
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<wait_for_vtune_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0xf,-0x34(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x3f,%eax
xor    %ecx,%ecx
cmp    $0x2,%edx
cmove  %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x1,%eax
mov    $0xffffffff,%ecx
cmp    $0x2,%edx
cmove  %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x1,%al
cmpl   $0x2,-0x18(%rbp)
mov    %al,-0x3d(%rbp)
je     119a <wait_for_vtune_value+0x6a>
cmpl   $0x1,-0x18(%rbp)
sete   %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0xf,-0x2c(%rbp)
jae    1262 <wait_for_vtune_value+0x132>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
lea    -0x28(%rbp),%rcx
call   1040 <get_vtune@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11e2 <wait_for_vtune_value+0xb2>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1340 <wait_for_vtune_value+0x210>
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    120e <wait_for_vtune_value+0xde>
jmp    11f3 <wait_for_vtune_value+0xc3>
jmp    11f8 <wait_for_vtune_value+0xc8>
jmp    11fd <wait_for_vtune_value+0xcd>
jmp    1202 <wait_for_vtune_value+0xd2>
movl   $0x0,-0x4(%rbp)
jmp    1340 <wait_for_vtune_value+0x210>
jmp    1213 <wait_for_vtune_value+0xe3>
jmp    1218 <wait_for_vtune_value+0xe8>
jmp    121d <wait_for_vtune_value+0xed>
jmp    1222 <wait_for_vtune_value+0xf2>
jmp    1227 <wait_for_vtune_value+0xf7>
jmp    122c <wait_for_vtune_value+0xfc>
jmp    1231 <wait_for_vtune_value+0x101>
jmp    1236 <wait_for_vtune_value+0x106>
jmp    123b <wait_for_vtune_value+0x10b>
jmp    1240 <wait_for_vtune_value+0x110>
jmp    1245 <wait_for_vtune_value+0x115>
jmp    124a <wait_for_vtune_value+0x11a>
jmp    124f <wait_for_vtune_value+0x11f>
jmp    1254 <wait_for_vtune_value+0x124>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ae <wait_for_vtune_value+0x7e>
jmp    1267 <wait_for_vtune_value+0x137>
jmp    126c <wait_for_vtune_value+0x13c>
jmp    1271 <wait_for_vtune_value+0x141>
jmp    1276 <wait_for_vtune_value+0x146>
jmp    127b <wait_for_vtune_value+0x14b>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x38(%rbp),%eax
je     1325 <wait_for_vtune_value+0x1f5>
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x24(%rbp),%ecx
call   1050 <write_vcocap@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     12c2 <wait_for_vtune_value+0x192>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1340 <wait_for_vtune_value+0x210>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x19,%edx
lea    -0x28(%rbp),%rcx
call   1040 <get_vtune@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     12ef <wait_for_vtune_value+0x1bf>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1340 <wait_for_vtune_value+0x210>
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    131b <wait_for_vtune_value+0x1eb>
jmp    1300 <wait_for_vtune_value+0x1d0>
jmp    1305 <wait_for_vtune_value+0x1d5>
jmp    130a <wait_for_vtune_value+0x1da>
jmp    130f <wait_for_vtune_value+0x1df>
movl   $0x0,-0x4(%rbp)
jmp    1340 <wait_for_vtune_value+0x210>
jmp    1320 <wait_for_vtune_value+0x1f0>
jmp    127b <wait_for_vtune_value+0x14b>
jmp    132a <wait_for_vtune_value+0x1fa>
jmp    132f <wait_for_vtune_value+0x1ff>
jmp    1334 <wait_for_vtune_value+0x204>
jmp    1339 <wait_for_vtune_value+0x209>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_vtune_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,0x4(%rsp)
mov    %rcx,0x10(%rsp)
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%rbp
xor    %eax,%eax
xor    %ecx,%ecx
cmp    $0x2,%edx
setne  %cl
mov    $0x3f,%edx
cmove  %eax,%edx
mov    %edx,0xc(%rsp)
lea    (%rcx,%rcx,1),%eax
add    $0xffffffff,%eax
mov    %eax,0x8(%rsp)
lea    -0x1(%r12),%eax
xor    %edi,%edi
cmp    $0x2,%eax
setb   %dil
call   1030 <assert@plt>
mov    $0xf,%r15d
mov    %rsp,%r14
nopl   (%rax)
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %edx,%edx
mov    %r14,%rcx
call   1040 <get_vtune@plt>
test   %eax,%eax
jne    1201 <wait_for_vtune_value+0xd1>
xor    %ebx,%ebx
cmp    %r12d,(%rsp)
je     1203 <wait_for_vtune_value+0xd3>
add    $0xffffffff,%r15d
jne    1190 <wait_for_vtune_value+0x60>
mov    0x4(%rsp),%r14d
mov    0x10(%rsp),%r15
nopl   0x0(%rax)
mov    (%r15),%edx
cmp    0xc(%rsp),%edx
je     1203 <wait_for_vtune_value+0xd3>
add    0x8(%rsp),%edx
mov    %edx,(%r15)
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r14d,%ecx
call   1050 <write_vcocap@plt>
test   %eax,%eax
jne    1201 <wait_for_vtune_value+0xd1>
mov    %rbp,%rdi
mov    %r13d,%esi
mov    $0x19,%edx
mov    %rsp,%rcx
call   1040 <get_vtune@plt>
test   %eax,%eax
jne    1201 <wait_for_vtune_value+0xd1>
cmp    %r12d,(%rsp)
jne    11c0 <wait_for_vtune_value+0x90>
jmp    1203 <wait_for_vtune_value+0xd3>
mov    %eax,%ebx
mov    %ebx,%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 @wait_for_vtune_value(%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
%15 = alloca i32
%16 = alloca i32
%17 = 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 0, i32* %14
store i32 15, i32* %15
%18 = load i32, i32* %9
%19 = icmp eq i32 %18, 2
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 0, i32 63
store i32 %21, i32* %16
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, 2
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 -1, i32 1
store i32 %25, i32* %17
%26 = load i32, i32* %9
%27 = icmp eq i32 %26, 2
br i1 %27, label %31, label %28
28: ; preds = %5
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, 1
br label %31
31: ; preds = %28, %5
%32 = phi i1 [ true, %5 ], [ %30, %28 ]
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
store i32 0, i32* %13
br label %35
35: ; preds = %69, %31
%36 = load i32, i32* %13
%37 = icmp ult i32 %36, 15
br i1 %37, label %38, label %72
38: ; preds = %35
%39 = load %struct.bladerf*, %struct.bladerf** %7
%40 = load i32, i32* %8
%41 = call i32 @get_vtune(%struct.bladerf* %39, i32 %40, i32 0, i32* %12)
store i32 %41, i32* %14
%42 = load i32, i32* %14
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = load i32, i32* %14
store i32 %45, i32* %6
br label %121
46: ; preds = %38
%47 = load i32, i32* %12
%48 = load i32, i32* %9
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %55
50: ; preds = %46
br label %51
51: ; preds = %50
br label %52
52: ; preds = %51
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
store i32 0, i32* %6
br label %121
55: ; preds = %46
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
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63
br label %65
65: ; preds = %64
br label %66
66: ; preds = %65
br label %67
67: ; preds = %66
br label %68
68: ; preds = %67
br label %69
69: ; preds = %68
%70 = load i32, i32* %13
%71 = add i32 %70, 1
store i32 %71, i32* %13
br label %35
72: ; preds = %35
br label %73
73: ; preds = %72
br label %74
74: ; preds = %73
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75
br label %77
77: ; preds = %115, %76
%78 = load i32*, i32** %10
%79 = load i32, i32* %78
%80 = load i32, i32* %16
%81 = icmp ne i32 %79, %80
br i1 %81, label %82, label %116
82: ; preds = %77
%83 = load i32, i32* %17
%84 = load i32*, i32** %10
%85 = load i32, i32* %84
%86 = add nsw i32 %85, %83
store i32 %86, i32* %84
%87 = load %struct.bladerf*, %struct.bladerf** %7
%88 = load i32, i32* %8
%89 = load i32*, i32** %10
%90 = load i32, i32* %89
%91 = load i32, i32* %11
%92 = call i32 @write_vcocap(%struct.bladerf* %87, i32 %88, i32 %90, i32 %91)
store i32 %92, i32* %14
%93 = load i32, i32* %14
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %82
%96 = load i32, i32* %14
store i32 %96, i32* %6
br label %121
97: ; preds = %82
%98 = load %struct.bladerf*, %struct.bladerf** %7
%99 = load i32, i32* %8
%100 = call i32 @get_vtune(%struct.bladerf* %98, i32 %99, i32 25, i32* %12)
store i32 %100, i32* %14
%101 = load i32, i32* %14
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %97
%104 = load i32, i32* %14
store i32 %104, i32* %6
br label %121
105: ; preds = %97
%106 = load i32, i32* %12
%107 = load i32, i32* %9
%108 = icmp eq i32 %106, %107
br i1 %108, label %109, label %114
109: ; preds = %105
br label %110
110: ; preds = %109
br label %111
111: ; preds = %110
br label %112
112: ; preds = %111
br label %113
113: ; preds = %112
store i32 0, i32* %6
br label %121
114: ; preds = %105
br label %115
115: ; preds = %114
br label %77
116: ; preds = %77
br label %117
117: ; preds = %116
br label %118
118: ; preds = %117
br label %119
119: ; preds = %118
br label %120
120: ; preds = %119
store i32 0, i32* %6
br label %121
121: ; preds = %120, %113, %103, %95, %54, %44
%122 = load i32, i32* %6
ret i32 %122
}

LLVM IR (-O2):
%struct.bladerf = type { i32 }
define i32 @wait_for_vtune_value(%struct.bladerf* %0, i32 %1, i32 %2, i32* nocapture %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = icmp eq i32 %2, 2
%9 = select i1 %8, i32 0, i32 63
%10 = select i1 %8, i32 -1, i32 1
%11 = add i32 %2, -1
%12 = icmp ult i32 %11, 2
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
br label %18
15: ; preds = %22
%16 = add nuw nsw i32 %19, 1
%17 = icmp eq i32 %16, 15
br i1 %17, label %25, label %18
18: ; preds = %5, %15
%19 = phi i32 [ 0, %5 ], [ %16, %15 ]
%20 = call i32 @get_vtune(%struct.bladerf* %0, i32 %1, i32 0, i32* %6)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, %2
br i1 %24, label %38, label %15
25: ; preds = %15, %35
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, %9
br i1 %27, label %38, label %28
28: ; preds = %25
%29 = add nsw i32 %26, %10
store i32 %29, i32* %3
%30 = call i32 @write_vcocap(%struct.bladerf* %0, i32 %1, i32 %29, i32 %4)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = call i32 @get_vtune(%struct.bladerf* %0, i32 %1, i32 25, i32* %6)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, %2
br i1 %37, label %38, label %25
38: ; preds = %22, %18, %25, %35, %32, %28
%39 = phi i32 [ 0, %25 ], [ 0, %35 ], [ %33, %32 ], [ %30, %28 ], [ 0, %22 ], [ %20, %18 ]
ret i32 %39
}