#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 */
int timeval_compare(struct timeval *, struct timeval *);
int frames_to_send(struct timeval *today, struct timeval *diff,
                   struct timeval *log) {
  struct timeval cmp;
  cmp.tv_sec = log->tv_sec + diff->tv_sec;
  cmp.tv_usec = log->tv_usec + diff->tv_usec;
  if (cmp.tv_usec > 1000000) {
    cmp.tv_usec -= 1000000;
    cmp.tv_sec++;
  }
  if (cmp.tv_usec < 0) {
    cmp.tv_usec += 1000000;
    cmp.tv_sec--;
  }
  return timeval_compare(&cmp, today);
}


x86 assembly (clang, -O0):
<frames_to_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
add    0x8(%rcx),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0xf4240,-0x28(%rbp)
jle    116b <frames_to_send+0x5b>
mov    -0x28(%rbp),%eax
sub    $0xf4240,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    118c <frames_to_send+0x7c>
mov    -0x28(%rbp),%eax
add    $0xf4240,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1030 <timeval_compare@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<frames_to_send>:
sub    $0x18,%rsp
mov    %rdi,%rax
mov    0x8(%rsi),%rcx
add    0x8(%rdx),%rcx
mov    %rcx,0x10(%rsp)
mov    (%rsi),%esi
add    (%rdx),%esi
mov    %esi,0x8(%rsp)
cmp    $0xf4240,%esi
jle    1140 <frames_to_send+0x30>
mov    $0x1,%edx
mov    $0xfff0bdc0,%edi
jmp    1150 <frames_to_send+0x40>
test   %esi,%esi
jns    115e <frames_to_send+0x4e>
mov    $0xffffffffffffffff,%rdx
mov    $0xf4240,%edi
add    %edi,%esi
mov    %esi,0x8(%rsp)
add    %rdx,%rcx
mov    %rcx,0x10(%rsp)
lea    0x8(%rsp),%rdi
mov    %rax,%rsi
call   1030 <timeval_compare@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i32 @frames_to_send(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
%7 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store %struct.timeval* %2, %struct.timeval** %6
%8 = load %struct.timeval*, %struct.timeval** %6
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%10 = load i64, i64* %9
%11 = load %struct.timeval*, %struct.timeval** %5
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%13 = load i64, i64* %12
%14 = add nsw i64 %10, %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 %14, i64* %15
%16 = load %struct.timeval*, %struct.timeval** %6
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load %struct.timeval*, %struct.timeval** %5
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %18, %21
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%25 = load i32, i32* %24
%26 = icmp sgt i32 %25, 1000000
br i1 %26, label %27, label %34
27: ; preds = %3
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%29 = load i32, i32* %28
%30 = sub nsw i32 %29, 1000000
store i32 %30, i32* %28
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%32 = load i64, i64* %31
%33 = add nsw i64 %32, 1
store i64 %33, i64* %31
br label %34
34: ; preds = %27, %3
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%36 = load i32, i32* %35
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1000000
store i32 %41, i32* %39
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%43 = load i64, i64* %42
%44 = add nsw i64 %43, -1
store i64 %44, i64* %42
br label %45
45: ; preds = %38, %34
%46 = load %struct.timeval*, %struct.timeval** %4
%47 = call i32 @timeval_compare(%struct.timeval* %7, %struct.timeval* %46)
ret i32 %47
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @frames_to_send(%struct.timeval* %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture %2) {
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %4 to i8*
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = add nsw i64 %9, %7
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 %10, i64* %11
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, %13
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 %16, i32* %17
%18 = icmp sgt i32 %16, 1000000
br i1 %18, label %21, label %19
19: ; preds = %3
%20 = icmp slt i32 %16, 0
br i1 %20, label %21, label %26
21: ; preds = %19, %3
%22 = phi i32 [ -1000000, %3 ], [ 1000000, %19 ]
%23 = phi i64 [ 1, %3 ], [ -1, %19 ]
%24 = add nsw i32 %16, %22
store i32 %24, i32* %17
%25 = add nsw i64 %10, %23
store i64 %25, i64* %11
br label %26
26: ; preds = %21, %19
%27 = call i32 @timeval_compare(%struct.timeval* %4, %struct.timeval* %0)
ret i32 %27
}