#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 */
int sub_time_katcp(struct timeval *delta, struct timeval *alpha,
                   struct timeval *beta) {
  if (alpha->tv_usec < beta->tv_usec) {
    if (alpha->tv_sec <= beta->tv_sec) {
      delta->tv_sec = 0;
      delta->tv_usec = 0;
      return -1;
    }
    delta->tv_sec = alpha->tv_sec - (beta->tv_sec + 1);
    delta->tv_usec = (1000000 + alpha->tv_usec) - beta->tv_usec;
  } else {
    if (alpha->tv_sec < beta->tv_sec) {
      delta->tv_sec = 0;
      delta->tv_usec = 0;
      return -1;
    }
    delta->tv_sec = alpha->tv_sec - beta->tv_sec;
    delta->tv_usec = alpha->tv_usec - beta->tv_usec;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sub_time_katcp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
jge    119d <sub_time_katcp+0x9d>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    0x8(%rcx),%rax
jg     115d <sub_time_katcp+0x5d>
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <sub_time_katcp+0x10a>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x1,%rax
sub    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    -0x20(%rbp),%rax
sub    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1203 <sub_time_katcp+0x103>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    0x8(%rcx),%rax
jge    11d6 <sub_time_katcp+0xd6>
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <sub_time_katcp+0x10a>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x20(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
sub    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<sub_time_katcp>:
mov    (%rsi),%rax
mov    0x8(%rsi),%rcx
mov    0x8(%rdx),%rsi
sub    (%rdx),%rax
jge    1127 <sub_time_katcp+0x27>
cmp    %rsi,%rcx
jle    112c <sub_time_katcp+0x2c>
not    %rsi
add    %rsi,%rcx
mov    %rcx,0x8(%rdi)
add    $0xf4240,%rax
jmp    113c <sub_time_katcp+0x3c>
sub    %rsi,%rcx
jge    1138 <sub_time_katcp+0x38>
xorps  %xmm0,%xmm0
movups %xmm0,(%rdi)
mov    $0xffffffff,%eax
ret
mov    %rcx,0x8(%rdi)
mov    %rax,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i32 @sub_time_katcp(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = alloca i32
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
%7 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %5
store %struct.timeval* %1, %struct.timeval** %6
store %struct.timeval* %2, %struct.timeval** %7
%8 = load %struct.timeval*, %struct.timeval** %6
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load %struct.timeval*, %struct.timeval** %7
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = icmp slt i64 %10, %13
br i1 %14, label %15, label %49
15: ; preds = %3
%16 = load %struct.timeval*, %struct.timeval** %6
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = load %struct.timeval*, %struct.timeval** %7
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%21 = load i64, i64* %20
%22 = icmp sle i64 %18, %21
br i1 %22, label %23, label %28
23: ; preds = %15
%24 = load %struct.timeval*, %struct.timeval** %5
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %24, i32 0, i32 1
store i64 0, i64* %25
%26 = load %struct.timeval*, %struct.timeval** %5
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %26, i32 0, i32 0
store i64 0, i64* %27
store i32 -1, i32* %4
br label %82
28: ; preds = %15
%29 = load %struct.timeval*, %struct.timeval** %6
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 1
%31 = load i64, i64* %30
%32 = load %struct.timeval*, %struct.timeval** %7
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %32, i32 0, i32 1
%34 = load i64, i64* %33
%35 = add nsw i64 %34, 1
%36 = sub nsw i64 %31, %35
%37 = load %struct.timeval*, %struct.timeval** %5
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %37, i32 0, i32 1
store i64 %36, i64* %38
%39 = load %struct.timeval*, %struct.timeval** %6
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %39, i32 0, i32 0
%41 = load i64, i64* %40
%42 = add nsw i64 1000000, %41
%43 = load %struct.timeval*, %struct.timeval** %7
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %43, i32 0, i32 0
%45 = load i64, i64* %44
%46 = sub nsw i64 %42, %45
%47 = load %struct.timeval*, %struct.timeval** %5
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %47, i32 0, i32 0
store i64 %46, i64* %48
br label %81
49: ; preds = %3
%50 = load %struct.timeval*, %struct.timeval** %6
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %50, i32 0, i32 1
%52 = load i64, i64* %51
%53 = load %struct.timeval*, %struct.timeval** %7
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %53, i32 0, i32 1
%55 = load i64, i64* %54
%56 = icmp slt i64 %52, %55
br i1 %56, label %57, label %62
57: ; preds = %49
%58 = load %struct.timeval*, %struct.timeval** %5
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %58, i32 0, i32 1
store i64 0, i64* %59
%60 = load %struct.timeval*, %struct.timeval** %5
%61 = getelementptr inbounds %struct.timeval, %struct.timeval* %60, i32 0, i32 0
store i64 0, i64* %61
store i32 -1, i32* %4
br label %82
62: ; preds = %49
%63 = load %struct.timeval*, %struct.timeval** %6
%64 = getelementptr inbounds %struct.timeval, %struct.timeval* %63, i32 0, i32 1
%65 = load i64, i64* %64
%66 = load %struct.timeval*, %struct.timeval** %7
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %66, i32 0, i32 1
%68 = load i64, i64* %67
%69 = sub nsw i64 %65, %68
%70 = load %struct.timeval*, %struct.timeval** %5
%71 = getelementptr inbounds %struct.timeval, %struct.timeval* %70, i32 0, i32 1
store i64 %69, i64* %71
%72 = load %struct.timeval*, %struct.timeval** %6
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %72, i32 0, i32 0
%74 = load i64, i64* %73
%75 = load %struct.timeval*, %struct.timeval** %7
%76 = getelementptr inbounds %struct.timeval, %struct.timeval* %75, i32 0, i32 0
%77 = load i64, i64* %76
%78 = sub nsw i64 %74, %77
%79 = load %struct.timeval*, %struct.timeval** %5
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %79, i32 0, i32 0
store i64 %78, i64* %80
br label %81
81: ; preds = %62, %28
store i32 0, i32* %4
br label %82
82: ; preds = %81, %57, %23
%83 = load i32, i32* %4
ret i32 %83
}

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