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

/* Variables and functions */
double atof(char *);
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, char *, double const, double const,
                          double const, ...);
double sin(double);
int /*<<< orphan*/ usage(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 5) {
    usage(argv[0], "wrong number of parameters");
  }
  struct timeval tv;
  gettimeofday(&tv, NULL);
  long t0 = 1000000L * tv.tv_sec + tv.tv_usec;
  const double A = atof(argv[1]);
  const double B = atof(argv[2]);
  const int N = atoi(argv[3]);
  if (A >= B) {
    usage(argv[0], "B must be > A");
  }
  if (N <= 0) {
    usage(argv[0], "N must be > 0");
  }
  printf("started: pid=%8d ID=%-8s A=%8.6lf B=%8.6lf N=%8d\n\n", getpid(),
         argv[4], A, B, N);
  const double delta = (B - A) / N;
  const double delta2 = delta / 2;
  double x = A;
  double result = 0.0;
  for (int i = 0; i < N; i++) {
    double contribution = 0.0;
    contribution += sin(x);
    x += delta2;
    contribution += 4 * sin(x);
    x += delta2;
    contribution += sin(x);
    contribution *= delta;
    contribution /= 6;
    result += contribution;
  }
  gettimeofday(&tv, NULL);
  long t1 = 1000000L * tv.tv_sec + tv.tv_usec;
  long delta_t = t1 - t0;
  printf("pid=%8d ID=%-8s t=%8ld A=%8.6lf B=%8.6lf N=%8d -> result=%8.6f\n\n",
         getpid(), argv[4], delta_t, A, B, N, result);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11b6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe67(%rip),%rsi
