#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 {
  long long tv_usec;
  int tv_sec;
};

/* Variables and functions */
int abs(long long);
int /*<<< orphan*/ printf(char *, long long);
int check_diff(struct timeval start, struct timeval end) {
  long long diff;
  diff = end.tv_usec - start.tv_usec;
  diff += (end.tv_sec - start.tv_sec) * 1000000;
  if (abs(diff - 2 * 1000000) > 1000000 / 2) {
    printf("Diff too high: %lld..", diff);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x10(%rbp),%eax
imul   $0xf4240,%eax,%eax
cltq
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
sub    $0x1e8480,%rdi
call   1030 <abs@plt>
cmp    $0x7a120,%eax
jle    118f <check_diff+0x6f>
mov    -0x30(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <check_diff+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_diff>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
sub    %rdi,%rbx
sub    %esi,%ecx
imul   $0xf4240,%ecx,%eax
movslq %eax,%r14
lea    (%rbx,%r14,1),%rdi
add    $0xffffffffffe17b80,%rdi
call   1030 <abs@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x7a121,%ecx
jl     1168 <check_diff+0x48>
add    %r14,%rbx
lea    0xea5(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
@.str = [22 x i8] c"Diff too high: %lld..\00"
define i32 @check_diff(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca i64
%9 = bitcast %struct.timeval* %6 to { i64, i32 }*
%10 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %9, i32 0, i32 0
store i64 %0, i64* %10
%11 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %9, i32 0, i32 1
store i32 %1, i32* %11
%12 = bitcast %struct.timeval* %7 to { i64, i32 }*
%13 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %12, i32 0, i32 0
store i64 %2, i64* %13
%14 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %12, i32 0, i32 1
store i32 %3, i32* %14
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%18 = load i64, i64* %17
%19 = sub nsw i64 %16, %18
store i64 %19, i64* %8
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%23 = load i32, i32* %22
%24 = sub nsw i32 %21, %23
%25 = mul nsw i32 %24, 1000000
%26 = sext i32 %25 to i64
%27 = load i64, i64* %8
%28 = add nsw i64 %27, %26
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = sub nsw i64 %29, 2000000
%31 = call i32 @abs(i64 %30)
%32 = icmp sgt i32 %31, 500000
br i1 %32, label %33, label %36
33: ; preds = %4
%34 = load i64, i64* %8
%35 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %34)
store i32 -1, i32* %5
br label %37
36: ; preds = %4
store i32 0, i32* %5
br label %37
37: ; preds = %36, %33
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@.str = [22 x i8] c"Diff too high: %lld..\00"
define i32 @check_diff(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = sub nsw i64 %2, %0
%6 = sub nsw i32 %3, %1
%7 = mul nsw i32 %6, 1000000
%8 = sext i32 %7 to i64
%9 = add nsw i64 %5, %8
%10 = add nsw i64 %9, -2000000
%11 = tail call i32 @abs(i64 %10)
%12 = icmp sgt i32 %11, 500000
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %15
15: ; preds = %4, %13
%16 = phi i32 [ -1, %13 ], [ 0, %4 ]
ret i32 %16
}