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

/* Variables and functions */
struct timeval timediff(struct timeval *a, struct timeval *b) {
  struct timeval rslt, tmp;
  tmp = *a;
  if ((rslt.tv_usec = tmp.tv_usec - b->tv_usec) < 0) {
    rslt.tv_usec += 1000000;
    --(tmp.tv_sec);
  }
  if ((rslt.tv_sec = tmp.tv_sec - b->tv_sec) < 0) {
    rslt.tv_usec = 0;
    rslt.tv_sec = 0;
  }
  return (rslt);
}


x86 assembly (clang, -O0):
<timediff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x30(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    1152 <timediff+0x52>
mov    -0x10(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jge    117c <timediff+0x7c>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<timediff>:
mov    (%rdi),%rcx
mov    0x8(%rdi),%rdx
sub    (%rsi),%rcx
lea    0xf4240(%rcx),%rax
test   %rcx,%rcx
cmovns %rcx,%rax
sar    $0x3f,%rcx
sub    0x8(%rsi),%rdx
xor    %esi,%esi
add    %rcx,%rdx
cmovs  %rsi,%rax
cmovs  %rsi,%rdx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define { i64, i64 } @timediff(%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* %0, i64 0, i32 1
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%8 = load i64, i64* %7
%9 = sub nsw i64 %4, %8
%10 = icmp slt i64 %9, 0
%11 = add nsw i64 %9, 1000000
%12 = select i1 %10, i64 %11, i64 %9
%13 = ashr i64 %9, 63
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%15 = load i64, i64* %14
%16 = sub i64 %6, %15
%17 = add i64 %16, %13
%18 = icmp slt i64 %17, 0
%19 = select i1 %18, i64 0, i64 %12
%20 = select i1 %18, i64 0, i64 %17
%21 = insertvalue { i64, i64 } poison, i64 %19, 0
%22 = insertvalue { i64, i64 } %21, i64 %20, 1
ret { i64, i64 } %22
}