#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 {
  long tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  struct timespec tim;
  tim.tv_sec = 0;
  tim.tv_nsec = 500000000L;
  int i = 0;
  while (i < 20) {
    printf("%d\n", i);
    i++;
    nanosleep(&tim, NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x1dcd6500,-0x18(%rbp)
1d
movl   $0x0,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jge    117a <main+0x5a>
mov    -0x1c(%rbp),%esi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
jmp    1146 <main+0x26>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movaps 0xed2(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed7(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x8,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x9,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0xb,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0xc,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0xd,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0xe,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0xf,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x10,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x11,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x12,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %r14,%rdi
mov    $0x13,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i64 500000000, i64* %5
store i32 0, i32* %3
br label %6
6: ; preds = %9, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 20
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
%14 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
br label %6
15: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca <2 x i64>
%2 = bitcast <2 x i64>* %1 to %struct.timespec*
%3 = bitcast <2 x i64>* %1 to i8*
store <2 x i64> <i64 500000000, i64 0>, <2 x i64>* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 1)
%7 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 2)
%9 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%11 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4)
%13 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 5)
%15 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%16 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 6)
%17 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 7)
%19 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 8)
%21 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 9)
%23 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 10)
%25 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 11)
%27 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 12)
%29 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 13)
%31 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 14)
%33 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 15)
%35 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 16)
%37 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 17)
%39 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 18)
%41 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 19)
%43 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
ret i32 0
}