#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;
};
typedef int pid_t;
typedef int clockid_t;

/* Variables and functions */
int __syscall(int, int, struct timespec *);
int clock_getcpuclockid(pid_t pid, clockid_t *clk) {
  struct timespec ts;
  clockid_t id = (-pid - 1) * 8U + 2;
  int ret = __syscall(264, id, &ts);
  if (ret)
    return -ret;
  *clk = id;
  return 0;
}


x86 assembly (clang, -O0):
<clock_getcpuclockid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
sub    -0x8(%rbp),%eax
sub    $0x1,%eax
shl    $0x3,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x108,%edi
lea    -0x18(%rbp),%rdx
call   1030 <__syscall@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     115b <clock_getcpuclockid+0x4b>
xor    %eax,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    116b <clock_getcpuclockid+0x5b>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_getcpuclockid>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
not    %edi
lea    0x2(,%rdi,8),%ebp
mov    %rsp,%rdx
mov    $0x108,%edi
mov    %ebp,%esi
call   1030 <__syscall@plt>
test   %eax,%eax
je     1136 <clock_getcpuclockid+0x26>
neg    %eax
jmp    113a <clock_getcpuclockid+0x2a>
mov    %ebp,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
define i32 @clock_getcpuclockid(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.timespec
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = load i32, i32* %4
%10 = sub nsw i32 0, %9
%11 = sub nsw i32 %10, 1
%12 = mul i32 %11, 8
%13 = add i32 %12, 2
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i32 @__syscall(i32 264, i32 %14, %struct.timespec* %6)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* %8
%20 = sub nsw i32 0, %19
store i32 %20, i32* %3
br label %24
21: ; preds = %2
%22 = load i32, i32* %7
%23 = load i32*, i32** %5
store i32 %22, i32* %23
store i32 0, i32* %3
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
define i32 @clock_getcpuclockid(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = xor i32 %0, -1
%6 = shl i32 %5, 3
%7 = or i32 %6, 2
%8 = call i32 @__syscall(i32 264, i32 %7, %struct.timespec* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = sub nsw i32 0, %8
br label %13
12: ; preds = %2
store i32 %7, i32* %1
br label %13
13: ; preds = %12, %10
%14 = phi i32 [ %11, %10 ], [ 0, %12 ]
ret i32 %14
}