#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_sec;
  int tv_nsec;
};
typedef int /*<<< orphan*/ clockid_t;

/* Variables and functions */
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, scalar_t__, int);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
int /*<<< orphan*/ pthread_getcpuclockid(int /*<<< orphan*/,
                                         int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_self();
void *a_thread_func() {
  clockid_t cpuclock;
  struct timespec ts = {.tv_sec = 1, .tv_nsec = 1};
  pthread_getcpuclockid(pthread_self(), &cpuclock);
  clock_gettime(cpuclock, &ts);
  if (ts.tv_sec != 0) {
    printf("ts.tv_sec: %ld, ts.tv_nsec: %ld\n", ts.tv_sec, ts.tv_nsec);
    exit(1);
  }
  pthread_exit(0);
  return NULL;
}


x86 assembly (clang, -O0):
<a_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,%edi
lea    -0x4(%rbp),%rsi
call   1040 <pthread_getcpuclockid@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmpl   $0x0,-0x10(%rbp)
je     11b8 <a_thread_func+0x58>
movslq -0x10(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe5f(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_thread_func>:
sub    $0x18,%rsp
movabs $0x100000001,%rax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0x14(%rsp),%rsi
mov    %eax,%edi
call   1040 <pthread_getcpuclockid@plt>
mov    0x14(%rsp),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
movslq 0x8(%rsp),%rsi
test   %rsi,%rsi
jne    11ac <a_thread_func+0x4c>
xor    %edi,%edi
call   1060 <pthread_exit@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    0xc(%rsp),%edx
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@__const.a_thread_func.ts = %struct.timespec { i32 1, i32 1 }
@.str = [33 x i8] c"ts.tv_sec: %ld, ts.tv_nsec: %ld\0A\00"
define i8* @a_thread_func() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = call i32 (...) @pthread_self()
%5 = call i32 @pthread_getcpuclockid(i32 %4, i32* %1)
%6 = load i32, i32* %1
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %2)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = call i32 @pthread_exit(i32 0)
ret i8* null
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [33 x i8] c"ts.tv_sec: %ld, ts.tv_nsec: %ld\0A\00"
define noalias i8* @a_thread_func() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timespec*
%4 = bitcast i32* %1 to i8*
%5 = bitcast i64* %2 to i8*
store i64 4294967297, i64* %2
%6 = tail call i32 (...) @pthread_self()
%7 = call i32 @pthread_getcpuclockid(i32 %6, i32* %1)
%8 = load i32, i32* %1
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %3)
%10 = bitcast i64* %2 to i32*
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %0
%14 = sext i32 %11 to i64
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %14, i32 %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = call i32 @pthread_exit(i32 0)
ret i8* null
}