#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 {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};
typedef int clockid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ clock_getcpuclockid(int /*<<< orphan*/, int *);
int clock_gettime(int, struct timespec *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *, long, long);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  clockid_t id;
  struct timespec ts;
  if (clock_getcpuclockid(getpid(), &id) != 0) {
    perror("clock_getcpuclockid");
    exit(EXIT_FAILURE);
  }
  while (1) {
    if (clock_gettime(id, &ts) == -1) {
      perror("clock_gettime");
      exit(EXIT_FAILURE);
    }
    printf("CPU-time clock (%d) for PID %s is %ld.%09ld seconds\n", id, argv[1],
           (long)ts.tv_sec, (long)ts.tv_nsec);
    fflush(stdout);
    sleep(1);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
lea    -0x14(%rbp),%rsi
call   1060 <clock_getcpuclockid@plt>
cmp    $0x0,%rax
je     11cc <main+0x4c>
lea    0xe47(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11d1 <main+0x51>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    1200 <main+0x80>
lea    0xe27(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe08(%rip),%rdi
call   1050 <printf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    11d1 <main+0x51>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
call   1060 <clock_getcpuclockid@plt>
test   %rax,%rax
jne    1217 <main+0x97>
mov    0x4(%rsp),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
je     120e <main+0x8e>
lea    0xe62(%rip),%r14
mov    0x2e11(%rip),%r12
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
mov    0x4(%rsp),%esi
mov    0x8(%rbx),%rdx
mov    0x8(%rsp),%r8
mov    0x10(%rsp),%rcx
mov    %r14,%rdi
call   1050 <printf@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    0x4(%rsp),%edi
mov    %r15,%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x50>
lea    0xdff(%rip),%rdi
jmp    121e <main+0x9e>
lea    0xde2(%rip),%rdi
call   1080 <perror@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [20 x i8] c"clock_getcpuclockid\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"clock_gettime\00"
@.str.2 = [53 x i8] c"CPU-time clock (%d) for PID %s is %ld.%09ld seconds\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @getpid()
%9 = call i64 @clock_getcpuclockid(i32 %8, i32* %6)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %15, %24
%17 = load i32, i32* %6
%18 = call i32 @clock_gettime(i32 %17, %struct.timespec* %7)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %16
%25 = load i32, i32* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%30 = load i64, i64* %29
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%32 = load i64, i64* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %28, i64 %30, i64 %32)
%34 = load i32, i32* @stdout
%35 = call i32 @fflush(i32 %34)
%36 = call i32 @sleep(i32 1)
br label %16
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@.str = [20 x i8] c"clock_getcpuclockid\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"clock_gettime\00"
@.str.2 = [53 x i8] c"CPU-time clock (%d) for PID %s is %ld.%09ld seconds\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.timespec* %4 to i8*
%7 = tail call i32 (...) @getpid()
%8 = call i64 @clock_getcpuclockid(i32 %7, i32* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* %3
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %22, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
br label %26
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %26, %10
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %14, %26
%27 = load i32, i32* %3
%28 = load i8*, i8** %15
%29 = load i64, i64* %16
%30 = load i64, i64* %17
%31 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %27, i8* %28, i64 %29, i64 %30)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = call i32 @sleep(i32 1)
%35 = load i32, i32* %3
%36 = call i32 @clock_gettime(i32 %35, %struct.timespec* %4)
%37 = icmp eq i32 %36, -1
br i1 %37, label %22, label %26
}