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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void my_gettime(int clk_id __attribute__((unused)), struct timespec *ts) {
  struct timeval tv;
  int res;
  res = gettimeofday(&tv, NULL);
  assert(res == 0);
  ts->tv_sec = tv.tv_sec;
  ts->tv_nsec = tv.tv_usec * 1000;
}


x86 assembly (clang, -O0):
<my_gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
imul   $0x3e8,-0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_gettime>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x4(%rbx)
imul   $0x3e8,0x8(%rsp),%eax
mov    %eax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i32 }
define void @my_gettime(i32 %0, %struct.timespec* %1) {
%3 = alloca i32
%4 = alloca %struct.timespec*
%5 = alloca %struct.timeval
%6 = alloca i32
store i32 %0, i32* %3
store %struct.timespec* %1, %struct.timespec** %4
%7 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%13 = load i32, i32* %12
%14 = load %struct.timespec*, %struct.timespec** %4
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 1
store i32 %13, i32* %15
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, 1000
%19 = load %struct.timespec*, %struct.timespec** %4
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 0
store i32 %18, i32* %20
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i32 }
define void @my_gettime(i32 %0, %struct.timespec* nocapture writeonly %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 1000
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 %14, i32* %15
ret void
}