#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 */

/* Variables and functions */
int /*<<< orphan*/ get_time(long *, long *);
void add_millisec_to_now(long long milliseconds, long *sec, long *us) {
  long cur_sec, cur_us, when_sec, when_us;
  get_time(&cur_sec, &cur_us);
  when_sec = cur_sec + milliseconds / 1000;
  when_us = cur_us + (milliseconds % 1000) * 1000;
  if (when_us >= 1000000) {
    when_sec++;
    when_us -= 1000000;
  }
  *sec = when_sec;
  *us = when_us;
}


x86 assembly (clang, -O0):
<add_millisec_to_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <get_time@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    -0x40(%rbp),%rax
imul   $0x3e8,%rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0xf4240,-0x38(%rbp)
jl     11a5 <add_millisec_to_now+0x95>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
sub    $0xf4240,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_millisec_to_now>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <get_time@plt>
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mov    %rbx,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x7,%rdx
add    %rax,%rdx
imul   $0x3e8,%rdx,%rax
add    0x8(%rsp),%rdx
mov    (%rsp),%rcx
sub    %rax,%rbx
imul   $0x3e8,%rbx,%rax
lea    (%rcx,%rax,1),%rsi
xor    %edi,%edi
cmp    $0xf4240,%rsi
lea    -0xf4240(%rcx,%rax,1),%rax
ff
cmovl  %rsi,%rax
setge  %dil
add    %rdx,%rdi
mov    %rdi,(%r15)
mov    %rax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @add_millisec_to_now(i64 %0, i64* %1, i64* %2) {
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%11 = call i32 @get_time(i64* %7, i64* %8)
%12 = load i64, i64* %7
%13 = load i64, i64* %4
%14 = sdiv i64 %13, 1000
%15 = add nsw i64 %12, %14
store i64 %15, i64* %9
%16 = load i64, i64* %8
%17 = load i64, i64* %4
%18 = srem i64 %17, 1000
%19 = mul nsw i64 %18, 1000
%20 = add nsw i64 %16, %19
store i64 %20, i64* %10
%21 = load i64, i64* %10
%22 = icmp sge i64 %21, 1000000
br i1 %22, label %23, label %28
23: ; preds = %3
%24 = load i64, i64* %9
%25 = add nsw i64 %24, 1
store i64 %25, i64* %9
%26 = load i64, i64* %10
%27 = sub nsw i64 %26, 1000000
store i64 %27, i64* %10
br label %28
28: ; preds = %23, %3
%29 = load i64, i64* %9
%30 = load i64*, i64** %5
store i64 %29, i64* %30
%31 = load i64, i64* %10
%32 = load i64*, i64** %6
store i64 %31, i64* %32
ret void
}

LLVM IR (-O2):
define void @add_millisec_to_now(i64 %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i64* %4 to i8*
%7 = bitcast i64* %5 to i8*
%8 = call i32 @get_time(i64* %4, i64* %5)
%9 = load i64, i64* %4
%10 = sdiv i64 %0, 1000
%11 = add nsw i64 %9, %10
%12 = load i64, i64* %5
%13 = srem i64 %0, 1000
%14 = mul nsw i64 %13, 1000
%15 = add nsw i64 %12, %14
%16 = icmp sgt i64 %15, 999999
%17 = add nsw i64 %15, -1000000
%18 = zext i1 %16 to i64
%19 = add nsw i64 %11, %18
%20 = select i1 %16, i64 %17, i64 %15
store i64 %19, i64* %1
store i64 %20, i64* %2
ret void
}