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

/* Variables and functions */
long gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void dtimer(double *time, struct timeval *itime, int icntrl) {
  long oss, usec;
  const double tick = 1.0 / 1000000.0;
  struct timeval jclock, nclock;
  if (!(icntrl))
    return;
  if (icntrl == 1)
    goto L10;
  oss = gettimeofday(&jclock, NULL);
  *itime = jclock;
  return;
L10:
  oss = gettimeofday(&nclock, NULL);
  jclock = *itime;
  usec = nclock.tv_usec - jclock.tv_usec;
  *time = (nclock.tv_sec - jclock.tv_sec) + usec * tick;
  return;
}


x86 assembly (clang, -O0):
<dtimer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  0xed5(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    113f <dtimer+0x2f>
jmp    11d2 <dtimer+0xc2>
cmpl   $0x1,-0x14(%rbp)
jne    114e <dtimer+0x3e>
jmp    1177 <dtimer+0x67>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    %rcx,0x8(%rax)
jmp    11d2 <dtimer+0xc2>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x40(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x48(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm1
cvtsi2sdq -0x28(%rbp),%xmm0
movsd  0xe3e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dtimer>:
push   %r14
push   %rbx
sub    $0x28,%rsp
test   %edx,%edx
je     117f <dtimer+0x6f>
mov    %rsi,%rbx
cmp    $0x1,%edx
jne    116c <dtimer+0x5c>
mov    %rdi,%r14
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movups (%rbx),%xmm0
movaps %xmm0,(%rsp)
mov    0x18(%rsp),%rax
mov    0x20(%rsp),%rcx
sub    (%rsp),%rax
sub    0x8(%rsp),%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
cvtsi2sd %rax,%xmm1
mulsd  0xe9f(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
jmp    117f <dtimer+0x6f>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movapd (%rsp),%xmm0
movupd %xmm0,(%rbx)
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @dtimer(double* nocapture writeonly %0, %struct.timeval* nocapture %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %4 to i8*
%7 = bitcast %struct.timeval* %5 to i8*
switch i32 %2, label %8 [
i32 0, label %27
i32 1, label %11
]
8: ; preds = %3
%9 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%10 = bitcast %struct.timeval* %1 to i8*
br label %27
11: ; preds = %3
%12 = call i64 @gettimeofday(%struct.timeval* %5, i32* null)
%13 = bitcast %struct.timeval* %1 to i8*
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%17 = load i64, i64* %16
%18 = sub nsw i64 %15, %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%20 = load i64, i64* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%22 = load i64, i64* %21
%23 = sub nsw i64 %20, %22
%24 = sitofp i64 %23 to double
%25 = sitofp i64 %18 to double
%26 = tail call double @llvm.fmuladd.f64(double %25, double 0x3EB0C6F7A0B5ED8D, double %24)
store double %26, double* %0
br label %27
27: ; preds = %3, %11, %8
ret void
}