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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
int pthread_getcpuclockid(int /*<<< orphan*/, int *);
int /*<<< orphan*/ pthread_self();
void *thread_func() {
  int rc;
  clockid_t cid;
  rc = pthread_getcpuclockid(pthread_self(), &cid);
  if (rc != 0) {
    perror("unexpected error: "
           "pthread_getcpuclockid"
           " "
           "1-1"
           ": "
           "pthread_getcpuclockid");
    exit(1);
  }
  printf("clock id of new thread is %d\n", cid);
  pthread_exit(0);
  return NULL;
}


x86 assembly (clang, -O0):
<thread_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
call   1030 <pthread_getcpuclockid@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     119d <thread_func+0x3d>
lea    0xe72(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%esi
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <pthread_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_func>:
push   %rax
xor    %eax,%eax
call   1060 <pthread_self@plt>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
call   1030 <pthread_getcpuclockid@plt>
test   %eax,%eax
jne    1193 <thread_func+0x33>
mov    0x4(%rsp),%esi
lea    0xec0(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <pthread_exit@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe66(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [67 x i8] c"unexpected error: pthread_getcpuclockid 1-1: pthread_getcpuclockid\00"
@.str.1 = [30 x i8] c"clock id of new thread is %d\0A\00"
define i8* @thread_func() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @pthread_self()
%4 = call i32 @pthread_getcpuclockid(i32 %3, i32* %2)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @pthread_exit(i32 0)
ret i8* null
}

LLVM IR (-O2):
@.str = [67 x i8] c"unexpected error: pthread_getcpuclockid 1-1: pthread_getcpuclockid\00"
@.str.1 = [30 x i8] c"clock id of new thread is %d\0A\00"
define noalias i8* @thread_func() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @pthread_self()
%4 = call i32 @pthread_getcpuclockid(i32 %3, i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* %1
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @pthread_exit(i32 0)
ret i8* null
}