#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*/ assert(int);
void timevaladd(struct timeval *tv_io, long ms) {
  struct timeval tmp;
  assert(ms >= 0);
  tmp = *tv_io;
  tmp.tv_usec += (ms % 1000) * 1000;
  tmp.tv_sec += ms / 1000;
  if (tmp.tv_usec >= 1000000) {
    tmp.tv_sec++;
    tmp.tv_usec -= 1000000;
  }
  *tv_io = tmp;
}


x86 assembly (clang, -O0):
<timevaladd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x20(%rbp)
mov    0x8(%rax),%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)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0xf4240,-0x20(%rbp)
jl     11a0 <timevaladd+0x90>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
sub    $0xf4240,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    %rcx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @timevaladd(%struct.timeval* nocapture %0, i64 %1) {
%3 = lshr i64 %1, 63
%4 = trunc i64 %3 to i32
%5 = xor i32 %4, 1
%6 = tail call i32 @assert(i32 %5)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%10 = load i64, i64* %9
%11 = srem i64 %1, 1000
%12 = mul nsw i64 %11, 1000
%13 = add nsw i64 %8, %12
%14 = sdiv i64 %1, 1000
%15 = add nsw i64 %10, %14
%16 = icmp sgt i64 %13, 999999
%17 = add nsw i64 %13, -1000000
%18 = zext i1 %16 to i64
%19 = add nsw i64 %15, %18
%20 = select i1 %16, i64 %17, i64 %13
store i64 %20, i64* %7
store i64 %19, i64* %9
ret void
}