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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ usleep(int);
int main(void) {
  struct timeval tv;
  double t1;
  double t2;
  gettimeofday(&tv, NULL);
  t1 = tv.tv_sec + tv.tv_usec / 1000000.0;
  sleep(1);
  usleep(50);
  gettimeofday(&tv, NULL);
  t2 = tv.tv_sec + tv.tv_usec / 1000000.0;
  printf("%.6lf seconds elapsed.\n", t2 - t1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe92(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    $0x32,%edi
call   1060 <usleep@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe52(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  (%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    $0x32,%edi
call   1060 <usleep@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movapd (%rsp),%xmm0
movapd %xmm0,%xmm1
shufpd $0x1,0x10(%rsp),%xmm1
divpd  0xe63(%rip),%xmm1
unpcklpd 0x20(%rsp),%xmm0
addpd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
subsd  %xmm1,%xmm0
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [24 x i8] c"%.6lf seconds elapsed.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca double
%4 = alloca double
store i32 0, i32* %1
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%7 = load double, double* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%9 = load double, double* %8
%10 = fdiv double %9, 1.000000e+06
%11 = fadd double %7, %10
store double %11, double* %3
%12 = call i32 @sleep(i32 1)
%13 = call i32 @usleep(i32 50)
%14 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%16 = load double, double* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%18 = load double, double* %17
%19 = fdiv double %18, 1.000000e+06
%20 = fadd double %16, %19
store double %20, double* %4
%21 = load double, double* %4
%22 = load double, double* %3
%23 = fsub double %21, %22
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %23)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [24 x i8] c"%.6lf seconds elapsed.\0A\00"
define i32 @main() {
%1 = alloca <2 x double>
%2 = bitcast <2 x double>* %1 to %struct.timeval*
%3 = bitcast <2 x double>* %1 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds <2 x double>, <2 x double>* %1, i64 0, i64 0
%6 = load double, double* %5
%7 = getelementptr inbounds <2 x double>, <2 x double>* %1, i64 0, i64 1
%8 = load double, double* %7
%9 = tail call i32 @sleep(i32 1)
%10 = tail call i32 @usleep(i32 50)
%11 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%12 = load <2 x double>, <2 x double>* %1
%13 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%14 = insertelement <2 x double> %13, double %8, i64 1
%15 = fdiv <2 x double> %14, <double 1.000000e+06, double 1.000000e+06>
%16 = insertelement <2 x double> %12, double %6, i64 1
%17 = fadd <2 x double> %16, %15
%18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%19 = fsub <2 x double> %17, %18
%20 = extractelement <2 x double> %19, i64 0
%21 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %20)
ret i32 0
}