#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
unsigned int atoi(char *);
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ is_expired(struct timespec *, struct timespec *, unsigned int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, size_t);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fputs("Argument missing.\n", stderr);
    return 2;
  }
  unsigned delta = atoi(argv[1]);
  struct timespec start, cur;
  int r = clock_gettime(CLOCK_MONOTONIC, &start);
  if (r == -1) {
    perror(0);
    return 1;
  }
  for (size_t i = 0;; ++i) {
    printf("%zu\n", i);
    if (i % 1000 == 0) {
      int r = clock_gettime(CLOCK_MONOTONIC, &cur);
      if (r == -1) {
        perror(0);
        return 1;
      }
      if (is_expired(&start, &cur, delta))
        break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11a1 <main+0x41>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x2,-0x4(%rbp)
jmp    1286 <main+0x126>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11e3 <main+0x83>
xor    %edi,%edi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1286 <main+0x126>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x0,%rdx
jne    1269 <main+0x109>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1245 <main+0xe5>
xor    %edi,%edi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1286 <main+0x126>
mov    -0x14(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <is_expired@plt>
cmp    $0x0,%rax
je     1264 <main+0x104>
jmp    127f <main+0x11f>
jmp    1269 <main+0x109>
jmp    126e <main+0x10e>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11eb <main+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     1192 <main+0x32>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x2,%eax
jmp    1249 <main+0xe9>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,0xc(%rsp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
je     123d <main+0xdd>
xor    %r13d,%r13d
movabs $0x20c49ba5e353f7cf,%r15
9b c4 20
lea    0xe44(%rip),%rbx
lea    0x10(%rsp),%r12
xor    %ebp,%ebp
jmp    11e8 <main+0x88>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
add    $0xffffffffffffffff,%r13
mov    %rbp,%rax
shr    $0x3,%rax
mul    %r15
shr    $0x4,%rdx
imul   $0x3e8,%rdx,%r14
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
add    %r13,%r14
jne    11e0 <main+0x80>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
je     123d <main+0xdd>
lea    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    0xc(%rsp),%edx
call   1080 <is_expired@plt>
test   %rax,%rax
je     11e0 <main+0x80>
xor    %eax,%eax
jmp    1249 <main+0xe9>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [19 x i8] c"Argument missing.\0A\00"
@stderr = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str.1 = [5 x i8] c"%zu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 2, i32* %3
br label %53
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* @CLOCK_MONOTONIC
%23 = call i32 @clock_gettime(i32 %22, %struct.timespec* %7)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %17
%27 = call i32 @perror(i32 0)
store i32 1, i32* %3
br label %53
28: ; preds = %17
store i64 0, i64* %10
br label %29
29: ; preds = %49, %28
%30 = load i64, i64* %10
%31 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %30)
%32 = load i64, i64* %10
%33 = urem i64 %32, 1000
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %29
%36 = load i32, i32* @CLOCK_MONOTONIC
%37 = call i32 @clock_gettime(i32 %36, %struct.timespec* %8)
store i32 %37, i32* %11
%38 = load i32, i32* %11
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @perror(i32 0)
store i32 1, i32* %3
br label %53
42: ; preds = %35
%43 = load i32, i32* %6
%44 = call i64 @is_expired(%struct.timespec* %7, %struct.timespec* %8, i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
br label %52
47: ; preds = %42
br label %48
48: ; preds = %47, %29
br label %49
49: ; preds = %48
%50 = load i64, i64* %10
%51 = add i64 %50, 1
store i64 %51, i64* %10
br label %29
52: ; preds = %46
store i32 0, i32* %3
br label %53
53: ; preds = %52, %40, %26, %14
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@.str = [19 x i8] c"Argument missing.\0A\00"
@stderr = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str.1 = [5 x i8] c"%zu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %36
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = bitcast %struct.timespec* %3 to i8*
%14 = bitcast %struct.timespec* %4 to i8*
%15 = load i32, i32* @CLOCK_MONOTONIC
%16 = call i32 @clock_gettime(i32 %15, %struct.timespec* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %32, label %18
18: ; preds = %9, %30
%19 = phi i64 [ %31, %30 ], [ 0, %9 ]
%20 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %19)
%21 = urem i64 %19, 1000
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i32, i32* @CLOCK_MONOTONIC
%25 = call i32 @clock_gettime(i32 %24, %struct.timespec* %4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = call i64 @is_expired(%struct.timespec* %3, %struct.timespec* %4, i32 %12)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %18, %27
%31 = add i64 %19, 1
br label %18
32: ; preds = %23, %9
%33 = call i32 @perror(i32 0)
br label %34
34: ; preds = %27, %32
%35 = phi i32 [ 1, %32 ], [ 0, %27 ]
br label %36
36: ; preds = %34, %6
%37 = phi i32 [ 2, %6 ], [ %35, %34 ]
ret i32 %37
}