call   1080 <usage@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
imul   $0xf4240,-0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     122a <main+0xaa>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe0e(%rip),%rsi
call   1080 <usage@plt>
cmpl   $0x0,-0x3c(%rbp)
jg     1247 <main+0xc7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdff(%rip),%rsi
call   1080 <usage@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
cvtsi2sdl -0x3c(%rbp),%xmm2
lea    0xde1(%rip),%rdi
mov    $0x3,%al
call   1050 <printf@plt>
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xd66(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    137c <main+0x1fc>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1070 <sin@plt>
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1070 <sin@plt>
movsd  -0x70(%rbp),%xmm1
movsd  0xd06(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1070 <sin@plt>
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  0xcb2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12bc <main+0x13c>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
imul   $0xf4240,-0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
cvtsi2sdq -0x80(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
mov    -0x3c(%rbp),%ecx
movsd  -0x60(%rbp),%xmm3
lea    0xcad(%rip),%rdi
mov    $0x4,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
cmp    $0x5,%edi
je     11a3 <main+0x23>
mov    (%rbx),%rdi
lea    0xe82(%rip),%rsi
call   1080 <usage@plt>
lea    0x38(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x38(%rsp),%r15
mov    0x40(%rsp),%r14
mov    0x8(%rbx),%rdi
call   1030 <atof@plt>
movsd  %xmm0,0x18(%rsp)
mov    0x10(%rbx),%rdi
call   1030 <atof@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
movsd  0x18(%rsp),%xmm0
ucomisd 0x10(%rsp),%xmm0
jb     1200 <main+0x80>
mov    (%rbx),%rdi
lea    0xe40(%rip),%rsi
call   1080 <usage@plt>
test   %r12d,%r12d
jg     1214 <main+0x94>
mov    (%rbx),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <usage@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    0x20(%rbx),%rdx
cvtsi2sd %r12d,%xmm2
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  %xmm2,0x8(%rsp)
mov    $0x3,%al
call   1050 <printf@plt>
xorpd  %xmm1,%xmm1
test   %r12d,%r12d
jle    1318 <main+0x198>
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm0
subsd  %xmm0,%xmm1
divsd  0x8(%rsp),%xmm1
movsd  0xd8f(%rip),%xmm2
movsd  %xmm1,0x48(%rsp)
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x30(%rsp)
mov    %r12d,%ebp
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm1,%xmm1
xchg   %ax,%ax
movsd  %xmm1,0x28(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <sin@plt>
addsd  0xd6f(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1070 <sin@plt>
mulsd  0xd3a(%rip),%xmm0
addsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1070 <sin@plt>
movsd  0x28(%rsp),%xmm1
addsd  0x20(%rsp),%xmm0
mulsd  0x48(%rsp),%xmm0
divsd  0xd05(%rip),%xmm0
addsd  %xmm0,%xmm1
add    $0xffffffff,%ebp
jne    1290 <main+0x110>
movsd  %xmm1,0x28(%rsp)
lea    0x38(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x38(%rsp),%rax
sub    %r15,%rax
mov    0x40(%rsp),%rcx
sub    %r14,%rcx
imul   $0xf4240,%rax,%rbp
add    %rcx,%rbp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    0x20(%rbx),%rdx
xorps  %xmm0,%xmm0
cvtsi2sd %rbp,%xmm0
lea    0xd2c(%rip),%rdi
mov    %eax,%esi
movsd  0x18(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
mov    %r12d,%ecx
movsd  0x28(%rsp),%xmm3
mov    $0x4,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [27 x i8] c"wrong number of parameters\00"
@.str.1 = [14 x i8] c"B must be > A\00"
@.str.2 = [14 x i8] c"N must be > 0\00"
@.str.3 = [51 x i8] c"started: pid=%8d ID=%-8s A=%8.6lf B=%8.6lf N=%8d\0A\0A\00"
@.str.4 = [65 x i8] c"pid=%8d ID=%-8s t=%8ld A=%8.6lf B=%8.6lf N=%8d -> result=%8.6f\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca i64
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca i32
%16 = alloca double
%17 = alloca i64
%18 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 5
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @usage(i8* %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %21, %2
%27 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%29 = load i64, i64* %28
%30 = mul nsw i64 1000000, %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%32 = load i64, i64* %31
%33 = add nsw i64 %30, %32
store i64 %33, i64* %7
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call double @atof(i8* %36)
store double %37, double* %8
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call double @atof(i8* %40)
store double %41, double* %9
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
store i32 %45, i32* %10
%46 = load double, double* %8
%47 = load double, double* %9
%48 = fcmp oge double %46, %47
br i1 %48, label %49, label %54
49: ; preds = %26
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @usage(i8* %52, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %54
54: ; preds = %49, %26
%55 = load i32, i32* %10
%56 = icmp sle i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 0
%60 = load i8*, i8** %59
%61 = call i32 @usage(i8* %60, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %62
62: ; preds = %57, %54
%63 = call i32 (...) @getpid()
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 4
%66 = load i8*, i8** %65
%67 = load double, double* %8
%68 = load double, double* %9
%69 = load i32, i32* %10
%70 = sitofp i32 %69 to double
%71 = call i32 (i8*, i32, i8*, double, double, double, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %63, i8* %66, double %67, double %68, double %70)
%72 = load double, double* %9
%73 = load double, double* %8
%74 = fsub double %72, %73
%75 = load i32, i32* %10
%76 = sitofp i32 %75 to double
%77 = fdiv double %74, %76
store double %77, double* %11
%78 = load double, double* %11
%79 = fdiv double %78, 2.000000e+00
store double %79, double* %12
%80 = load double, double* %8
store double %80, double* %13
store double 0.000000e+00, double* %14
store i32 0, i32* %15
br label %81
81: ; preds = %112, %62
%82 = load i32, i32* %15
%83 = load i32, i32* %10
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %115
85: ; preds = %81
store double 0.000000e+00, double* %16
%86 = load double, double* %13
%87 = call double @sin(double %86)
%88 = load double, double* %16
%89 = fadd double %88, %87
store double %89, double* %16
%90 = load double, double* %12
%91 = load double, double* %13
%92 = fadd double %91, %90
store double %92, double* %13
%93 = load double, double* %13
%94 = call double @sin(double %93)
%95 = load double, double* %16
%96 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %94, double %95)
store double %96, double* %16
%97 = load double, double* %12
%98 = load double, double* %13
%99 = fadd double %98, %97
store double %99, double* %13
%100 = load double, double* %13
%101 = call double @sin(double %100)
%102 = load double, double* %16
%103 = fadd double %102, %101
store double %103, double* %16
%104 = load double, double* %11
%105 = load double, double* %16
%106 = fmul double %105, %104
store double %106, double* %16
%107 = load double, double* %16
%108 = fdiv double %107, 6.000000e+00
store double %108, double* %16
%109 = load double, double* %16
%110 = load double, double* %14
%111 = fadd double %110, %109
store double %111, double* %14
br label %112
112: ; preds = %85
%113 = load i32, i32* %15
%114 = add nsw i32 %113, 1
store i32 %114, i32* %15
br label %81
115: ; preds = %81
%116 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%117 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%118 = load i64, i64* %117
%119 = mul nsw i64 1000000, %118
%120 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%121 = load i64, i64* %120
%122 = add nsw i64 %119, %121
store i64 %122, i64* %17
%123 = load i64, i64* %17
%124 = load i64, i64* %7
%125 = sub nsw i64 %123, %124
store i64 %125, i64* %18
%126 = call i32 (...) @getpid()
%127 = load i8**, i8*** %5
%128 = getelementptr inbounds i8*, i8** %127, i64 4
%129 = load i8*, i8** %128
%130 = load i64, i64* %18
%131 = sitofp i64 %130 to double
%132 = load double, double* %8
%133 = load double, double* %9
%134 = load i32, i32* %10
%135 = load double, double* %14
%136 = call i32 (i8*, i32, i8*, double, double, double, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %126, i8* %129, double %131, double %132, double %133, i32 %134, double %135)
%137 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [27 x i8] c"wrong number of parameters\00"
@.str.1 = [14 x i8] c"B must be > A\00"
@.str.2 = [14 x i8] c"N must be > 0\00"
@.str.3 = [51 x i8] c"started: pid=%8d ID=%-8s A=%8.6lf B=%8.6lf N=%8d\0A\0A\00"
@.str.4 = [65 x i8] c"pid=%8d ID=%-8s t=%8ld A=%8.6lf B=%8.6lf N=%8d -> result=%8.6f\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = icmp eq i32 %0, 5
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @usage(i8* %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %5, %2
%9 = bitcast %struct.timeval* %3 to i8*
%10 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%14 = load i64, i64* %13
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call double @atof(i8* %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call double @atof(i8* %19)
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = fcmp ult double %17, %20
br i1 %24, label %28, label %25
25: ; preds = %8
%26 = load i8*, i8** %1
%27 = tail call i32 @usage(i8* %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %8
%29 = icmp slt i32 %23, 1
br i1 %29, label %30, label %33
30: ; preds = %28
%31 = load i8*, i8** %1
%32 = tail call i32 @usage(i8* %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %30, %28
%34 = tail call i32 (...) @getpid()
%35 = getelementptr inbounds i8*, i8** %1, i64 4
%36 = load i8*, i8** %35
%37 = sitofp i32 %23 to double
%38 = tail call i32 (i8*, i32, i8*, double, double, double, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %34, i8* %36, double %17, double %20, double %37)
%39 = fsub double %20, %17
%40 = fdiv double %39, %37
%41 = fmul double %40, 5.000000e-01
%42 = icmp sgt i32 %23, 0
br i1 %42, label %57, label %43
43: ; preds = %57, %33
%44 = phi double [ 0.000000e+00, %33 ], [ %71, %57 ]
%45 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%46 = load i64, i64* %11
%47 = load i64, i64* %13
%48 = sub i64 %46, %12
%49 = mul i64 %48, 1000000
%50 = sub i64 %47, %14
%51 = add i64 %50, %49
%52 = tail call i32 (...) @getpid()
%53 = load i8*, i8** %35
%54 = sitofp i64 %51 to double
%55 = tail call i32 (i8*, i32, i8*, double, double, double, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %52, i8* %53, double %54, double %17, double %20, i32 %23, double %44)
%56 = tail call i32 @exit(i32 0)
unreachable
57: ; preds = %33, %57
%58 = phi double [ %66, %57 ], [ %17, %33 ]
%59 = phi double [ %71, %57 ], [ 0.000000e+00, %33 ]
%60 = phi i32 [ %72, %57 ], [ 0, %33 ]
%61 = tail call double @sin(double %58)
%62 = fadd double %61, 0.000000e+00
%63 = fadd double %41, %58
%64 = tail call double @sin(double %63)
%65 = tail call double @llvm.fmuladd.f64(double %64, double 4.000000e+00, double %62)
%66 = fadd double %41, %63
%67 = tail call double @sin(double %66)
%68 = fadd double %65, %67
%69 = fmul double %40, %68
%70 = fdiv double %69, 6.000000e+00
%71 = fadd double %59, %70
%72 = add nuw nsw i32 %60, 1
%73 = icmp eq i32 %72, %23
br i1 %73, label %43, label %57
}