#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 + 0.5 * sin(a);
  for (i = 1; i < n - 1; i++) {
    I = I + sin(a + i * h);
  }
  I = I + 0.5 * sin(b);
  I = I * h;
  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>
movsd  -0x38(%rbp),%xmm1
movsd  0xe71(%rip),%xmm2
mulsd  %xmm2,%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    11f9 <main+0xd9>
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>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a3 <main+0x83>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <sin@plt>
movsd  -0x48(%rbp),%xmm1
movsd  0xde6(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xdc6(%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>
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  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
addsd  0xe55(%rip),%xmm1
add    $0x2,%ebx
cmp    $0x64,%ebx
jne    1160 <main+0x40>
movsd  0x18(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0xe42(%rip),%xmm0
addsd  (%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
lea    0xe40(%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 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %17, double %15)
store double %18, double* %6
store i32 1, i32* %7
br label %19
19: ; preds = %33, %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 %36
24: ; preds = %19
%25 = load double, double* %6
%26 = load double, double* %3
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to double
%29 = load double, double* %5
%30 = call double @llvm.fmuladd.f64(double %28, double %29, double %26)
%31 = call double @sin(double %30)
%32 = fadd double %25, %31
store double %32, double* %6
br label %33
33: ; preds = %24
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %19
36: ; preds = %19
%37 = load double, double* %6
%38 = load double, double* %4
%39 = call double @sin(double %38)
%40 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %39, double %37)
store double %40, double* %6
%41 = load double, double* %6
%42 = load double, double* %5
%43 = fmul double %41, %42
store double %43, double* %6
%44 = load double, double* %6
%45 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %44)
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 = fadd double %5, %8
%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 = fadd double %9, %13
%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 = tail call double @llvm.fmuladd.f64(double %18, double 5.000000e-01, double %14)
%20 = fmul double %2, %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), double %20)
ret i32 0
}