#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  struct timeval start, end;
  double time_elapsed;
  if (gettimeofday(&start, NULL) < 0) {
    fprintf(stderr, "Err.(%s) getting time, start\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  sleep(3);
  if (gettimeofday(&end, NULL) < 0) {
    fprintf(stderr, "Err.(%s) getting time, end\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  time_elapsed = ((((end.tv_sec - start.tv_sec) * 1000000.) +
                   ((end.tv_usec - start.tv_usec))) /
                  1000000.);
  printf("Tempo trascorso: %f secondi\n", time_elapsed);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
jge    11c0 <main+0x60>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0x3,%edi
call   1080 <sleep@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
jge    121b <main+0xbb>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe1e(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%eax
sub    -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x14(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xdc9(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xdb9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xde6(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
js     11d5 <main+0x75>
mov    $0x3,%edi
call   1080 <sleep@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
js     11f5 <main+0x95>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
cvtsi2sd %eax,%xmm0
sub    0xc(%rsp),%ecx
cvtsi2sd %ecx,%xmm1
movsd  0xe52(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e04(%rip),%rax
mov    (%rax),%ebx
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe15(%rip),%rsi
jmp    1213 <main+0xb3>
mov    0x2de4(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe13(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [30 x i8] c"Err.(%s) getting time, start\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Err.(%s) getting time, end\0A\00"
@.str.2 = [29 x i8] c"Tempo trascorso: %f secondi\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca double
store i32 0, i32* %1
%5 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call i32 @sleep(i32 3)
%16 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%29 = load i32, i32* %28
%30 = sub nsw i32 %27, %29
%31 = sitofp i32 %30 to double
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%35 = load i32, i32* %34
%36 = sub nsw i32 %33, %35
%37 = sitofp i32 %36 to double
%38 = call double @llvm.fmuladd.f64(double %31, double 1.000000e+06, double %37)
%39 = fdiv double %38, 1.000000e+06
store double %39, double* %4
%40 = load double, double* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %40)
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [30 x i8] c"Err.(%s) getting time, start\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"Err.(%s) getting time, end\0A\00"
@.str.2 = [29 x i8] c"Tempo trascorso: %f secondi\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = tail call i32 @sleep(i32 3)
%16 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%29 = load i32, i32* %28
%30 = sub nsw i32 %27, %29
%31 = sitofp i32 %30 to double
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%35 = load i32, i32* %34
%36 = sub nsw i32 %33, %35
%37 = sitofp i32 %36 to double
%38 = tail call double @llvm.fmuladd.f64(double %31, double 1.000000e+06, double %37)
%39 = fdiv double %38, 1.000000e+06
%40 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %39)
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}