#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 */
struct timespec {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_PROCESS_CPUTIME_ID;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, unsigned long long);
int main() {
  unsigned long long iter = 0;
  struct timespec t;
  while (iter % 128 != 0 ||
         (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t), t.tv_sec) < 1) {
    iter++;
  }
  printf("%llu iterations\n", iter);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
and    $0x7f,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
jne    116a <main+0x4a>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmpl   $0x1,-0x18(%rbp)
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117a <main+0x5a>
jmp    118b <main+0x6b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1137 <main+0x17>
mov    -0x10(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
mov    0x2eb6(%rip),%r15
lea    0x8(%rsp),%r14
jmp    1144 <main+0x24>
nopl   0x0(%rax)
add    $0x1,%rbx
test   $0x7f,%bl
jne    1140 <main+0x20>
mov    (%r15),%edi
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
cmpl   $0x0,0x8(%rsp)
jle    1140 <main+0x20>
lea    0xe9e(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str = [17 x i8] c"%llu iterations\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.timespec
store i32 0, i32* %1
store i64 0, i64* %2
br label %4
4: ; preds = %16, %0
%5 = load i64, i64* %2
%6 = urem i64 %5, 128
%7 = icmp ne i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%10 = call i32 @clock_gettime(i32 %9, %struct.timespec* %3)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp slt i32 %12, 1
br label %14
14: ; preds = %8, %4
%15 = phi i1 [ true, %4 ], [ %13, %8 ]
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = load i64, i64* %2
%18 = add i64 %17, 1
store i64 %18, i64* %2
br label %4
19: ; preds = %14
%20 = load i64, i64* %2
%21 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %20)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_PROCESS_CPUTIME_ID = global i32 0
@.str = [17 x i8] c"%llu iterations\0A\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
br label %4
4: ; preds = %13, %0
%5 = phi i64 [ 0, %0 ], [ %14, %13 ]
%6 = and i64 %5, 127
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i32, i32* @CLOCK_PROCESS_CPUTIME_ID
%10 = call i32 @clock_gettime(i32 %9, %struct.timespec* %1)
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %4, %8
%14 = add i64 %5, 1
br label %4
15: ; preds = %8
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %5)
ret i32 0
}