#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 sin(double);
double nthIntegral(double dt, int n) {
  double integral = 0;
  int i;
  for (i = 0; i < n; i++) {
    double t = (double)i / dt;
    double s = sin(t);
    integral = integral + s * dt;
  }
  return integral;
}


x86 assembly (clang, -O0):
<nthIntegral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1183 <nthIntegral+0x73>
cvtsi2sdl -0x1c(%rbp),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112f <nthIntegral+0x1f>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nthIntegral>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %edi,%edi
jle    1145 <nthIntegral+0x35>
mov    %edi,%r14d
movapd %xmm0,%xmm1
cmp    $0x1,%edi
movsd  %xmm0,0x10(%rsp)
jne    114e <nthIntegral+0x3e>
xorpd  %xmm2,%xmm2
xorpd  %xmm0,%xmm0
test   $0x1,%r14b
je     11d8 <nthIntegral+0xc8>
jmp    11de <nthIntegral+0xce>
xorpd  %xmm2,%xmm2
jmp    11d8 <nthIntegral+0xc8>
mov    %r14d,%ebp
and    $0xfffffffe,%ebp
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
xorpd  %xmm0,%xmm0
xchg   %ax,%ax
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
movsd  0x18(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x10(%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x10(%rsp),%xmm1
movapd %xmm0,%xmm2
movsd  0x18(%rsp),%xmm0
mulsd  %xmm1,%xmm2
addsd  0x8(%rsp),%xmm2
addsd  0xe3c(%rip),%xmm0
add    $0x2,%ebx
cmp    %ebx,%ebp
jne    1160 <nthIntegral+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
test   $0x1,%r14b
jne    11de <nthIntegral+0xce>
movapd %xmm2,%xmm0
jmp    11f9 <nthIntegral+0xe9>
divsd  %xmm1,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1030 <sin@plt>
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @nthIntegral(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %9
9: ; preds = %24, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i32, i32* %6
%15 = sitofp i32 %14 to double
%16 = load double, double* %3
%17 = fdiv double %15, %16
store double %17, double* %7
%18 = load double, double* %7
%19 = call double @sin(double %18)
store double %19, double* %8
%20 = load double, double* %5
%21 = load double, double* %8
%22 = load double, double* %3
%23 = call double @llvm.fmuladd.f64(double %21, double %22, double %20)
store double %23, double* %5
br label %24
24: ; preds = %13
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %9
27: ; preds = %9
%28 = load double, double* %5
ret double %28
}

LLVM IR (-O2):
define double @nthIntegral(double %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %36
4: ; preds = %2
%5 = and i32 %1, 1
%6 = icmp eq i32 %1, 1
br i1 %6, label %27, label %7
7: ; preds = %4
%8 = and i32 %1, -2
br label %9
9: ; preds = %9, %7
%10 = phi double [ 0.000000e+00, %7 ], [ %21, %9 ]
%11 = phi i32 [ 0, %7 ], [ %22, %9 ]
%12 = phi i32 [ 0, %7 ], [ %23, %9 ]
%13 = sitofp i32 %11 to double
%14 = fdiv double %13, %0
%15 = tail call double @sin(double %14)
%16 = tail call double @llvm.fmuladd.f64(double %15, double %0, double %10)
%17 = or i32 %11, 1
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, %0
%20 = tail call double @sin(double %19)
%21 = tail call double @llvm.fmuladd.f64(double %20, double %0, double %16)
%22 = add nuw nsw i32 %11, 2
%23 = add i32 %12, 2
%24 = icmp eq i32 %23, %8
br i1 %24, label %25, label %9
25: ; preds = %9
%26 = sitofp i32 %22 to double
br label %27
27: ; preds = %25, %4
%28 = phi double [ undef, %4 ], [ %21, %25 ]
%29 = phi double [ 0.000000e+00, %4 ], [ %21, %25 ]
%30 = phi double [ 0.000000e+00, %4 ], [ %26, %25 ]
%31 = icmp eq i32 %5, 0
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = fdiv double %30, %0
%34 = tail call double @sin(double %33)
%35 = tail call double @llvm.fmuladd.f64(double %34, double %0, double %29)
br label %36
36: ; preds = %32, %27, %2
%37 = phi double [ 0.000000e+00, %2 ], [ %28, %27 ], [ %35, %32 ]
ret double %37
}