#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 {
  long 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*/);
void addToCurTime(struct timespec *ts, long timediff_ms) {
  struct timeval tv;
  gettimeofday(&tv, 0);
  tv.tv_sec += timediff_ms / 1000;
  tv.tv_usec += (timediff_ms % 1000) * 1000;
  if (tv.tv_usec >= 1000000) {
    tv.tv_sec++;
    tv.tv_usec -= 1000000;
  }
  ts->tv_sec = tv.tv_sec;
  ts->tv_nsec = tv.tv_usec * 1000L;
}


x86 assembly (clang, -O0):
<addToCurTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
imul   $0x3e8,%rdx,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0xf4240,-0x20(%rbp)
jl     1186 <addToCurTime+0x76>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
sub    $0xf4240,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
imul   $0x3e8,-0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addToCurTime>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@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    0x10(%rsp),%rdx
sub    %rax,%rbx
imul   $0x3e8,%rbx,%rax
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,1),%rsi
xor    %edi,%edi
cmp    $0xf4240,%rsi
setge  %dil
lea    -0xf4240(%rcx,%rax,1),%rax
ff
cmovl  %rsi,%rax
add    %rdx,%rdi
mov    %rdi,0x8(%r14)
imul   $0x3e8,%rax,%rax
mov    %rax,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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