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

/* Variables and functions */
int /*<<< orphan*/ SYS_clock_gettime;
scalar_t__ clock_gettime(scalar_t__, struct timespec *);
int /*<<< orphan*/ ksft_test_result_error(char *, int);
int syscall(int /*<<< orphan*/, scalar_t__, struct timespec *);
int _gettime(clockid_t clk_id, struct timespec *res, bool raw_syscall) {
  int err;
  if (!raw_syscall) {
    if (clock_gettime(clk_id, res)) {
      ({
        ksft_test_result_error("clock_gettime(%d)"
                               ": %m"
                               "\n",
                               (int)clk_id);
        -1;
      });
      return -1;
    }
    return 0;
  }
  err = syscall(SYS_clock_gettime, clk_id, res);
  if (err)
    ({
      ksft_test_result_error("syscall(SYS_clock_gettime(%d))"
                             ": %m"
                             "\n",
                             (int)clk_id);
      -1;
    });
  return err;
}


x86 assembly (clang, -O0):
<_gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1195 <_gettime+0x65>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     1189 <_gettime+0x59>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe8f(%rip),%rdi
call   1040 <ksft_test_result_error@plt>
movl   $0xffffffff,-0x24(%rbp)
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <_gettime+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    11d7 <_gettime+0xa7>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <syscall@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11d1 <_gettime+0xa1>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe52(%rip),%rdi
call   1040 <ksft_test_result_error@plt>
movl   $0xffffffff,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gettime>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbx
test   %edx,%edx
je     1160 <_gettime+0x30>
mov    0x2eac(%rip),%rcx
mov    (%rcx),%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <syscall@plt>
test   %eax,%eax
je     1185 <_gettime+0x55>
mov    %eax,%ebp
lea    0xeb9(%rip),%rdi
jmp    117c <_gettime+0x4c>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
je     1185 <_gettime+0x55>
mov    $0xffffffff,%ebp
lea    0xe84(%rip),%rdi
mov    %ebx,%esi
call   1040 <ksft_test_result_error@plt>
jmp    1187 <_gettime+0x57>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [23 x i8] c"clock_gettime(%d): %m\0A\00"
@SYS_clock_gettime = global i32 0
@.str.1 = [36 x i8] c"syscall(SYS_clock_gettime(%d)): %m\0A\00"
define i32 @_gettime(i64 %0, %struct.timespec* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.timespec*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i64 %0, i64* %5
store %struct.timespec* %1, %struct.timespec** %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %3
%14 = load i64, i64* %5
%15 = load %struct.timespec*, %struct.timespec** %6
%16 = call i64 @clock_gettime(i64 %14, %struct.timespec* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i64, i64* %5
%20 = trunc i64 %19 to i32
%21 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 -1, i32* %9
%22 = load i32, i32* %9
store i32 -1, i32* %4
br label %38
23: ; preds = %13
store i32 0, i32* %4
br label %38
24: ; preds = %3
%25 = load i32, i32* @SYS_clock_gettime
%26 = load i64, i64* %5
%27 = load %struct.timespec*, %struct.timespec** %6
%28 = call i32 @syscall(i32 %25, i64 %26, %struct.timespec* %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load i64, i64* %5
%33 = trunc i64 %32 to i32
%34 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %33)
store i32 -1, i32* %10
%35 = load i32, i32* %10
br label %36
36: ; preds = %31, %24
%37 = load i32, i32* %8
store i32 %37, i32* %4
br label %38
38: ; preds = %36, %23, %18
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@.str = [23 x i8] c"clock_gettime(%d): %m\0A\00"
@SYS_clock_gettime = global i32 0
@.str.1 = [36 x i8] c"syscall(SYS_clock_gettime(%d)): %m\0A\00"
define i32 @_gettime(i64 %0, %struct.timespec* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = tail call i64 @clock_gettime(i64 %0, %struct.timespec* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %17, label %12
8: ; preds = %3
%9 = load i32, i32* @SYS_clock_gettime
%10 = tail call i32 @syscall(i32 %9, i64 %0, %struct.timespec* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8, %5
%13 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %8 ]
%14 = phi i32 [ -1, %5 ], [ %10, %8 ]
%15 = trunc i64 %0 to i32
%16 = tail call i32 @ksft_test_result_error(i8* %13, i32 %15)
br label %17
17: ; preds = %12, %8, %5
%18 = phi i32 [ 0, %5 ], [ 0, %8 ], [ %14, %12 ]
ret i32 %18
}