#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 */

/* Variables and functions */
int /*<<< orphan*/ clear_pin(int);
int /*<<< orphan*/ clock();
int pin_is_set(int);
int /*<<< orphan*/ set_pin(int);
int acquire() {
  int sample, i, total, iterations, wait;
  iterations = 200;
  total = 0;
  while (iterations--) {
    clear_pin((1 << 1));
    wait = 250;
    while (wait--)
      ;
    clock();
    sample = 0;
    for (i = 0; i < 8; i++) {
      clock();
      wait = 2500;
      while (wait--)
        ;
      sample <<= 1;
      sample |= (pin_is_set((1 << 14)) == (1 << 14));
    }
    set_pin((1 << 1));
    total += sample;
    wait = 7000;
    while (wait--)
      ;
  }
  return total / 200;
}


x86 assembly (clang, -O0):
<acquire>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xc8,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
je     1246 <acquire+0x106>
mov    $0x2,%edi
call   1060 <clear_pin@plt>
movl   $0xfa,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1194 <acquire+0x54>
jmp    117b <acquire+0x3b>
mov    $0x0,%al
call   1040 <clock@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    120e <acquire+0xce>
mov    $0x0,%al
call   1040 <clock@plt>
movl   $0x9c4,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11da <acquire+0x9a>
jmp    11c1 <acquire+0x81>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
cmp    $0x4000,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a9 <acquire+0x69>
mov    $0x2,%edi
call   1030 <set_pin@plt>
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x1b58,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1241 <acquire+0x101>
jmp    1228 <acquire+0xe8>
jmp    1156 <acquire+0x16>
mov    -0xc(%rbp),%eax
mov    $0xc8,%ecx
cltd
idiv   %ecx
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acquire>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffff38,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edi
call   1060 <clear_pin@plt>
xor    %eax,%eax
call   1040 <clock@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
xor    %ebx,%ebx
cmp    $0x4000,%eax
sete   %bl
xor    %eax,%eax
call   1040 <clock@plt>
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
xor    %ecx,%ecx
cmp    $0x4000,%eax
sete   %cl
lea    (%rcx,%rbx,2),%ebx
xor    %eax,%eax
call   1040 <clock@plt>
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
xor    %ebp,%ebp
cmp    $0x4000,%eax
sete   %bpl
xor    %eax,%eax
call   1040 <clock@plt>
add    %ebp,%ebp
lea    0x0(%rbp,%rbx,4),%ebx
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
xor    %ebp,%ebp
cmp    $0x4000,%eax
sete   %bpl
or     %ebx,%ebp
xor    %eax,%eax
call   1040 <clock@plt>
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
xor    %ebx,%ebx
cmp    $0x4000,%eax
sete   %bl
xor    %eax,%eax
call   1040 <clock@plt>
add    %ebx,%ebx
lea    (%rbx,%rbp,4),%ebp
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
xor    %r12d,%r12d
cmp    $0x4000,%eax
sete   %r12b
or     %ebp,%r12d
xor    %eax,%eax
call   1040 <clock@plt>
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
xor    %ebp,%ebp
cmp    $0x4000,%eax
sete   %bpl
xor    %eax,%eax
call   1040 <clock@plt>
mov    $0x4000,%edi
call   1050 <pin_is_set@plt>
xor    %ebx,%ebx
cmp    $0x4000,%eax
sete   %bl
mov    $0x2,%edi
call   1030 <set_pin@plt>
add    %ebp,%ebp
lea    0x0(%rbp,%r12,4),%eax
or     %ebx,%eax
add    %eax,%r15d
inc    %r14d
jne    1160 <acquire+0x20>
movslq %r15d,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @acquire() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 200, i32* %4
store i32 0, i32* %3
br label %6
6: ; preds = %50, %0
%7 = load i32, i32* %4
%8 = add nsw i32 %7, -1
store i32 %8, i32* %4
%9 = icmp ne i32 %7, 0
br i1 %9, label %10, label %51
10: ; preds = %6
%11 = call i32 @clear_pin(i32 2)
store i32 250, i32* %5
br label %12
12: ; preds = %16, %10
%13 = load i32, i32* %5
%14 = add nsw i32 %13, -1
store i32 %14, i32* %5
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %17
16: ; preds = %12
br label %12
17: ; preds = %12
%18 = call i32 (...) @clock()
store i32 0, i32* %1
store i32 0, i32* %2
br label %19
19: ; preds = %37, %17
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 8
br i1 %21, label %22, label %40
22: ; preds = %19
%23 = call i32 (...) @clock()
store i32 2500, i32* %5
br label %24
24: ; preds = %28, %22
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
%27 = icmp ne i32 %25, 0
br i1 %27, label %28, label %29
28: ; preds = %24
br label %24
29: ; preds = %24
%30 = load i32, i32* %1
%31 = shl i32 %30, 1
store i32 %31, i32* %1
%32 = call i32 @pin_is_set(i32 16384)
%33 = icmp eq i32 %32, 16384
%34 = zext i1 %33 to i32
%35 = load i32, i32* %1
%36 = or i32 %35, %34
store i32 %36, i32* %1
br label %37
37: ; preds = %29
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %19
40: ; preds = %19
%41 = call i32 @set_pin(i32 2)
%42 = load i32, i32* %1
%43 = load i32, i32* %3
%44 = add nsw i32 %43, %42
store i32 %44, i32* %3
store i32 7000, i32* %5
br label %45
45: ; preds = %49, %40
%46 = load i32, i32* %5
%47 = add nsw i32 %46, -1
store i32 %47, i32* %5
%48 = icmp ne i32 %46, 0
br i1 %48, label %49, label %50
49: ; preds = %45
br label %45
50: ; preds = %45
br label %6
51: ; preds = %6
%52 = load i32, i32* %3
%53 = sdiv i32 %52, 200
ret i32 %53
}

