#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 scalar_t__ time_t;
struct timespec {
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ clockid_t;

/* Variables and functions */
scalar_t__ get_delta();
int timemachine_clock_gettime(int /*<<< orphan*/, struct timespec *);
int clock_gettime(clockid_t clk_id, struct timespec *tp) {
  time_t delta = get_delta();
  int retv = timemachine_clock_gettime(clk_id, tp);
  if (retv == 0 && tp) {
    tp->tv_sec += delta;
  }
  return retv;
}


x86 assembly (clang, -O0):
<clock_gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <get_delta@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <timemachine_clock_gettime@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    116e <clock_gettime+0x4e>
cmpq   $0x0,-0x10(%rbp)
je     116e <clock_gettime+0x4e>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq (%rax),%rcx
add    %rdx,%rcx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_gettime>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <get_delta@plt>
mov    %rax,%r14
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <timemachine_clock_gettime@plt>
test   %rbx,%rbx
je     1149 <clock_gettime+0x29>
test   %eax,%eax
jne    1149 <clock_gettime+0x29>
add    %r14d,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
define i32 @clock_gettime(i32 %0, %struct.timespec* %1) {
%3 = alloca i32
%4 = alloca %struct.timespec*
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %3
store %struct.timespec* %1, %struct.timespec** %4
%7 = call i64 (...) @get_delta()
store i64 %7, i64* %5
%8 = load i32, i32* %3
%9 = load %struct.timespec*, %struct.timespec** %4
%10 = call i32 @timemachine_clock_gettime(i32 %8, %struct.timespec* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = load %struct.timespec*, %struct.timespec** %4
%15 = icmp ne %struct.timespec* %14, null
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i64, i64* %5
%18 = load %struct.timespec*, %struct.timespec** %4
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %17
%23 = trunc i64 %22 to i32
store i32 %23, i32* %19
br label %24
24: ; preds = %16, %13, %2
%25 = load i32, i32* %6
ret i32 %25
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
define i32 @clock_gettime(i32 %0, %struct.timespec* %1) {
%3 = tail call i64 (...) @get_delta()
%4 = tail call i32 @timemachine_clock_gettime(i32 %0, %struct.timespec* %1)
%5 = icmp eq i32 %4, 0
%6 = icmp ne %struct.timespec* %1, null
%7 = and i1 %6, %5
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = trunc i64 %3 to i32
%12 = add i32 %10, %11
store i32 %12, i32* %9
br label %13
13: ; preds = %8, %2
ret i32 %4
}