#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 timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct timespec {
  long tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int _ythread_timespec_get(struct timespec *ts, int base) {
  struct timeval tv;
  if (base != 1)
    return 0;
  gettimeofday(&tv, NULL);
  ts->tv_sec = (time_t)tv.tv_sec;
  ts->tv_nsec = 1000L * (long)tv.tv_usec;
  return base;
}


x86 assembly (clang, -O0):
<_ythread_timespec_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
je     1135 <_ythread_timespec_get+0x25>
movl   $0x0,-0x4(%rbp)
jmp    1163 <_ythread_timespec_get+0x53>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
imul   $0x3e8,-0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ythread_timespec_get>:
xor    %eax,%eax
cmp    $0x1,%esi
jne    1147 <_ythread_timespec_get+0x37>
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rax
mov    %rax,0x8(%rbx)
imul   $0x3e8,(%rsp),%rax
mov    %rax,(%rbx)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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