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

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


x86 assembly (clang, -O0):
<a_thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmpl   $0x0,-0x8(%rbp)
jne    116c <a_thread_func+0x3c>
cmpl   $0x5f5e100,-0x4(%rbp)
jl     1189 <a_thread_func+0x59>
movslq -0x8(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_thread_func>:
push   %rax
movabs $0x100000001,%rax
mov    %rax,(%rsp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
movslq (%rsp),%rsi
mov    0x4(%rsp),%edx
test   %rsi,%rsi
jne    1169 <a_thread_func+0x39>
cmp    $0x5f5e100,%edx
jge    1169 <a_thread_func+0x39>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

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