#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_nsec;
  scalar_t__ tv_sec;
};
typedef int clock_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ __ploop_err(int /*<<< orphan*/, char *);
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ errno;
clock_t get_cpu_time(void) {
  struct timespec ts;
  if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
    __ploop_err(errno, "clock_gettime");
    return (clock_t)-1;
  }
  return ((clock_t)(ts.tv_sec) * 1000000000) + ts.tv_nsec;
}


x86 assembly (clang, -O0):
<get_cpu_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     1165 <get_cpu_time+0x45>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xeac(%rip),%rsi
call   1040 <__ploop_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1175 <get_cpu_time+0x55>
mov    -0x10(%rbp),%rax
imul   $0x3b9aca00,%eax,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_time>:
sub    $0x18,%rsp
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
je     115b <get_cpu_time+0x3b>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    0xeb4(%rip),%rsi
call   1040 <__ploop_err@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret
imul   $0x3b9aca00,0x10(%rsp),%eax
3b
add    0x8(%rsp),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@errno = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
define i32 @get_cpu_time() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @__ploop_err(i32 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %17
9: ; preds = %0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%11 = load i64, i64* %10
%12 = trunc i64 %11 to i32
%13 = mul nsw i32 %12, 1000000000
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %13, %15
store i32 %16, i32* %1
br label %17
17: ; preds = %9, %6
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@errno = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
define i32 @get_cpu_time() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @__ploop_err(i32 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %17
9: ; preds = %0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%11 = load i64, i64* %10
%12 = trunc i64 %11 to i32
%13 = mul nsw i32 %12, 1000000000
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %13, %15
br label %17
17: ; preds = %9, %6
%18 = phi i32 [ -1, %6 ], [ %16, %9 ]
ret i32 %18
}