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

/* Variables and functions */
void timeval_adjust_usec(struct timeval *l, struct timeval *r) {
  int tmpsec;
  if (r->tv_usec > l->tv_usec) {
    tmpsec = (r->tv_usec - l->tv_usec) / 1000000 + 1;
    r->tv_sec += tmpsec;
    r->tv_usec -= 1000000 * tmpsec;
  }
  if ((l->tv_usec - r->tv_usec) > 1000000) {
    tmpsec = (l->tv_usec - r->tv_usec) / 1000000;
    r->tv_sec -= tmpsec;
    r->tv_usec += 1000000 * tmpsec;
  }
}


x86 assembly (clang, -O0):
<timeval_adjust_usec>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
jle    1163 <timeval_adjust_usec+0x63>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
add    $0x1,%rax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
imul   $0xf4240,-0x14(%rbp),%eax
movslq %eax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
cmp    $0xf4240,%rax
jle    11bb <timeval_adjust_usec+0xbb>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
sub    %edx,%ecx
mov    %ecx,0x8(%rax)
imul   $0xf4240,-0x14(%rbp),%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_adjust_usec>:
mov    (%rsi),%r8
mov    (%rdi),%rax
mov    %r8,%rcx
movabs $0x431bde82d7b634db,%r9
de 1b 43
sub    %rax,%rcx
jle    1142 <timeval_adjust_usec+0x42>
mov    %rcx,%rax
imul   %r9
mov    %rdx,%rax
shr    $0x12,%rax
shr    $0x3f,%rdx
add    %edx,%eax
add    $0x1,%eax
add    %eax,0x8(%rsi)
imul   $0xf4240,%eax,%eax
cltq
sub    %rax,%r8
mov    %r8,(%rsi)
mov    (%rdi),%rax
sub    %r8,%rax
cmp    $0xf4241,%rax
jl     116f <timeval_adjust_usec+0x6f>
mul    %r9
shr    $0x12,%rdx
sub    %edx,0x8(%rsi)
movabs $0xf424000000000,%rax
imul   %rdx,%rax
sar    $0x20,%rax
add    %r8,%rax
mov    %rax,(%rsi)
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define void @timeval_adjust_usec(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%6 = load %struct.timeval*, %struct.timeval** %4
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%8 = load i64, i64* %7
%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 = icmp sgt i64 %8, %11
br i1 %12, label %13, label %36
13: ; preds = %2
%14 = load %struct.timeval*, %struct.timeval** %4
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load %struct.timeval*, %struct.timeval** %3
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = sub nsw i64 %16, %19
%21 = sdiv i64 %20, 1000000
%22 = add nsw i64 %21, 1
%23 = trunc i64 %22 to i32
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = load %struct.timeval*, %struct.timeval** %4
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = add nsw i32 %27, %24
store i32 %28, i32* %26
%29 = load i32, i32* %5
%30 = mul nsw i32 1000000, %29
%31 = sext i32 %30 to i64
%32 = load %struct.timeval*, %struct.timeval** %4
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %32, i32 0, i32 0
%34 = load i64, i64* %33
%35 = sub nsw i64 %34, %31
store i64 %35, i64* %33
br label %36
36: ; preds = %13, %2
%37 = load %struct.timeval*, %struct.timeval** %3
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = load %struct.timeval*, %struct.timeval** %4
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = sub nsw i64 %39, %42
%44 = icmp sgt i64 %43, 1000000
br i1 %44, label %45, label %67
45: ; preds = %36
%46 = load %struct.timeval*, %struct.timeval** %3
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %46, i32 0, i32 0
%48 = load i64, i64* %47
%49 = load %struct.timeval*, %struct.timeval** %4
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %49, i32 0, i32 0
%51 = load i64, i64* %50
%52 = sub nsw i64 %48, %51
%53 = sdiv i64 %52, 1000000
%54 = trunc i64 %53 to i32
store i32 %54, i32* %5
%55 = load i32, i32* %5
%56 = load %struct.timeval*, %struct.timeval** %4
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %56, i32 0, i32 1
%58 = load i32, i32* %57
%59 = sub nsw i32 %58, %55
store i32 %59, i32* %57
%60 = load i32, i32* %5
%61 = mul nsw i32 1000000, %60
%62 = sext i32 %61 to i64
%63 = load %struct.timeval*, %struct.timeval** %4
%64 = getelementptr inbounds %struct.timeval, %struct.timeval* %63, i32 0, i32 0
%65 = load i64, i64* %64
%66 = add nsw i64 %65, %62
store i64 %66, i64* %64
br label %67
67: ; preds = %45, %36
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
define void @timeval_adjust_usec(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = icmp sgt i64 %4, %6
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = sub nsw i64 %4, %6
%10 = sdiv i64 %9, 1000000
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 1
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %14, %12
store i32 %15, i32* %13
%16 = mul nsw i32 %12, 1000000
%17 = sext i32 %16 to i64
%18 = sub nsw i64 %4, %17
store i64 %18, i64* %3
%19 = load i64, i64* %5
br label %20
20: ; preds = %8, %2
%21 = phi i64 [ %18, %8 ], [ %4, %2 ]
%22 = phi i64 [ %19, %8 ], [ %6, %2 ]
%23 = sub nsw i64 %22, %21
%24 = icmp sgt i64 %23, 1000000
br i1 %24, label %25, label %34
25: ; preds = %20
%26 = udiv i64 %23, 1000000
%27 = trunc i64 %26 to i32
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%29 = load i32, i32* %28
%30 = sub nsw i32 %29, %27
store i32 %30, i32* %28
%31 = mul i64 %26, 4294967296000000
%32 = ashr exact i64 %31, 32
%33 = add nsw i64 %32, %21
store i64 %33, i64* %3
br label %34
34: ; preds = %25, %20
ret void
}