#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 */
void zmDbgSubtractTime(struct timeval *const tp1, struct timeval *const tp2) {
  tp1->tv_sec -= tp2->tv_sec;
  if (tp1->tv_usec <= tp2->tv_usec) {
    tp1->tv_sec--;
    tp1->tv_usec = 1000000 - (tp2->tv_usec - tp1->tv_usec);
  } else {
    tp1->tv_usec = tp1->tv_usec - tp2->tv_usec;
  }
}


x86 assembly (clang, -O0):
<zmDbgSubtractTime>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jg     1169 <zmDbgSubtractTime+0x69>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
mov    $0xf4240,%ecx
sub    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    117e <zmDbgSubtractTime+0x7e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<zmDbgSubtractTime>:
mov    0x8(%rdi),%rdx
sub    0x8(%rsi),%rdx
mov    (%rdi),%rax
mov    %rdx,0x8(%rdi)
mov    (%rsi),%rcx
cmp    %rcx,%rax
jg     1125 <zmDbgSubtractTime+0x25>
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x8(%rdi)
add    $0xf4240,%rax
sub    %rcx,%rax
mov    %rax,(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @zmDbgSubtractTime(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%6 = load i64, i64* %5
%7 = sub nsw i64 %6, %4
store i64 %7, i64* %5
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = icmp sgt i64 %9, %11
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = add nsw i64 %7, -1
store i64 %14, i64* %5
%15 = add i64 %9, 1000000
br label %16
16: ; preds = %2, %13
%17 = phi i64 [ %15, %13 ], [ %9, %2 ]
%18 = sub i64 %17, %11
store i64 %18, i64* %8
ret void
}