#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;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void add_ms(struct timeval *tv, long ms) {
  long s, usec;
  gettimeofday(tv, NULL);
  usec = tv->tv_usec + (ms * 1000);
  s = usec / 1000000;
  tv->tv_usec = usec % 1000000;
  tv->tv_sec = tv->tv_sec + s;
}


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

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

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define void @add_ms(%struct.timeval* %0, i64 %1) {
%3 = alloca %struct.timeval*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
store i64 %1, i64* %4
%7 = load %struct.timeval*, %struct.timeval** %3
%8 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%9 = load %struct.timeval*, %struct.timeval** %3
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* %4
%13 = mul nsw i64 %12, 1000
%14 = add nsw i64 %11, %13
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = sdiv i64 %15, 1000000
store i64 %16, i64* %5
%17 = load i64, i64* %6
%18 = srem i64 %17, 1000000
%19 = load %struct.timeval*, %struct.timeval** %3
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
store i64 %18, i64* %20
%21 = load %struct.timeval*, %struct.timeval** %3
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
%23 = load i64, i64* %22
%24 = load i64, i64* %5
%25 = add nsw i64 %23, %24
%26 = load %struct.timeval*, %struct.timeval** %3
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %26, i32 0, i32 1
store i64 %25, i64* %27
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @add_ms(%struct.timeval* nocapture %0, i64 %1) {
%3 = tail call i32 @gettimeofday(%struct.timeval* %0, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = mul nsw i64 %1, 1000
%7 = add nsw i64 %5, %6
%8 = sdiv i64 %7, 1000000
%9 = srem i64 %7, 1000000
store i64 %9, i64* %4
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%11 = load i64, i64* %10
%12 = add nsw i64 %11, %8
store i64 %12, i64* %10
ret void
}