#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 */
void sesc_tvsub(struct timeval *tdiff, struct timeval *t1, struct timeval *t0) {
  tdiff->tv_sec = t1->tv_sec - t0->tv_sec;
  tdiff->tv_usec = t1->tv_usec - t0->tv_usec;
  if (tdiff->tv_usec < 0 && tdiff->tv_sec > 0) {
    tdiff->tv_sec--;
    tdiff->tv_usec += 1000000;
  }
  if (tdiff->tv_usec < 0 || t1->tv_sec < t0->tv_sec) {
    tdiff->tv_sec = 0;
    tdiff->tv_usec = 0;
  }
}


x86 assembly (clang, -O0):
<sesc_tvsub>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jge    117b <sesc_tvsub+0x7b>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jle    117b <sesc_tvsub+0x7b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jl     119e <sesc_tvsub+0x9e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jge    11b5 <sesc_tvsub+0xb5>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<sesc_tvsub>:
movdqu (%rsi),%xmm0
movdqu (%rdx),%xmm1
psubq  %xmm1,%xmm0
movdqu %xmm0,(%rdi)
pshufd $0xee,%xmm0,%xmm1
movq   %xmm1,%rax
test   %rax,%rax
js     1128 <sesc_tvsub+0x28>
mov    (%rsi),%rax
cmp    (%rdx),%rax
jl     1146 <sesc_tvsub+0x46>
ret
movq   %xmm0,%rcx
test   %rcx,%rcx
jle    1146 <sesc_tvsub+0x46>
paddq  0xec6(%rip),%xmm0
movdqu %xmm0,(%rdi)
cmp    $0xfffffffffff0bdc0,%rax
jae    111f <sesc_tvsub+0x1f>
pxor   %xmm0,%xmm0
movdqu %xmm0,(%rdi)
ret

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

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