#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 */
typedef scalar_t__ time_t;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ bug(char *, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ subtract_times(struct timeval *, struct timeval *);
time_t end_timer(struct timeval *sttime) {
  struct timeval etime;
  gettimeofday(&etime, NULL);
  if (!sttime || (!sttime->tv_sec && !sttime->tv_usec)) {
    bug("%s", "End_timer: bad sttime.");
    return 0;
  }
  subtract_times(&etime, sttime);
  *sttime = etime;
  return (etime.tv_sec * 1000000) + etime.tv_usec;
}


x86 assembly (clang, -O0):
<end_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmpq   $0x0,-0x10(%rbp)
je     1170 <end_timer+0x40>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1190 <end_timer+0x60>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1190 <end_timer+0x60>
lea    0xe89(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1030 <bug@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c1 <end_timer+0x91>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1040 <subtract_times@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    %rcx,0x8(%rax)
imul   $0xf4240,-0x20(%rbp),%eax
cltq
add    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<end_timer>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rbx,%rbx
je     1177 <end_timer+0x47>
cmpl   $0x0,(%rbx)
jne    1153 <end_timer+0x23>
cmpq   $0x0,0x8(%rbx)
je     1177 <end_timer+0x47>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1040 <subtract_times@plt>
movups (%rsp),%xmm0
movups %xmm0,(%rbx)
movslq (%rsp),%rax
imul   $0xf4240,%rax,%rax
add    0x8(%rsp),%rax
jmp    118c <end_timer+0x5c>
lea    0xe82(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1030 <bug@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [23 x i8] c"End_timer: bad sttime.\00"
define i64 @end_timer(%struct.timeval* %0) {
%2 = alloca i64
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %3
%5 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%6 = load %struct.timeval*, %struct.timeval** %3
%7 = icmp ne %struct.timeval* %6, null
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load %struct.timeval*, %struct.timeval** %3
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = load %struct.timeval*, %struct.timeval** %3
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%16 = load i64, i64* %15
%17 = icmp ne i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13, %1
%19 = call i32 @bug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* %2
br label %33
20: ; preds = %13, %8
%21 = load %struct.timeval*, %struct.timeval** %3
%22 = call i32 @subtract_times(%struct.timeval* %4, %struct.timeval* %21)
%23 = load %struct.timeval*, %struct.timeval** %3
%24 = bitcast %struct.timeval* %23 to i8*
%25 = bitcast %struct.timeval* %4 to i8*
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%27 = load i32, i32* %26
%28 = mul nsw i32 %27, 1000000
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%31 = load i64, i64* %30
%32 = add nsw i64 %29, %31
store i64 %32, i64* %2
br label %33
33: ; preds = %20, %18
%34 = load i64, i64* %2
ret i64 %34
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [23 x i8] c"End_timer: bad sttime.\00"
define i64 @end_timer(%struct.timeval* %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = icmp eq %struct.timeval* %0, null
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10, %1
%15 = tail call i32 @bug(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %26
16: ; preds = %10, %6
%17 = call i32 @subtract_times(%struct.timeval* %2, %struct.timeval* %0)
%18 = bitcast %struct.timeval* %0 to i8*
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%20 = load i32, i32* %19
%21 = mul nsw i32 %20, 1000000
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%24 = load i64, i64* %23
%25 = add nsw i64 %24, %22
br label %26
26: ; preds = %16, %14
%27 = phi i64 [ %25, %16 ], [ 0, %14 ]
ret i64 %27
}