#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 */
typedef int time_t;
struct timespec {
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
time_t time(time_t *result) {
  struct timespec ts;
  if (clock_gettime(CLOCK_REALTIME, &ts) < 0) {
    return -1;
  }
  if (result) {
    *result = ts.tv_sec;
  }
  return ts.tv_sec;
}


x86 assembly (clang, -O0):
<time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
jge    1144 <time+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    115e <time+0x4e>
cmpq   $0x0,-0x10(%rbp)
je     1158 <time+0x48>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ec1(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
js     113d <time+0x2d>
mov    0x8(%rsp),%eax
test   %rbx,%rbx
je     1142 <time+0x32>
mov    %eax,(%rbx)
jmp    1142 <time+0x32>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
define i32 @time(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.timespec
store i32* %0, i32** %3
%5 = load i32, i32* @CLOCK_REALTIME
%6 = call i64 @clock_gettime(i32 %5, %struct.timespec* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %19
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32*, i32** %3
store i32 %14, i32* %15
br label %16
16: ; preds = %12, %9
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %8
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_REALTIME = global i32 0
define i32 @time(i32* writeonly %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = load i32, i32* @CLOCK_REALTIME
%5 = call i64 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = icmp eq i32* %0, null
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%10 = load i32, i32* %9
br i1 %8, label %12, label %11
11: ; preds = %7
store i32 %10, i32* %0
br label %12
12: ; preds = %7, %11, %1
%13 = phi i32 [ -1, %1 ], [ %10, %11 ], [ %10, %7 ]
ret i32 %13
}