#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*/);
double timer_progress(const struct timeval *restrict start, double duration) {
  struct timeval now;
  unsigned long time_difference;
  gettimeofday(&now, 0);
  time_difference = (now.tv_sec * 1000000 + now.tv_usec -
                     start->tv_sec * 1000000 - start->tv_usec);
  return time_difference / (duration * 1000000.0);
}


x86 assembly (clang, -O0):
<timer_progress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   $0xf4240,%eax,%eax
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%edx
mov    0x4(%rcx),%ecx
imul   $0xf4240,%edx,%edx
sub    %edx,%eax
sub    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
movaps 0xeb6(%rip),%xmm1
movq   -0x20(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xeb5(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe7e(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_progress>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    (%rbx),%eax
imul   $0xf4240,%eax,%eax
sub    0x4(%rbx),%ecx
add    %eax,%ecx
movslq %ecx,%rax
movq   %rax,%xmm1
punpckldq 0xeb4(%rip),%xmm1
subpd  0xebc(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0xeb2(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define double @timer_progress(%struct.timeval* noalias %0, double %1) {
%3 = alloca %struct.timeval*
%4 = alloca double
%5 = alloca %struct.timeval
%6 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
store double %1, double* %4
%7 = call i32 @gettimeofday(%struct.timeval* %5, i32 0)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%9 = load i32, i32* %8
%10 = mul nsw i32 %9, 1000000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %10, %12
%14 = load %struct.timeval*, %struct.timeval** %3
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 1000000
%18 = sub nsw i32 %13, %17
%19 = load %struct.timeval*, %struct.timeval** %3
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = sub nsw i32 %18, %21
%23 = sext i32 %22 to i64
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = uitofp i64 %24 to double
%26 = load double, double* %4
%27 = fmul double %26, 1.000000e+06
%28 = fdiv double %25, %27
ret double %28
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define double @timer_progress(%struct.timeval* noalias nocapture %0, double %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%13 = load i32, i32* %12
%14 = sub i32 %7, %11
%15 = mul i32 %14, 1000000
%16 = sub i32 %9, %13
%17 = add i32 %16, %15
%18 = sext i32 %17 to i64
%19 = uitofp i64 %18 to double
%20 = fmul double %1, 1.000000e+06
%21 = fdiv double %19, %20
ret double %21
}