#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int TIME_UTC;
int __clock_gettime(int /*<<< orphan*/, struct timespec *);
int timespec_get(struct timespec *ts, int base) {
  if (base != TIME_UTC)
    return 0;
  int ret = __clock_gettime(CLOCK_REALTIME, ts);
  return ret < 0 ? 0 : base;
}


x86 assembly (clang, -O0):
<timespec_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2eaf(%rip),%rcx
cmp    (%rcx),%eax
je     113d <timespec_get+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    1172 <timespec_get+0x62>
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <__clock_gettime@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1166 <timespec_get+0x56>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    116c <timespec_get+0x5c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_get>:
push   %rbx
mov    %esi,%ebx
mov    0x2ebe(%rip),%rcx
xor    %eax,%eax
cmp    %esi,(%rcx)
jne    113a <timespec_get+0x2a>
mov    %rdi,%rsi
mov    0x2eb6(%rip),%rax
mov    (%rax),%edi
call   1030 <__clock_gettime@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@TIME_UTC = global i32 0
@CLOCK_REALTIME = global i32 0
define i32 @timespec_get(%struct.timespec* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.timespec*
%5 = alloca i32
%6 = alloca i32
store %struct.timespec* %0, %struct.timespec** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = load i32, i32* @TIME_UTC
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %22
11: ; preds = %2
%12 = load i32, i32* @CLOCK_REALTIME
%13 = load %struct.timespec*, %struct.timespec** %4
%14 = call i32 @__clock_gettime(i32 %12, %struct.timespec* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
br label %20
18: ; preds = %11
%19 = load i32, i32* %5
br label %20
20: ; preds = %18, %17
%21 = phi i32 [ 0, %17 ], [ %19, %18 ]
store i32 %21, i32* %3
br label %22
22: ; preds = %20, %10
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@TIME_UTC = global i32 0
@CLOCK_REALTIME = global i32 0
define i32 @timespec_get(%struct.timespec* %0, i32 %1) {
%3 = load i32, i32* @TIME_UTC
%4 = icmp eq i32 %3, %1
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @CLOCK_REALTIME
%7 = tail call i32 @__clock_gettime(i32 %6, %struct.timespec* %0)
%8 = icmp slt i32 %7, 0
%9 = select i1 %8, i32 0, i32 %1
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ %9, %5 ], [ 0, %2 ]
ret i32 %11
}