#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 */
double Trap(int /*<<< orphan*/, double, double, double, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, double *, double *, int *);
int main(void) {
  int comm_sz;
  double integral;
  struct timeval start, end;
  gettimeofday(&start, NULL);
  double lb, ub;
  int trap_count;
  scanf("%lf %lf %d", &lb, &ub, &trap_count);
  integral = Trap(0, lb, ub, (ub - lb) / trap_count, trap_count);
  printf("%.5lf\n", integral);
  gettimeofday(&end, NULL);
  int duration = ((end.tv_sec * 1000000 + end.tv_usec) -
                  (start.tv_sec * 1000000 + start.tv_usec));
  printf("%d\n", duration);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    0xe9d(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1060 <scanf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x28(%rbp),%xmm2
cvtsi2sdl -0x34(%rbp),%xmm3
divsd  %xmm3,%xmm2
mov    -0x34(%rbp),%esi
xor    %edi,%edi
call   1050 <Trap@plt>
movsd  %xmm0,-0x10(%rbp)
cvttsd2si -0x10(%rbp),%esi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
imul   $0xf4240,-0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
imul   $0xf4240,-0x18(%rbp),%ecx
add    -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0xea9(%rip),%rdi
lea    0x20(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1060 <scanf@plt>
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
mov    0x4(%rsp),%esi
cvtsi2sd %esi,%xmm3
divsd  %xmm3,%xmm2
xor    %edi,%edi
call   1050 <Trap@plt>
cvttsd2si %xmm0,%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%esi
sub    0x10(%rsp),%eax
imul   $0xf4240,%eax,%eax
sub    0x14(%rsp),%esi
add    %eax,%esi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [11 x i8] c"%lf %lf %d\00"
@.str.1 = [7 x i8] c"%.5lf\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%11 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double* %6, double* %7, i32* %8)
%12 = load double, double* %6
%13 = load double, double* %7
%14 = load double, double* %7
%15 = load double, double* %6
%16 = fsub double %14, %15
%17 = load i32, i32* %8
%18 = sitofp i32 %17 to double
%19 = fdiv double %16, %18
%20 = load i32, i32* %8
%21 = call double @Trap(i32 0, double %12, double %13, double %19, i32 %20)
store double %21, double* %3
%22 = load double, double* %3
%23 = fptosi double %22 to i32
%24 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%27 = load i32, i32* %26
%28 = mul nsw i32 %27, 1000000
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%30 = load i32, i32* %29
%31 = add nsw i32 %28, %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%33 = load i32, i32* %32
%34 = mul nsw i32 %33, 1000000
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%36 = load i32, i32* %35
%37 = add nsw i32 %34, %36
%38 = sub nsw i32 %31, %37
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %39)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [11 x i8] c"%lf %lf %d\00"
@.str.1 = [7 x i8] c"%.5lf\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = bitcast %struct.timeval* %1 to i8*
%7 = bitcast %struct.timeval* %2 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%9 = bitcast double* %3 to i8*
%10 = bitcast double* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), double* %3, double* %4, i32* %5)
%13 = load double, double* %3
%14 = load double, double* %4
%15 = fsub double %14, %13
%16 = load i32, i32* %5
%17 = sitofp i32 %16 to double
%18 = fdiv double %15, %17
%19 = call double @Trap(i32 0, double %13, double %14, double %18, i32 %16)
%20 = fptosi double %19 to i32
%21 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%30 = load i32, i32* %29
%31 = sub i32 %24, %28
%32 = mul i32 %31, 1000000
%33 = sub i32 %26, %30
%34 = add i32 %33, %32
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
ret i32 0
}