#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 {
  double tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
int /*<<< orphan*/ usleep(int);
int main() {
  struct timeval t_start, t_end, dt;
  gettimeofday(&t_start, NULL);
  double dt_time;
  while (1) {
    gettimeofday(&t_end, NULL);
    timersub(&t_end, &t_start, &dt);
    dt_time = dt.tv_sec + ((double)dt.tv_usec / 1000000);
    printf("%f\n", dt_time);
    gettimeofday(&t_start, NULL);
    usleep(2000);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <timersub@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
movsd  0xe73(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  %xmm1,-0x50(%rbp)
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    $0x7d0,%edi
call   1060 <usleep@plt>
jmp    115c <main+0x1c>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0x28(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x18(%rsp),%rbx
lea    0x8(%rsp),%r15
lea    0xe9d(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <timersub@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x10(%rsp),%xmm0
divsd  0xe66(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
mov    %r12,%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x7d0,%edi
call   1060 <usleep@plt>
jmp    1170 <main+0x30>

LLVM IR (-O0):
%struct.timeval = type { double, i64 }
@.str = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca double
store i32 0, i32* %1
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %7
7: ; preds = %0, %7
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%9 = call i32 @timersub(%struct.timeval* %3, %struct.timeval* %2, %struct.timeval* %4)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%11 = load double, double* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = fdiv double %14, 1.000000e+06
%16 = fadd double %11, %15
store double %16, double* %5
%17 = load double, double* %5
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %17)
%19 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%20 = call i32 @usleep(i32 2000)
br label %7
}

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
@.str = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
br label %10
10: ; preds = %10, %0
%11 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%12 = call i32 @timersub(%struct.timeval* %2, %struct.timeval* %1, %struct.timeval* %3)
%13 = load double, double* %8
%14 = load i64, i64* %9
%15 = sitofp i64 %14 to double
%16 = fdiv double %15, 1.000000e+06
%17 = fadd double %13, %16
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %17)
%19 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%20 = call i32 @usleep(i32 2000)
br label %10
}