#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ print_error(char *, char *, ...);
double timeval_to_double(struct timeval *);
int /*<<< orphan*/ timeval_to_str(struct timeval *, char *);
void print_time_diff(void) {
  char datetime_buf[37];
  static double pre_time = 0.0;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  timeval_to_str(&tv, datetime_buf);
  double current_time = timeval_to_double(&tv);
  if (pre_time) {
    double time_diff = current_time - pre_time;
    print_error("[time] %s (diff %10.6lf)", datetime_buf, time_diff);
  } else {
    print_error("[time] %s", datetime_buf);
  }
  pre_time = current_time;
}


x86 assembly (clang, -O0):
<print_time_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdi
call   1060 <timeval_to_str@plt>
lea    -0x38(%rbp),%rdi
call   1050 <timeval_to_double@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  0x2ed0(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1190 <print_time_diff+0x50>
jp     1190 <print_time_diff+0x50>
jmp    11be <print_time_diff+0x7e>
movsd  -0x40(%rbp),%xmm0
subsd  0x2eab(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
lea    -0x30(%rbp),%rsi
movsd  -0x48(%rbp),%xmm0
lea    0xe4e(%rip),%rdi
mov    $0x1,%al
call   1030 <print_error@plt>
jmp    11d0 <print_time_diff+0x90>
lea    -0x30(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <print_error@plt>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,0x2e6b(%rip)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_time_diff>:
push   %rbx
sub    $0x40,%rsp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <timeval_to_str@plt>
mov    %rbx,%rdi
call   1050 <timeval_to_double@plt>
movapd %xmm0,%xmm2
movsd  0x2ed3(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movsd  %xmm2,(%rsp)
jne    1186 <print_time_diff+0x46>
jnp    11a3 <print_time_diff+0x63>
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
lea    0xe6b(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    $0x1,%al
call   1030 <print_error@plt>
jmp    11b6 <print_time_diff+0x76>
lea    0xe6f(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <print_error@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,0x2e85(%rip)
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@print_time_diff.pre_time = internal global double 0.000000e+00
@.str = [25 x i8] c"[time] %s (diff %10.6lf)\00"
@.str.1 = [10 x i8] c"[time] %s\00"
define void @print_time_diff() {
%1 = alloca [37 x i8]
%2 = alloca %struct.timeval
%3 = alloca double
%4 = alloca double
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = getelementptr inbounds [37 x i8], [37 x i8]* %1, i64 0, i64 0
%7 = call i32 @timeval_to_str(%struct.timeval* %2, i8* %6)
%8 = call double @timeval_to_double(%struct.timeval* %2)
store double %8, double* %3
%9 = load double, double* @print_time_diff.pre_time
%10 = fcmp une double %9, 0.000000e+00
br i1 %10, label %11, label %18
11: ; preds = %0
%12 = load double, double* %3
%13 = load double, double* @print_time_diff.pre_time
%14 = fsub double %12, %13
store double %14, double* %4
%15 = getelementptr inbounds [37 x i8], [37 x i8]* %1, i64 0, i64 0
%16 = load double, double* %4
%17 = call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15, double %16)
br label %21
18: ; preds = %0
%19 = getelementptr inbounds [37 x i8], [37 x i8]* %1, i64 0, i64 0
%20 = call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %11
%22 = load double, double* %3
store double %22, double* @print_time_diff.pre_time
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@print_time_diff.pre_time = internal unnamed_addr global double 0.000000e+00
@.str = [25 x i8] c"[time] %s (diff %10.6lf)\00"
@.str.1 = [10 x i8] c"[time] %s\00"
define void @print_time_diff() {
%1 = alloca [37 x i8]
%2 = alloca %struct.timeval
%3 = getelementptr inbounds [37 x i8], [37 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = call i32 @timeval_to_str(%struct.timeval* %2, i8* %3)
%7 = call double @timeval_to_double(%struct.timeval* %2)
%8 = load double, double* @print_time_diff.pre_time
%9 = fcmp une double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = fsub double %7, %8
%12 = call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %3, double %11)
br label %15
13: ; preds = %0
%14 = call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %15
15: ; preds = %13, %10
store double %7, double* @print_time_diff.pre_time
ret void
}