#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_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  struct timespec tp;
  tp.tv_sec = 0;
  tp.tv_nsec = 0;
  if (clock_gettime(CLOCK_REALTIME, &tp) == 0) {
    if (0 != tp.tv_sec) {
      printf("Test PASSED\n");
      return 0;
    } else {
      printf("clock_gettime() success, but tp not filled\n");
      return 1;
    }
  }
  printf("clock_gettime() failed\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
jne    1197 <main+0x77>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     117f <main+0x5f>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11aa <main+0x8a>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11aa <main+0x8a>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <clock_gettime@plt>
cmpq   $0x0,(%rsp)
lea    0xece(%rip),%rcx
lea    0xef2(%rip),%rdx
cmove  %rcx,%rdx
sete   %cl
test   %rax,%rax
setne  %al
lea    0xe9c(%rip),%rdi
cmove  %rdx,%rdi
or     %cl,%al
movzbl %al,%ebx
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [13 x i8] c"Test PASSED\0A\00"
@.str.1 = [44 x i8] c"clock_gettime() success, but tp not filled\0A\00"
@.str.2 = [24 x i8] c"clock_gettime() failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
store i32 0, i32* %1
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i64 0, i64* %3
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i64 0, i64* %4
%5 = load i32, i32* @CLOCK_REALTIME
%6 = call i64 @clock_gettime(i32 %5, %struct.timespec* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%10 = load i64, i64* %9
%11 = icmp ne i64 0, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %18
14: ; preds = %8
%15 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %18
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %18
18: ; preds = %16, %14, %12
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_REALTIME = global i32 0
@str = [23 x i8] c"clock_gettime() failed\00"
@str.3 = [43 x i8] c"clock_gettime() success, but tp not filled\00"
@str.4 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%4 = bitcast %struct.timespec* %1 to i8*
%5 = load i32, i32* @CLOCK_REALTIME
%6 = call i64 @clock_gettime(i32 %5, %struct.timespec* %1)
%7 = icmp eq i64 %6, 0
%8 = load i64, i64* %3
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0)
%11 = select i1 %7, i8* %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0)
%12 = xor i1 %7, true
%13 = select i1 %12, i1 true, i1 %9
%14 = zext i1 %13 to i32
%15 = call i32 @puts(i8* dereferenceable(1) %11)
ret i32 %14
}