#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 /*<<< orphan*/ time_t;
struct timeval {
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ monotime_since(struct timeval const *, struct timeval *);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
time_t monotime_to_realtime(const struct timeval *mono,
                            struct timeval *realout) {
  struct timeval delta, real;
  monotime_since(mono, &delta);
  gettimeofday(&real, NULL);
  timersub(&real, &delta, &real);
  if (realout)
    *realout = real;
  return real.tv_sec;
}


x86 assembly (clang, -O0):
<monotime_to_realtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <monotime_since@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
lea    -0x20(%rbp),%rdx
lea    -0x18(%rbp),%rsi
mov    %rdx,%rdi
call   1050 <timersub@plt>
cmpq   $0x0,-0x10(%rbp)
je     117e <monotime_to_realtime+0x4e>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monotime_to_realtime>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <monotime_since@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <timersub@plt>
test   %r15,%r15
je     1171 <monotime_to_realtime+0x41>
mov    (%rsp),%eax
mov    %eax,(%r15)
jmp    1174 <monotime_to_realtime+0x44>
mov    (%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
define i32 @monotime_to_realtime(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%7 = load %struct.timeval*, %struct.timeval** %3
%8 = call i32 @monotime_since(%struct.timeval* %7, %struct.timeval* %5)
%9 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%10 = call i32 @timersub(%struct.timeval* %6, %struct.timeval* %5, %struct.timeval* %6)
%11 = load %struct.timeval*, %struct.timeval** %4
%12 = icmp ne %struct.timeval* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load %struct.timeval*, %struct.timeval** %4
%15 = bitcast %struct.timeval* %14 to i8*
%16 = bitcast %struct.timeval* %6 to i8*
br label %17
17: ; preds = %13, %2
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%19 = load i32, i32* %18
ret i32 %19
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
define i32 @monotime_to_realtime(%struct.timeval* %0, %struct.timeval* writeonly %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = call i32 @monotime_since(%struct.timeval* %0, %struct.timeval* %3)
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = call i32 @timersub(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %4)
%10 = icmp eq %struct.timeval* %1, null
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
br i1 %10, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* %11
br label %17
14: ; preds = %2
%15 = getelementptr %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%16 = load i32, i32* %11
store i32 %16, i32* %15
br label %17
17: ; preds = %12, %14
%18 = phi i32 [ %13, %12 ], [ %16, %14 ]
ret i32 %18
}