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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long, long);
int main(void) {
  struct timespec t;
  while (1) {
    clock_gettime(CLOCK_MONOTONIC, &t);
    printf("%lds %ldns\n", (long)t.tv_sec, (long)t.tv_nsec);
    t.tv_sec = 1;
    t.tv_nsec = 0;
    nanosleep(&t, NULL);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
movslq -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <nanosleep@plt>
jmp    113f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea8(%rip),%r15
mov    %rsp,%rbx
lea    0xeb6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %rbx,%rsi
call   1030 <clock_gettime@plt>
movslq (%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1040 <printf@plt>
movl   $0x1,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <nanosleep@plt>
jmp    1150 <main+0x20>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@.str = [12 x i8] c"%lds %ldns\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
store i32 0, i32* %1
br label %3
3: ; preds = %0, %3
%4 = load i32, i32* @CLOCK_MONOTONIC
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%7 = load i32, i32* %6
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%10 = load i64, i64* %9
%11 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %8, i64 %10)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 1, i32* %12
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i64 0, i64* %13
%14 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
br label %3
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@.str = [12 x i8] c"%lds %ldns\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
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
br label %5
5: ; preds = %5, %0
%6 = load i32, i32* @CLOCK_MONOTONIC
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %1)
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = load i64, i64* %4
%11 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %9, i64 %10)
store i32 1, i32* %3
store i64 0, i64* %4
%12 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
br label %5
}