#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_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
struct timeval time_diff(struct timeval *t_finish_p,
                         struct timeval *t_start_p) {
  struct timeval result;
  if (t_finish_p->tv_sec == t_start_p->tv_sec) {
    result.tv_sec = 0;
    result.tv_usec = t_finish_p->tv_usec - t_start_p->tv_usec;
  } else if (t_finish_p->tv_usec >= t_start_p->tv_usec) {
    result.tv_sec = t_finish_p->tv_sec - t_start_p->tv_sec;
    result.tv_usec = t_finish_p->tv_usec - t_start_p->tv_usec;
  } else {
    result.tv_sec = t_finish_p->tv_sec - t_start_p->tv_sec - 1;
    result.tv_usec = t_finish_p->tv_usec + 1000000 - t_start_p->tv_usec;
  }
  return result;
}


x86 assembly (clang, -O0):
<time_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jne    1141 <time_diff+0x41>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x20(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <time_diff+0xb7>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    0x8(%rcx),%rax
jl     1182 <time_diff+0x82>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x20(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <time_diff+0xb2>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
sub    (%rcx),%rax
sub    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
add    $0xf4240,%rax
mov    -0x20(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <time_diff+0xb7>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_diff>:
mov    (%rdi),%rcx
mov    0x8(%rdi),%rdx
mov    (%rsi),%rdi
mov    0x8(%rsi),%rsi
mov    %rcx,%rax
sub    %rdi,%rax
jne    111c <time_diff+0x1c>
xor    %eax,%eax
sub    %rsi,%rdx
ret
cmp    %rsi,%rdx
jge    1131 <time_diff+0x31>
not    %rdi
add    %rdi,%rcx
add    $0xf4240,%rdx
mov    %rcx,%rax
sub    %rsi,%rdx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define { i64, i64 } @time_diff(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = icmp eq i64 %4, %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%11 = load i64, i64* %10
br i1 %7, label %20, label %12
12: ; preds = %2
%13 = icmp slt i64 %9, %11
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = sub nsw i64 %4, %6
br label %20
16: ; preds = %12
%17 = xor i64 %6, -1
%18 = add i64 %4, %17
%19 = add nsw i64 %9, 1000000
br label %20
20: ; preds = %2, %14, %16
%21 = phi i64 [ %9, %14 ], [ %19, %16 ], [ %9, %2 ]
%22 = phi i64 [ %15, %14 ], [ %18, %16 ], [ 0, %2 ]
%23 = sub i64 %21, %11
%24 = insertvalue { i64, i64 } poison, i64 %22, 0
%25 = insertvalue { i64, i64 } %24, i64 %23, 1
ret { i64, i64 } %25
}