#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 member_1;
  long long tv_sec;
  long long tv_usec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
struct timeval tkh_timeval_from_micros(long long micros) {
  struct timeval tv = {0, -1};
  if (micros < 0 || micros > 2000000000000000ll)
    return tv;
  tv.tv_sec = micros / 1000000;
  tv.tv_usec = micros - tv.tv_sec * 1000000;
  return tv;
}


x86 assembly (clang, -O0):
<tkh_timeval_from_micros>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x18(%rbp)
mov    %rdi,%rax
mov    %rax,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    0xee6(%rip),%rax
mov    %rax,(%rdi)
mov    0xee4(%rip),%rax
mov    %rax,0x8(%rdi)
mov    0xee1(%rip),%rax
mov    %rax,0x10(%rdi)
mov    0xede(%rip),%rax
mov    %rax,0x18(%rdi)
cmpq   $0x0,-0x8(%rbp)
jl     115d <tkh_timeval_from_micros+0x5d>
movabs $0x71afd498d0000,%rax
cmp    %rax,-0x8(%rbp)
jle    1162 <tkh_timeval_from_micros+0x62>
jmp    118e <tkh_timeval_from_micros+0x8e>
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rcx
imul   $0xf4240,0x8(%rax),%rdx
sub    %rdx,%rcx
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<tkh_timeval_from_micros>:
movups 0xf09(%rip),%xmm0
movups %xmm0,0x10(%rdi)
movups 0xeee(%rip),%xmm0
movups %xmm0,(%rdi)
movabs $0x71afd498d0000,%rax
cmp    %rax,%rsi
ja     114a <tkh_timeval_from_micros+0x4a>
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rsi,%rax
mul    %rcx
shr    $0x12,%rdx
mov    %rdx,0x8(%rdi)
imul   $0xfffffffffff0bdc0,%rdx,%rax
add    %rsi,%rax
mov    %rax,0x10(%rdi)
mov    %rdi,%rax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64, i64, i32 }
@__const.tkh_timeval_from_micros.tv = %struct.timeval { i32 0, i64 -1, i64 0, i32 0 }
define void @tkh_timeval_from_micros(%struct.timeval* noalias sret(%struct.timeval) align 8 %0, i64 %1) {
%3 = alloca i64
store i64 %1, i64* %3
%4 = bitcast %struct.timeval* %0 to i8*
%5 = load i64, i64* %3
%6 = icmp slt i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i64, i64* %3
%9 = icmp sgt i64 %8, 2000000000000000
br i1 %9, label %10, label %11
10: ; preds = %7, %2
br label %21
11: ; preds = %7
%12 = load i64, i64* %3
%13 = sdiv i64 %12, 1000000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i32 0, i32 1
store i64 %13, i64* %14
%15 = load i64, i64* %3
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i32 0, i32 1
%17 = load i64, i64* %16
%18 = mul nsw i64 %17, 1000000
%19 = sub nsw i64 %15, %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i32 0, i32 2
store i64 %19, i64* %20
br label %21
21: ; preds = %11, %10
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64, i64, i32 }
@__const.tkh_timeval_from_micros.tv = %struct.timeval { i32 0, i64 -1, i64 0, i32 0 }
define void @tkh_timeval_from_micros(%struct.timeval* noalias nocapture writeonly sret(%struct.timeval) align 8 %0, i64 %1) {
%3 = bitcast %struct.timeval* %0 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 dereferenceable(32) %3, i8* align 8 dereferenceable(32) bitcast (%struct.timeval* @__const.tkh_timeval_from_micros.tv to i8*), i64 32, i1 false)
%4 = icmp ugt i64 %1, 2000000000000000
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = udiv i64 %1, 1000000
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i64 %6, i64* %7
%8 = mul nsw i64 %6, -1000000
%9 = add nsw i64 %8, %1
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 2
store i64 %9, i64* %10
br label %11
11: ; preds = %2, %5
ret void
}