#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 {
  int tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
struct timeval Timeval_add(const struct timeval x, long long usec_delta) {
  struct timeval retval;
  long long sec_delta, usec;
  const long long K = (1000LL * 1000LL);
  usec = usec_delta + (long long)x.tv_usec;
  sec_delta = usec / K;
  usec %= K;
  retval.tv_sec = x.tv_sec + (int)sec_delta;
  retval.tv_usec = (int)usec;
  return retval;
}


x86 assembly (clang, -O0):
<Timeval_add>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x20(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x28(%rbp)
movq   $0xf4240,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movabs $0x431bde82d7b634db,%rcx
de 1b 43
imul   %rcx
mov    %rdx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x12,%rax
add    %rdx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
imul   %rcx
mov    -0x48(%rbp),%rax
mov    %rdx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x12,%rcx
add    %rdx,%rcx
imul   $0xf4240,%rcx,%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<Timeval_add>:
movslq %edi,%rcx
add    %rdx,%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,%edx,%eax
sub    %eax,%ecx
movslq %edx,%rdx
add    %rsi,%rdx
mov    %ecx,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define { i32, i64 } @Timeval_add(i32 %0, i64 %1, i64 %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = bitcast %struct.timeval* %5 to { i32, i64 }*
%11 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %10, i32 0, i32 0
store i32 %0, i32* %11
%12 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %10, i32 0, i32 1
store i64 %1, i64* %12
store i64 %2, i64* %6
store i64 1000000, i64* %9
%13 = load i64, i64* %6
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = add nsw i64 %13, %16
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = sdiv i64 %18, 1000000
store i64 %19, i64* %7
%20 = load i64, i64* %8
%21 = srem i64 %20, 1000000
store i64 %21, i64* %8
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%23 = load i64, i64* %22
%24 = load i64, i64* %7
%25 = trunc i64 %24 to i32
%26 = sext i32 %25 to i64
%27 = add nsw i64 %23, %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i64 %27, i64* %28
%29 = load i64, i64* %8
%30 = trunc i64 %29 to i32
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i32 %30, i32* %31
%32 = bitcast %struct.timeval* %4 to { i32, i64 }*
%33 = load { i32, i64 }, { i32, i64 }* %32
ret { i32, i64 } %33
}

LLVM IR (-O2):
define { i32, i64 } @Timeval_add(i32 %0, i64 %1, i64 %2) {
%4 = sext i32 %0 to i64
%5 = add nsw i64 %4, %2
%6 = sdiv i64 %5, 1000000
%7 = srem i64 %5, 1000000
%8 = shl i64 %6, 32
%9 = ashr exact i64 %8, 32
%10 = add nsw i64 %9, %1
%11 = trunc i64 %7 to i32
%12 = insertvalue { i32, i64 } poison, i32 %11, 0
%13 = insertvalue { i32, i64 } %12, i64 %10, 1
ret { i32, i64 } %13
}