#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_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
long zcoroutine_timeout_set_millisecond(long timeout) {
  if (timeout < 0) {
    timeout = (3600L * 24 * 365 * 10 * 1000);
  }
  long r;
  struct timeval tv;
  gettimeofday(&tv, 0);
  r = tv.tv_sec * 1000 + tv.tv_usec / 1000;
  return (r + timeout);
}


x86 assembly (clang, -O0):
<zcoroutine_timeout_set_millisecond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1135 <zcoroutine_timeout_set_millisecond+0x25>
movabs $0x496cebb800,%rax
mov    %rax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
imul   $0x3e8,-0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zcoroutine_timeout_set_millisecond>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
movabs $0x496cebb800,%rbx
cmovns %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
imul   $0x3e8,%rax,%rcx
movslq 0xc(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
cltq
add    %rcx,%rax
add    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i64 @zcoroutine_timeout_set_millisecond(i64 %0) {
%2 = alloca %struct.timeval
%3 = icmp slt i64 %0, 0
%4 = select i1 %3, i64 315360000000, i64 %0
%5 = bitcast %struct.timeval* %2 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = mul nsw i32 %8, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%11 = load i32, i32* %10
%12 = sdiv i32 %11, 1000
%13 = add nsw i32 %12, %9
%14 = sext i32 %13 to i64
%15 = add nsw i64 %4, %14
ret i64 %15
}