LLVM IR (-O2):
define i32 @acquire() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 199, %0 ], [ %50, %1 ]
%3 = phi i32 [ 0, %0 ], [ %49, %1 ]
%4 = tail call i32 @clear_pin(i32 2)
%5 = tail call i32 (...) @clock()
%6 = tail call i32 (...) @clock()
%7 = tail call i32 @pin_is_set(i32 16384)
%8 = icmp eq i32 %7, 16384
%9 = tail call i32 (...) @clock()
%10 = select i1 %8, i32 2, i32 0
%11 = tail call i32 @pin_is_set(i32 16384)
%12 = icmp eq i32 %11, 16384
%13 = zext i1 %12 to i32
%14 = or i32 %10, %13
%15 = tail call i32 (...) @clock()
%16 = tail call i32 @pin_is_set(i32 16384)
%17 = icmp eq i32 %16, 16384
%18 = tail call i32 (...) @clock()
%19 = shl nuw nsw i32 %14, 2
%20 = select i1 %17, i32 2, i32 0
%21 = or i32 %19, %20
%22 = tail call i32 @pin_is_set(i32 16384)
%23 = icmp eq i32 %22, 16384
%24 = zext i1 %23 to i32
%25 = or i32 %21, %24
%26 = tail call i32 (...) @clock()
%27 = tail call i32 @pin_is_set(i32 16384)
%28 = icmp eq i32 %27, 16384
%29 = tail call i32 (...) @clock()
%30 = shl nuw nsw i32 %25, 2
%31 = select i1 %28, i32 2, i32 0
%32 = or i32 %30, %31
%33 = tail call i32 @pin_is_set(i32 16384)
%34 = icmp eq i32 %33, 16384
%35 = zext i1 %34 to i32
%36 = or i32 %32, %35
%37 = tail call i32 (...) @clock()
%38 = tail call i32 @pin_is_set(i32 16384)
%39 = icmp eq i32 %38, 16384
%40 = tail call i32 (...) @clock()
%41 = tail call i32 @pin_is_set(i32 16384)
%42 = icmp eq i32 %41, 16384
%43 = zext i1 %42 to i32
%44 = tail call i32 @set_pin(i32 2)
%45 = shl i32 %36, 2
%46 = select i1 %39, i32 2, i32 0
%47 = or i32 %45, %46
%48 = or i32 %47, %43
%49 = add nsw i32 %48, %3
%50 = add nsw i32 %2, -1
%51 = icmp eq i32 %2, 0
br i1 %51, label %52, label %1
52: ; preds = %1
%53 = sdiv i32 %49, 200
ret i32 %53
}