#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*/ timeradd(struct timeval *, struct timeval *,
                            struct timeval *);
struct timeval timeval_add_msec(struct timeval a, unsigned long msec) {
  struct timeval ret;
  struct timeval addtime;
  addtime.tv_sec = msec / 1000;
  addtime.tv_usec = (msec % 1000) * 1000;
  timeradd(&a, &addtime, &ret);
  return ret;
}


x86 assembly (clang, -O0):
<timeval_add_msec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
shr    $0x4,%rdx
mov    %rdx,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
shr    $0x3,%rax
mul    %rcx
mov    -0x40(%rbp),%rax
shr    $0x4,%rdx
imul   $0x3e8,%rdx,%rcx
sub    %rcx,%rax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <timeradd@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_add_msec>:
sub    $0x38,%rsp
mov    %rdx,%rcx
mov    %rdi,0x18(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdx,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mul    %rdx
shr    $0x4,%rdx
mov    %rdx,0x8(%rsp)
imul   $0x3e8,%rdx,%rax
sub    %rax,%rcx
imul   $0x3e8,%rcx,%rax
mov    %rax,0x10(%rsp)
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x28(%rsp),%rdx
call   1030 <timeradd@plt>
mov    0x28(%rsp),%rax
mov    0x30(%rsp),%rdx
add    $0x38,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define { i64, i64 } @timeval_add_msec(i64 %0, i64 %1, i64 %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca i64
%7 = alloca %struct.timeval
%8 = bitcast %struct.timeval* %5 to { i64, i64 }*
%9 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 0
store i64 %0, i64* %9
%10 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 1
store i64 %1, i64* %10
store i64 %2, i64* %6
%11 = load i64, i64* %6
%12 = udiv i64 %11, 1000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i64 %12, i64* %13
%14 = load i64, i64* %6
%15 = urem i64 %14, 1000
%16 = mul i64 %15, 1000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 %16, i64* %17
%18 = call i32 @timeradd(%struct.timeval* %5, %struct.timeval* %7, %struct.timeval* %4)
%19 = bitcast %struct.timeval* %4 to { i64, i64 }*
%20 = load { i64, i64 }, { i64, i64 }* %19
ret { i64, i64 } %20
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define { i64, i64 } @timeval_add_msec(i64 %0, i64 %1, i64 %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i64 %0, i64* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 %1, i64* %8
%9 = bitcast %struct.timeval* %6 to i8*
%10 = udiv i64 %2, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
store i64 %10, i64* %11
%12 = urem i64 %2, 1000
%13 = mul nuw nsw i64 %12, 1000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
store i64 %13, i64* %14
%15 = call i32 @timeradd(%struct.timeval* %5, %struct.timeval* %6, %struct.timeval* %4)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%17 = load i64, i64* %16
%18 = insertvalue { i64, i64 } poison, i64 %17, 0
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%20 = load i64, i64* %19
%21 = insertvalue { i64, i64 } %18, i64 %20, 1
ret { i64, i64 } %21
}