#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;
};
struct syscall_result {
  int dummy;
};
typedef int /*<<< orphan*/ clockid_t;

/* Variables and functions */
int clock_gettime_syscall_wrapper(int /*<<< orphan*/, struct timespec *);
int clock_gettime_vdso_wrapper(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ record_syscall_result(struct syscall_result *, int,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ syscall_prepare();
void clock_gettime_bogus_id(void *arg, struct syscall_result *res) {
  struct timespec ts;
  int err;
  syscall_prepare();
  err = arg ? clock_gettime_syscall_wrapper((clockid_t)-1, &ts)
            : clock_gettime_vdso_wrapper((clockid_t)-1, &ts);
  record_syscall_result(res, err, errno);
}


x86 assembly (clang, -O0):
<clock_gettime_bogus_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <syscall_prepare@plt>
cmpq   $0x0,-0x8(%rbp)
je     1178 <clock_gettime_bogus_id+0x38>
mov    $0xffffffff,%edi
lea    -0x18(%rbp),%rsi
call   1060 <clock_gettime_syscall_wrapper@plt>
mov    %eax,-0x20(%rbp)
jmp    1189 <clock_gettime_bogus_id+0x49>
mov    $0xffffffff,%edi
lea    -0x18(%rbp),%rsi
call   1050 <clock_gettime_vdso_wrapper@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e43(%rip),%rax
mov    (%rax),%edx
call   1040 <record_syscall_result@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_gettime_bogus_id>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <syscall_prepare@plt>
mov    %rsp,%rsi
mov    $0xffffffff,%edi
test   %rbx,%rbx
je     1165 <clock_gettime_bogus_id+0x25>
call   1060 <clock_gettime_syscall_wrapper@plt>
jmp    116a <clock_gettime_bogus_id+0x2a>
call   1050 <clock_gettime_vdso_wrapper@plt>
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%edx
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <record_syscall_result@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.syscall_result = type { i32 }
%struct.timespec = type { i32 }
@errno = global i32 0
define void @clock_gettime_bogus_id(i8* %0, %struct.syscall_result* %1) {
%3 = alloca i8*
%4 = alloca %struct.syscall_result*
%5 = alloca %struct.timespec
%6 = alloca i32
store i8* %0, i8** %3
store %struct.syscall_result* %1, %struct.syscall_result** %4
%7 = call i32 (...) @syscall_prepare()
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @clock_gettime_syscall_wrapper(i32 -1, %struct.timespec* %5)
br label %14
12: ; preds = %2
%13 = call i32 @clock_gettime_vdso_wrapper(i32 -1, %struct.timespec* %5)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ %11, %10 ], [ %13, %12 ]
store i32 %15, i32* %6
%16 = load %struct.syscall_result*, %struct.syscall_result** %4
%17 = load i32, i32* %6
%18 = load i32, i32* @errno
%19 = call i32 @record_syscall_result(%struct.syscall_result* %16, i32 %17, i32 %18)
ret void
}

LLVM IR (-O2):
%struct.syscall_result = type { i32 }
%struct.timespec = type { i32 }
@errno = global i32 0
define void @clock_gettime_bogus_id(i8* readnone %0, %struct.syscall_result* %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = tail call i32 (...) @syscall_prepare()
%6 = icmp eq i8* %0, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @clock_gettime_syscall_wrapper(i32 -1, %struct.timespec* %3)
br label %11
9: ; preds = %2
%10 = call i32 @clock_gettime_vdso_wrapper(i32 -1, %struct.timespec* %3)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ %10, %9 ]
%13 = load i32, i32* @errno
%14 = call i32 @record_syscall_result(%struct.syscall_result* %1, i32 %12, i32 %13)
ret void
}