#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__ clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
scalar_t__ clock();
scalar_t__ programdunq();
signed wait4dun(void) {
  clock_t then;
  unsigned waitcount;
  then = (clock() + ((CLOCKS_PER_SEC / 10000) + 1));
  while (clock() < then) {
    ;
  }
  if (programdunq()) {
    for (waitcount = 100; waitcount != 0; --waitcount) {
      if (!programdunq()) {
        return -1;
      }
    }
    return 0;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<wait4dun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    0x2eae(%rip),%rax
mov    (%rax),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
cmp    -0x10(%rbp),%rax
jge    116d <wait4dun+0x4d>
jmp    1157 <wait4dun+0x37>
mov    $0x0,%al
call   1040 <programdunq@plt>
cmp    $0x0,%rax
je     11cb <wait4dun+0xab>
movl   $0x64,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11bf <wait4dun+0x9f>
mov    $0x0,%al
call   1040 <programdunq@plt>
cmp    $0x0,%rax
jne    11ac <wait4dun+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <wait4dun+0xb2>
jmp    11b1 <wait4dun+0x91>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <wait4dun+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <wait4dun+0xb2>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait4dun>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <clock@plt>
mov    0x2eb7(%rip),%rcx
movslq (%rcx),%rcx
imul   $0x68db8bad,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
lea    (%rcx,%rax,1),%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <clock@plt>
cmp    %rbx,%rax
jl     1160 <wait4dun+0x40>
xor    %eax,%eax
call   1040 <programdunq@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11a2 <wait4dun+0x82>
mov    $0xffffff9c,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <programdunq@plt>
test   %rax,%rax
je     11a2 <wait4dun+0x82>
inc    %ebp
jne    1190 <wait4dun+0x70>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global i32 0
define i32 @wait4dun() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = call i64 (...) @clock()
%5 = load i32, i32* @CLOCKS_PER_SEC
%6 = sdiv i32 %5, 10000
%7 = add nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = add nsw i64 %4, %8
store i64 %9, i64* %2
br label %10
10: ; preds = %14, %0
%11 = call i64 (...) @clock()
%12 = load i64, i64* %2
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
br label %10
15: ; preds = %10
%16 = call i64 (...) @programdunq()
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %15
store i32 100, i32* %3
br label %19
19: ; preds = %27, %18
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = call i64 (...) @programdunq()
%24 = icmp ne i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22
store i32 -1, i32* %1
br label %32
26: ; preds = %22
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add i32 %28, -1
store i32 %29, i32* %3
br label %19
30: ; preds = %19
store i32 0, i32* %1
br label %32
31: ; preds = %15
store i32 -1, i32* %1
br label %32
32: ; preds = %31, %30, %25
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
define i32 @wait4dun() {
%1 = tail call i64 (...) @clock()
%2 = load i32, i32* @CLOCKS_PER_SEC
%3 = sdiv i32 %2, 10000
%4 = add nsw i32 %3, 1
%5 = sext i32 %4 to i64
%6 = add nsw i64 %1, %5
br label %7
7: ; preds = %7, %0
%8 = tail call i64 (...) @clock()
%9 = icmp slt i64 %8, %6
br i1 %9, label %7, label %10
10: ; preds = %7
%11 = tail call i64 (...) @programdunq()
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %15
13: ; preds = %15
%14 = icmp eq i32 %19, 0
br i1 %14, label %20, label %15
15: ; preds = %10, %13
%16 = phi i32 [ %19, %13 ], [ 100, %10 ]
%17 = tail call i64 (...) @programdunq()
%18 = icmp eq i64 %17, 0
%19 = add nsw i32 %16, -1
br i1 %18, label %20, label %13
20: ; preds = %13, %15, %10
%21 = phi i32 [ -1, %10 ], [ 0, %13 ], [ -1, %15 ]
ret i32 %21
}