#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 */

/* Variables and functions */
double M_PI;
int /*<<< orphan*/ printf(char *, double);
double sin(double);
int main() {
  int n = 100;
  double a = 0.0, b = M_PI;
  double h = (b - a) / n;
  double I = 0;
  int i;
  I = I + sin(a);
  for (i = 1; i < n - 1; i++) {
    if (i % 2 == 0) {
      I = I + 2 * sin(a + i * h);
    } else {
      I = I + 4 * sin(a + i * h);
    }
  }
  I = I + sin(b);
  I = I * h / 3;
  printf("Integration is: %lf \n", I);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2ea3(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    124f <main+0x12f>
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11fc <main+0xdc>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  -0x40(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    123c <main+0x11c>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sin@plt>
movsd  -0x48(%rbp),%xmm1
movsd  0xdd9(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1241 <main+0x121>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119a <main+0x7a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  0xd7a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xd75(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2ebc(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x18(%rsp)
divsd  0xec2(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xebc(%rip),%xmm1
mov    $0x2,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
call   1040 <sin@plt>
mulsd  0xe89(%rip),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0xe82(%rip),%xmm0
call   1040 <sin@plt>
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
addsd  0xe51(%rip),%xmm1
add    $0x2,%ebx
cmp    $0x64,%ebx
jne    1160 <main+0x40>
movsd  0x18(%rsp),%xmm0
call   1040 <sin@plt>
addsd  (%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
divsd  0xe33(%rip),%xmm0
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@.str = [22 x i8] c"Integration is: %lf \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %2
store double 0.000000e+00, double* %3
%8 = load double, double* @M_PI
store double %8, double* %4
%9 = load double, double* %4
%10 = load double, double* %3
%11 = fsub double %9, %10
%12 = load i32, i32* %2
%13 = sitofp i32 %12 to double
%14 = fdiv double %11, %13
store double %14, double* %5
store double 0.000000e+00, double* %6
%15 = load double, double* %6
%16 = load double, double* %3
%17 = call double @sin(double %16)
%18 = fadd double %15, %17
store double %18, double* %6
store i32 1, i32* %7
br label %19
19: ; preds = %47, %0
%20 = load i32, i32* %7
%21 = load i32, i32* %2
%22 = sub nsw i32 %21, 1
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %50
24: ; preds = %19
%25 = load i32, i32* %7
%26 = srem i32 %25, 2
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load double, double* %6
%30 = load double, double* %3
%31 = load i32, i32* %7
%32 = sitofp i32 %31 to double
%33 = load double, double* %5
%34 = call double @llvm.fmuladd.f64(double %32, double %33, double %30)
%35 = call double @sin(double %34)
%36 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %35, double %29)
store double %36, double* %6
br label %46
37: ; preds = %24
%38 = load double, double* %6
%39 = load double, double* %3
%40 = load i32, i32* %7
%41 = sitofp i32 %40 to double
%42 = load double, double* %5
%43 = call double @llvm.fmuladd.f64(double %41, double %42, double %39)
%44 = call double @sin(double %43)
%45 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %44, double %38)
store double %45, double* %6
br label %46
46: ; preds = %37, %28
br label %47
47: ; preds = %46
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %19
50: ; preds = %19
%51 = load double, double* %6
%52 = load double, double* %4
%53 = call double @sin(double %52)
%54 = fadd double %51, %53
store double %54, double* %6
%55 = load double, double* %6
%56 = load double, double* %5
%57 = fmul double %55, %56
%58 = fdiv double %57, 3.000000e+00
store double %58, double* %6
%59 = load double, double* %6
%60 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %59)
ret i32 0
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@.str = [22 x i8] c"Integration is: %lf \0A\00"
define i32 @main() {
%1 = load double, double* @M_PI
%2 = fdiv double %1, 1.000000e+02
br label %3
3: ; preds = %3, %0
%4 = phi i32 [ 1, %0 ], [ %15, %3 ]
%5 = phi double [ 0.000000e+00, %0 ], [ %14, %3 ]
%6 = sitofp i32 %4 to double
%7 = tail call double @llvm.fmuladd.f64(double %6, double %2, double 0.000000e+00)
%8 = tail call double @sin(double %7)
%9 = tail call double @llvm.fmuladd.f64(double %8, double 4.000000e+00, double %5)
%10 = add nuw nsw i32 %4, 1
%11 = sitofp i32 %10 to double
%12 = tail call double @llvm.fmuladd.f64(double %11, double %2, double 0.000000e+00)
%13 = tail call double @sin(double %12)
%14 = tail call double @llvm.fmuladd.f64(double %13, double 2.000000e+00, double %9)
%15 = add nuw nsw i32 %4, 2
%16 = icmp eq i32 %15, 99
br i1 %16, label %17, label %3
17: ; preds = %3
%18 = tail call double @sin(double %1)
%19 = fadd double %14, %18
%20 = fmul double %2, %19
%21 = fdiv double %20, 3.000000e+00
%22 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %21)
ret i32 0
}