#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 /*<<< orphan*/ time_t;

/* Variables and functions */
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void delay(int nDelaySeconds) {
  time_t tStart, tNow;
  double fdElapsedSeconds;
  time(&tStart);
  do {
    time(&tNow);
    fdElapsedSeconds = difftime(tNow, tStart);
    printf("elapsed secs = %.f", fdElapsedSeconds);
  } while (fdElapsedSeconds < nDelaySeconds);
}


x86 assembly (clang, -O0):
<delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <time@plt>
lea    -0xc(%rbp),%rdi
call   1050 <time@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <difftime@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x4(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1144 <delay+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delay>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x4(%rsp),%rdi
call   1050 <time@plt>
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rsp,%r14
lea    0xea9(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <time@plt>
mov    (%rsp),%edi
mov    0x4(%rsp),%esi
call   1040 <difftime@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
ucomisd 0x10(%rsp),%xmm0
ja     1160 <delay+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"elapsed secs = %.f\00"
define void @delay(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %2
%6 = call i32 @time(i32* %3)
br label %7
7: ; preds = %14, %1
%8 = call i32 @time(i32* %4)
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = call double @difftime(i32 %9, i32 %10)
store double %11, double* %5
%12 = load double, double* %5
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), double %12)
br label %14
14: ; preds = %7
%15 = load double, double* %5
%16 = load i32, i32* %2
%17 = sitofp i32 %16 to double
%18 = fcmp olt double %15, %17
br i1 %18, label %7, label %19
19: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"elapsed secs = %.f\00"
define void @delay(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @time(i32* %2)
%7 = sitofp i32 %0 to double
br label %8
8: ; preds = %8, %1
%9 = call i32 @time(i32* %3)
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = call double @difftime(i32 %10, i32 %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), double %12)
%14 = fcmp olt double %12, %7
br i1 %14, label %8, label %15
15: ; preds = %8
ret void
}