#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 /*<<< orphan*/ tv_nsec;
};

/* Variables and functions */
int errno;
struct timespec *malloc(int);
int /*<<< orphan*/ printf(char *, int, ...);
int syscall(int, struct timespec *);
int main() {
  int ret;
  struct timespec *current_time = malloc(sizeof(struct timespec));
  ret = syscall(314, current_time);
  if (ret == 0)
    printf("Time is %ld ns.\n", current_time->tv_nsec);
  else
    printf("ret = %d, errno = %d\n", ret, errno);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x13a,%edi
call   1040 <syscall@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1181 <main+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119b <main+0x6b>
mov    -0x8(%rbp),%esi
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x13a,%edi
mov    %rax,%rsi
call   1040 <syscall@plt>
test   %eax,%eax
je     116a <main+0x3a>
mov    0x2e8a(%rip),%rcx
mov    (%rcx),%edx
lea    0xeb2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    117a <main+0x4a>
mov    (%rbx),%esi
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [17 x i8] c"Time is %ld ns.\0A\00"
@.str.1 = [22 x i8] c"ret = %d, errno = %d\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timespec*
store i32 0, i32* %1
%4 = call %struct.timespec* @malloc(i32 4)
store %struct.timespec* %4, %struct.timespec** %3
%5 = load %struct.timespec*, %struct.timespec** %3
%6 = call i32 @syscall(i32 314, %struct.timespec* %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load %struct.timespec*, %struct.timespec** %3
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %18
14: ; preds = %0
%15 = load i32, i32* %2
%16 = load i32, i32* @errno
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
br label %18
18: ; preds = %14, %9
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@.str = [17 x i8] c"Time is %ld ns.\0A\00"
@.str.1 = [22 x i8] c"ret = %d, errno = %d\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = tail call %struct.timespec* @malloc(i32 4)
%2 = tail call i32 @syscall(i32 314, %struct.timespec* %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %11
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %9)
br label %11
11: ; preds = %8, %4
ret i32 0
}