#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*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
long int mumu_timing() {
  static int started = 0;
  static struct timeval oldtime;
  struct timeval tv;
  long delta;
  gettimeofday(&tv, NULL);
  if (started) {
    delta =
        (tv.tv_sec - oldtime.tv_sec) * 1000000 + (tv.tv_usec - oldtime.tv_usec);
  } else {
    delta = 0;
    started = 1;
  }
  oldtime = tv;
  return delta;
}


x86 assembly (clang, -O0):
<mumu_timing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmpl   $0x0,0x2f00(%rip)
je     1157 <mumu_timing+0x47>
mov    -0x8(%rbp),%eax
sub    0x2ef5(%rip),%eax
imul   $0xf4240,%eax,%eax
mov    -0x4(%rbp),%ecx
sub    0x2eea(%rip),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x10(%rbp)
jmp    1169 <mumu_timing+0x59>
movq   $0x0,-0x10(%rbp)
movl   $0x1,0x2ec3(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,0x2ebc(%rip)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mumu_timing>:
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmpb   $0x1,0x2f0e(%rip)
jne    1144 <mumu_timing+0x34>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x2f07(%rip),%eax
imul   $0xf4240,%eax,%eax
sub    0x2eff(%rip),%ecx
add    %eax,%ecx
movslq %ecx,%rax
jmp    114d <mumu_timing+0x3d>
movb   $0x1,0x2ee5(%rip)
xor    %eax,%eax
mov    (%rsp),%rcx
mov    %rcx,0x2ee0(%rip)
pop    %rcx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@mumu_timing.started = internal global i32 0
@mumu_timing.oldtime = internal global %struct.timeval zeroinitializer
define i64 @mumu_timing() {
%1 = alloca %struct.timeval
%2 = alloca i64
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = load i32, i32* @mumu_timing.started
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @mumu_timing.oldtime, i32 0, i32 0)
%10 = sub nsw i32 %8, %9
%11 = mul nsw i32 %10, 1000000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%13 = load i32, i32* %12
%14 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @mumu_timing.oldtime, i32 0, i32 1)
%15 = sub nsw i32 %13, %14
%16 = add nsw i32 %11, %15
%17 = sext i32 %16 to i64
store i64 %17, i64* %2
br label %19
18: ; preds = %0
store i64 0, i64* %2
store i32 1, i32* @mumu_timing.started
br label %19
19: ; preds = %18, %6
%20 = bitcast %struct.timeval* %1 to i8*
%21 = load i64, i64* %2
ret i64 %21
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@mumu_timing.started = internal unnamed_addr global i1 false
@mumu_timing.oldtime = internal unnamed_addr global %struct.timeval zeroinitializer
define i64 @mumu_timing() {
%1 = alloca i64
%2 = bitcast i64* %1 to %struct.timeval*
%3 = bitcast i64* %1 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = load i1, i1* @mumu_timing.started
br i1 %5, label %6, label %18
6: ; preds = %0
%7 = bitcast i64* %1 to i32*
%8 = load i32, i32* %7
%9 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @mumu_timing.oldtime, i64 0, i32 0)
%10 = sub nsw i32 %8, %9
%11 = mul nsw i32 %10, 1000000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%13 = load i32, i32* %12
%14 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @mumu_timing.oldtime, i64 0, i32 1)
%15 = sub i32 %13, %14
%16 = add nsw i32 %15, %11
%17 = sext i32 %16 to i64
br label %19
18: ; preds = %0
store i1 true, i1* @mumu_timing.started
br label %19
19: ; preds = %18, %6
%20 = phi i64 [ %17, %6 ], [ 0, %18 ]
%21 = load i64, i64* %1
store i64 %21, i64* bitcast (%struct.timeval* @mumu_timing.oldtime to i64*)
ret i64 %20
}