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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int timediff(struct timeval *t1, struct timeval *t2, struct timeval *diff) {
  int cmp = 0;
  struct timeval result;
  if (diff == NULL)
    diff = &result;
  diff->tv_sec = t2->tv_sec - t1->tv_sec;
  diff->tv_usec = t2->tv_usec - t1->tv_usec;
  if (diff->tv_sec == 0 && diff->tv_usec == 0) {
  } else if (diff->tv_sec <= 0 && diff->tv_usec <= 0) {
    cmp = -1;
    diff->tv_sec *= -1;
    diff->tv_usec *= -1;
  } else if (diff->tv_sec >= 0 && diff->tv_usec >= 0) {
    cmp = 1;
  } else if (diff->tv_sec < 0 && diff->tv_usec > 0) {
    cmp = -1;
    diff->tv_sec += 1;
    diff->tv_usec = 1000000 - diff->tv_usec;
  } else if (diff->tv_sec > 0 && diff->tv_usec < 0) {
    cmp = 1;
    diff->tv_sec -= 1;
    diff->tv_usec += 1000000;
  } else {
    assert(diff->tv_sec == 0);
    assert(diff->tv_usec == 0);
  }
  return cmp;
}


x86 assembly (clang, -O0):
<timediff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    113e <timediff+0x2e>
lea    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
sub    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
sub    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1185 <timediff+0x75>
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jne    1185 <timediff+0x75>
jmp    12ab <timediff+0x19b>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11c0 <timediff+0xb0>
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jg     11c0 <timediff+0xb0>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
imul   $0xffffffff,(%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
imul   $0xffffffff,0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
jmp    12a6 <timediff+0x196>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jl     11e7 <timediff+0xd7>
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jl     11e7 <timediff+0xd7>
movl   $0x1,-0x1c(%rbp)
jmp    12a1 <timediff+0x191>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jge    122c <timediff+0x11c>
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jle    122c <timediff+0x11c>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
sub    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
jmp    129c <timediff+0x18c>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jle    126e <timediff+0x15e>
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jge    126e <timediff+0x15e>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0xf4240,%ecx
mov    %ecx,0x4(%rax)
jmp    1297 <timediff+0x187>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x4(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    129c <timediff+0x18c>
jmp    12a1 <timediff+0x191>
jmp    12a6 <timediff+0x196>
jmp    12ab <timediff+0x19b>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timediff>:
mov    (%rsi),%ecx
sub    (%rdi),%ecx
test   %rdx,%rdx
lea    -0x4(%rsp),%r8
cmovne %rdx,%r8
lea    0x4(%rdx),%rax
mov    %ecx,(%r8)
mov    0x4(%rsi),%edx
lea    -0x8(%rsp),%rsi
cmovne %rax,%rsi
sub    0x4(%rdi),%edx
mov    %edx,(%rsi)
xor    %eax,%eax
mov    %ecx,%edi
or     %edx,%edi
je     113d <timediff+0x3d>
test   %ecx,%ecx
jle    113e <timediff+0x3e>
mov    $0x1,%eax
test   %edx,%edx
js     1162 <timediff+0x62>
ret
test   %edx,%edx
jle    1176 <timediff+0x76>
mov    $0x1,%eax
test   %ecx,%ecx
jns    113d <timediff+0x3d>
add    $0x1,%ecx
mov    %ecx,(%r8)
mov    $0xf4240,%ecx
sub    %edx,%ecx
mov    $0xffffffff,%eax
mov    %ecx,%edx
mov    %edx,(%rsi)
ret
add    $0xffffffff,%ecx
mov    %ecx,(%r8)
add    $0xf4240,%edx
mov    $0x1,%eax
mov    %edx,(%rsi)
ret
neg    %ecx
mov    %ecx,(%r8)
neg    %edx
mov    $0xffffffff,%eax
mov    %edx,(%rsi)
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @timediff(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
%7 = alloca i32
%8 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store %struct.timeval* %2, %struct.timeval** %6
store i32 0, i32* %7
%9 = load %struct.timeval*, %struct.timeval** %6
%10 = icmp eq %struct.timeval* %9, null
br i1 %10, label %11, label %12
11: ; preds = %3
store %struct.timeval* %8, %struct.timeval** %6
br label %12
12: ; preds = %11, %3
%13 = load %struct.timeval*, %struct.timeval** %5
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load %struct.timeval*, %struct.timeval** %4
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = sub nsw i32 %15, %18
%20 = load %struct.timeval*, %struct.timeval** %6
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load %struct.timeval*, %struct.timeval** %5
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%24 = load i32, i32* %23
%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 = sub nsw i32 %24, %27
%29 = load %struct.timeval*, %struct.timeval** %6
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 1
store i32 %28, i32* %30
%31 = load %struct.timeval*, %struct.timeval** %6
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %12
%36 = load %struct.timeval*, %struct.timeval** %6
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
br label %128
41: ; preds = %35, %12
%42 = load %struct.timeval*, %struct.timeval** %6
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = icmp sle i32 %44, 0
br i1 %45, label %46, label %60
46: ; preds = %41
%47 = load %struct.timeval*, %struct.timeval** %6
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %47, i32 0, i32 1
%49 = load i32, i32* %48
%50 = icmp sle i32 %49, 0
br i1 %50, label %51, label %60
51: ; preds = %46
store i32 -1, i32* %7
%52 = load %struct.timeval*, %struct.timeval** %6
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = mul nsw i32 %54, -1
store i32 %55, i32* %53
%56 = load %struct.timeval*, %struct.timeval** %6
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %56, i32 0, i32 1
%58 = load i32, i32* %57
%59 = mul nsw i32 %58, -1
store i32 %59, i32* %57
br label %127
60: ; preds = %46, %41
%61 = load %struct.timeval*, %struct.timeval** %6
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %61, i32 0, i32 0
%63 = load i32, i32* %62
%64 = icmp sge i32 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %60
%66 = load %struct.timeval*, %struct.timeval** %6
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %66, i32 0, i32 1
%68 = load i32, i32* %67
%69 = icmp sge i32 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %65
store i32 1, i32* %7
br label %126
71: ; preds = %65, %60
%72 = load %struct.timeval*, %struct.timeval** %6
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %92
76: ; preds = %71
%77 = load %struct.timeval*, %struct.timeval** %6
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %77, i32 0, i32 1
%79 = load i32, i32* %78
%80 = icmp sgt i32 %79, 0
br i1 %80, label %81, label %92
81: ; preds = %76
store i32 -1, i32* %7
%82 = load %struct.timeval*, %struct.timeval** %6
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %82, i32 0, i32 0
%84 = load i32, i32* %83
%85 = add nsw i32 %84, 1
store i32 %85, i32* %83
%86 = load %struct.timeval*, %struct.timeval** %6
%87 = getelementptr inbounds %struct.timeval, %struct.timeval* %86, i32 0, i32 1
%88 = load i32, i32* %87
%89 = sub nsw i32 1000000, %88
%90 = load %struct.timeval*, %struct.timeval** %6
%91 = getelementptr inbounds %struct.timeval, %struct.timeval* %90, i32 0, i32 1
store i32 %89, i32* %91
br label %125
92: ; preds = %76, %71
%93 = load %struct.timeval*, %struct.timeval** %6
%94 = getelementptr inbounds %struct.timeval, %struct.timeval* %93, i32 0, i32 0
%95 = load i32, i32* %94
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %111
97: ; preds = %92
%98 = load %struct.timeval*, %struct.timeval** %6
%99 = getelementptr inbounds %struct.timeval, %struct.timeval* %98, i32 0, i32 1
%100 = load i32, i32* %99
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %111
102: ; preds = %97
store i32 1, i32* %7
%103 = load %struct.timeval*, %struct.timeval** %6
%104 = getelementptr inbounds %struct.timeval, %struct.timeval* %103, i32 0, i32 0
%105 = load i32, i32* %104
%106 = sub nsw i32 %105, 1
store i32 %106, i32* %104
%107 = load %struct.timeval*, %struct.timeval** %6
%108 = getelementptr inbounds %struct.timeval, %struct.timeval* %107, i32 0, i32 1
%109 = load i32, i32* %108
%110 = add nsw i32 %109, 1000000
store i32 %110, i32* %108
br label %124
111: ; preds = %97, %92
%112 = load %struct.timeval*, %struct.timeval** %6
%113 = getelementptr inbounds %struct.timeval, %struct.timeval* %112, i32 0, i32 0
%114 = load i32, i32* %113
%115 = icmp eq i32 %114, 0
%116 = zext i1 %115 to i32
%117 = call i32 @assert(i32 %116)
%118 = load %struct.timeval*, %struct.timeval** %6
%119 = getelementptr inbounds %struct.timeval, %struct.timeval* %118, i32 0, i32 1
%120 = load i32, i32* %119
%121 = icmp eq i32 %120, 0
%122 = zext i1 %121 to i32
%123 = call i32 @assert(i32 %122)
br label %124
124: ; preds = %111, %102
br label %125
125: ; preds = %124, %81
br label %126
126: ; preds = %125, %70
br label %127
127: ; preds = %126, %51
br label %128
128: ; preds = %127, %40
%129 = load i32, i32* %7
ret i32 %129
}

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