#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 tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
int main(void) {
  struct timespec reqtime;
  printf("A line first...\n");
  putchar('\n');
  putchar('\n');
  for (int i = 0; i < 5; i++) {
    reqtime.tv_sec = 0;
    reqtime.tv_nsec = 1E9 * 0.001;
    printf("1 ms: ");
    nanosleep(&reqtime, NULL);
    printf("done\n");
  }
  putchar('\n');
  for (int i = 0; i < 5; i++) {
    reqtime.tv_sec = 0;
    reqtime.tv_nsec = 1E9 * 0.1;
    printf("100 ms: ");
    nanosleep(&reqtime, NULL);
    printf("done\n");
  }
  putchar('\n');
  reqtime.tv_sec = 1;
  reqtime.tv_nsec = 1E9 * 0.5;
  printf("1.5 s: ");
  nanosleep(&reqtime, NULL);
  printf("done\n");
  reqtime.tv_sec = 0;
  reqtime.tv_nsec = 1E9 * 0.005;
  printf("1.5 s (probably more because of printing). "
         "This line should wrap appropriately: ");
  for (int i = 0; i < 300; i++) {
    nanosleep(&reqtime, NULL);
    putchar('x');
    fflush(stdout);
  }
  putchar('\n');
  reqtime.tv_sec = 5;
  reqtime.tv_nsec = 1E9 * 0.555;
  printf("5.555 s: ");
  nanosleep(&reqtime, NULL);
  printf("done");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    11c1 <main+0x81>
movl   $0x0,-0x10(%rbp)
movl   $0xf4240,-0xc(%rbp)
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <nanosleep@plt>
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <main+0x36>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    121d <main+0xdd>
movl   $0x0,-0x10(%rbp)
movl   $0x5f5e100,-0xc(%rbp)
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <nanosleep@plt>
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11d2 <main+0x92>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x1,-0x10(%rbp)
movl   $0x1dcd6500,-0xc(%rbp)
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <nanosleep@plt>
lea    0xdc3(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x4c4b40,-0xc(%rbp)
lea    0xdc0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x12c,-0x1c(%rbp)
jge    12bb <main+0x17b>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <nanosleep@plt>
mov    $0x78,%edi
call   1030 <putchar@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    127b <main+0x13b>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x5,-0x10(%rbp)
movl   $0x2114a0c0,-0xc(%rbp)
lea    0xda6(%rip),%rdi
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <nanosleep@plt>
lea    0xd97(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf11(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movabs $0xf424000000000,%r12
mov    %r12,(%rsp)
lea    0xe70(%rip),%r15
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %rsp,%r13
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
lea    0xed7(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,(%rsp)
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,(%rsp)
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,(%rsp)
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,(%rsp)
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movabs $0x5f5e10000000000,%r12
e1 f5 05
mov    %r12,(%rsp)
lea    0xdbc(%rip),%r15
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,(%rsp)
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,(%rsp)
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,(%rsp)
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r12,(%rsp)
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movabs $0x1dcd650000000001,%rax
65 cd 1d
mov    %rax,(%rsp)
lea    0xd14(%rip),%rdi
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
movabs $0x4c4b4000000000,%rax
mov    %rax,(%rsp)
lea    0xcf0(%rip),%rdi
call   1050 <printf@plt>
mov    $0x12c,%ebp
mov    0x2ca7(%rip),%rbx
nopl   0x0(%rax)
mov    %r13,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
mov    $0x78,%edi
call   1030 <putchar@plt>
mov    (%rbx),%edi
call   1070 <fflush@plt>
add    $0xffffffff,%ebp
jne    1340 <main+0x1f0>
mov    $0xa,%edi
call   1030 <putchar@plt>
movabs $0x2114a0c000000005,%rax
a0 14 21
mov    %rax,(%rsp)
lea    0xcea(%rip),%rdi
call   1050 <printf@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <nanosleep@plt>
lea    0xcee(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [17 x i8] c"A line first...\0A\00"
@.str.1 = [7 x i8] c"1 ms: \00"
@.str.2 = [6 x i8] c"done\0A\00"
@.str.3 = [9 x i8] c"100 ms: \00"
@.str.4 = [8 x i8] c"1.5 s: \00"
@.str.5 = [81 x i8] c"1.5 s (probably more because of printing). This line should wrap appropriately: \00"
@stdout = global i32 0
@.str.6 = [10 x i8] c"5.555 s: \00"
@.str.7 = [5 x i8] c"done\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @putchar(i8 signext 10)
%8 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %3
br label %9
9: ; preds = %18, %0
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 5
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 0, i32* %13
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 1000000, i32* %14
%15 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%17 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %12
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %9
21: ; preds = %9
%22 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %4
br label %23
23: ; preds = %32, %21
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 5
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 0, i32* %27
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 100000000, i32* %28
%29 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%31 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %26
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %23
35: ; preds = %23
%36 = call i32 @putchar(i8 signext 10)
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 1, i32* %37
%38 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 500000000, i32* %38
%39 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%41 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%42 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 0, i32* %42
%43 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 5000000, i32* %43
%44 = call i32 @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %5
br label %45
45: ; preds = %53, %35
%46 = load i32, i32* %5
%47 = icmp slt i32 %46, 300
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%50 = call i32 @putchar(i8 signext 120)
%51 = load i32, i32* @stdout
%52 = call i32 @fflush(i32 %51)
br label %53
53: ; preds = %48
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %45
56: ; preds = %45
%57 = call i32 @putchar(i8 signext 10)
%58 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 5, i32* %58
%59 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 555000000, i32* %59
%60 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%61 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%62 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str.1 = [7 x i8] c"1 ms: \00"
@.str.3 = [9 x i8] c"100 ms: \00"
@.str.4 = [8 x i8] c"1.5 s: \00"
@.str.5 = [81 x i8] c"1.5 s (probably more because of printing). This line should wrap appropriately: \00"
@stdout = global i32 0
@.str.6 = [10 x i8] c"5.555 s: \00"
@str = [16 x i8] c"A line first...\00"
@str.10 = [5 x i8] c"done\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @putchar(i8 signext 10)
%5 = tail call i32 @putchar(i8 signext 10)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 0, i32* %6
store i32 1000000, i32* %7
%8 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 1000000, i32* %7
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 1000000, i32* %7
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 1000000, i32* %7
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 1000000, i32* %7
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
%23 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %6
store i32 100000000, i32* %7
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 100000000, i32* %7
%27 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 100000000, i32* %7
%30 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 100000000, i32* %7
%33 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 100000000, i32* %7
%36 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
%39 = call i32 @putchar(i8 signext 10)
store i32 1, i32* %6
store i32 500000000, i32* %7
%40 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
store i32 0, i32* %6
store i32 5000000, i32* %7
%43 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([81 x i8], [81 x i8]* @.str.5, i64 0, i64 0))
br label %49
44: ; preds = %49
%45 = call i32 @putchar(i8 signext 10)
store i32 5, i32* %6
store i32 555000000, i32* %7
%46 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%47 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%48 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
ret i32 0
49: ; preds = %0, %49
%50 = phi i32 [ 0, %0 ], [ %55, %49 ]
%51 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%52 = call i32 @putchar(i8 signext 120)
%53 = load i32, i32* @stdout
%54 = call i32 @fflush(i32 %53)
%55 = add nuw nsw i32 %50, 1
%56 = icmp eq i32 %55, 300
br i1 %56, label %44, label %49
}