#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 {
  unsigned long tv_sec;
  unsigned long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ timeradd(struct timeval *, struct timeval *,
                            struct timeval *);
void __sumjob_set_timeout(struct timeval *deadline,
                          unsigned long timeout_usec) {
  struct timeval timeout_tv;
  timeout_tv.tv_sec = timeout_usec / 1000000;
  timeout_tv.tv_usec = timeout_usec % 1000000;
  gettimeofday(deadline, NULL);
  timeradd(deadline, &timeout_tv, deadline);
}


x86 assembly (clang, -O0):
<__sumjob_set_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rsi
call   1030 <timeradd@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__sumjob_set_timeout>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rsi,%rax
mul    %rcx
shr    $0x12,%rdx
mov    %rdx,(%rsp)
imul   $0xf4240,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,0x8(%rsp)
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
call   1030 <timeradd@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define void @__sumjob_set_timeout(%struct.timeval* %0, i64 %1) {
%3 = alloca %struct.timeval*
%4 = alloca i64
%5 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = udiv i64 %6, 1000000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i64 %7, i64* %8
%9 = load i64, i64* %4
%10 = urem i64 %9, 1000000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 %10, i64* %11
%12 = load %struct.timeval*, %struct.timeval** %3
%13 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%14 = load %struct.timeval*, %struct.timeval** %3
%15 = load %struct.timeval*, %struct.timeval** %3
%16 = call i32 @timeradd(%struct.timeval* %14, %struct.timeval* %5, %struct.timeval* %15)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @__sumjob_set_timeout(%struct.timeval* %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = udiv i64 %1, 1000000
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i64 %5, i64* %6
%7 = urem i64 %1, 1000000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 %7, i64* %8
%9 = tail call i32 @gettimeofday(%struct.timeval* %0, i32* null)
%10 = call i32 @timeradd(%struct.timeval* %0, %struct.timeval* %3, %struct.timeval* %0)
ret void
}