#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 */
int atoi(char *);
double f(double);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage: %s num_intervals.\n", argv[0]);
    return 1;
  }
  int i;
  int N = atoi(argv[1]);
  double h = 2.0 / N;
  double S = 0.0;
  for (i = 0; i < N; i++) {
    S += h * (f(h * i) + f(h * (i + 1))) / 2.0;
  }
  printf("%f\n", S);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1171 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123f <main+0x10f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xe72(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1225 <main+0xf5>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
call   1030 <f@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdf7(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <main+0x76>
movsd  -0x28(%rbp),%xmm0
lea    0xdf1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x1,%edi
jg     1157 <main+0x27>
mov    (%rsi),%rsi
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    1236 <main+0x106>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
jle    1222 <main+0xf2>
mov    %eax,%r14d
cvtsi2sd %eax,%xmm0
movsd  0xe89(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
neg    %r14d
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xe3d(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x10(%rsp),%xmm0
call   1030 <f@plt>
addsd  0x20(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0xe19(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x18(%rsp),%xmm0
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    11a0 <main+0x70>
jmp    1226 <main+0xf6>
xorpd  %xmm0,%xmm0
lea    0xe05(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [26 x i8] c"Usage: %s num_intervals.\0A\00"
@.str.1 = [4 x i8] c"%f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %32
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = sitofp i32 %10 to double
%12 = fdiv double 2.000000e+00, %11
%13 = icmp sgt i32 %10, 0
br i1 %13, label %14, label %29
14: ; preds = %7, %14
%15 = phi double [ %27, %14 ], [ 0.000000e+00, %7 ]
%16 = phi i32 [ %20, %14 ], [ 0, %7 ]
%17 = sitofp i32 %16 to double
%18 = fmul double %12, %17
%19 = tail call double @f(double %18)
%20 = add nuw nsw i32 %16, 1
%21 = sitofp i32 %20 to double
%22 = fmul double %12, %21
%23 = tail call double @f(double %22)
%24 = fadd double %19, %23
%25 = fmul double %12, %24
%26 = fmul double %25, 5.000000e-01
%27 = fadd double %15, %26
%28 = icmp eq i32 %20, %10
br i1 %28, label %29, label %14
29: ; preds = %14, %7
%30 = phi double [ 0.000000e+00, %7 ], [ %27, %14 ]
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %30)
br label %32
32: ; preds = %29, %4
%33 = phi i32 [ 1, %4 ], [ 0, %29 ]
ret i32 %33
}