#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 */
size_t omp_get_thread_num();
int /*<<< orphan*/ printf(char *, int);
double sqrt(int);
int main() {
  int N = 4000000;
  double smi[1000];
  int i;
  for (i = 0; i < 1000; i++)
    smi[i] = 0;
#pragma omp parallel for
  for (i = 0; i < N; i++) {
    double x1 = i / ((double)N);
    double x2 = (i + 1) / ((double)N);
    double y1 = sqrt(1 - x1 * x1);
    double y2 = sqrt(1 - x2 * x2);
    smi[omp_get_thread_num()] += (x2 - x1) * (y1 + y2) * 0.5;
  }
  double sm = 0;
  for (i = 0; i < 1000; i++)
    sm += smi[i];
  printf("%.12f\n\n", sm * 4);
  for (i = 0; i < 10; i++) {
    printf("%.12f\n", 4 * smi[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3d0900,-0x8(%rbp)
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x3e8,-0x1f54(%rbp)
jge    118a <main+0x5a>
movslq -0x1f54(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f50(%rbp,%rax,8)
ff ff
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    1153 <main+0x23>
movl   $0x0,-0x1f54(%rbp)
mov    -0x1f54(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12db <main+0x1ab>
cvtsi2sdl -0x1f54(%rbp),%xmm0
ff
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x1f60(%rbp)
ff
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x1f68(%rbp)
ff
movsd  -0x1f60(%rbp),%xmm0
ff
movsd  -0x1f60(%rbp),%xmm1
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe03(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x1f70(%rbp)
ff
movsd  -0x1f68(%rbp),%xmm0
ff
movsd  -0x1f68(%rbp),%xmm1
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdbb(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x1f78(%rbp)
ff
movsd  -0x1f68(%rbp),%xmm0
ff
subsd  -0x1f60(%rbp),%xmm0
ff
movsd  -0x1f70(%rbp),%xmm1
ff
addsd  -0x1f78(%rbp),%xmm1
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x1f88(%rbp)
ff
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
movsd  -0x1f88(%rbp),%xmm0
ff
movsd  -0x1f50(%rbp,%rax,8),%xmm1
ff ff
movsd  0xd52(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x1f50(%rbp,%rax,8)
ff ff
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    1194 <main+0x64>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x1f80(%rbp)
ff
movl   $0x0,-0x1f54(%rbp)
cmpl   $0x3e8,-0x1f54(%rbp)
jge    1334 <main+0x204>
movslq -0x1f54(%rbp),%rax
movsd  -0x1f50(%rbp,%rax,8),%xmm0
ff ff
addsd  -0x1f80(%rbp),%xmm0
ff
movsd  %xmm0,-0x1f80(%rbp)
ff
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    12f0 <main+0x1c0>
movsd  0xcc4(%rip),%xmm0
mulsd  -0x1f80(%rbp),%xmm0
ff
cvttsd2si %xmm0,%esi
lea    0xcc9(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1f54(%rbp)
cmpl   $0xa,-0x1f54(%rbp)
jge    13a7 <main+0x277>
movslq -0x1f54(%rbp),%rax
movsd  0xc86(%rip),%xmm0
mulsd  -0x1f50(%rbp,%rax,8),%xmm0
ff ff
cvttsd2si %xmm0,%esi
lea    0xc92(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1f54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f54(%rbp)
jmp    135e <main+0x22e>
xor    %eax,%eax
add    $0x1f90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1f60,%rsp
lea    0x20(%rsp),%rdi
mov    $0x1f40,%edx
xor    %esi,%esi
call   1050 <memset@plt>
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movapd %xmm0,%xmm3
movsd  0xe84(%rip),%xmm1
divsd  %xmm1,%xmm3
movsd  %xmm3,0x10(%rsp)
movsd  0xe7a(%rip),%xmm2
addsd  %xmm2,%xmm0
movsd  %xmm0,0x18(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  0xe30(%rip),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1060 <sqrt@plt>
movsd  (%rsp),%xmm1
subsd  0x10(%rsp),%xmm1
addsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
movsd  0x18(%rsp),%xmm0
movsd  (%rsp),%xmm1
mulsd  0xdf7(%rip),%xmm1
addsd  0x20(%rsp,%rax,8),%xmm1
movsd  %xmm1,0x20(%rsp,%rax,8)
add    $0x1,%ebx
cmp    $0x3d0901,%ebx
jne    1170 <main+0x30>
xorpd  %xmm0,%xmm0
mov    $0x7,%eax
nopl   (%rax)
addsd  -0x18(%rsp,%rax,8),%xmm0
addsd  -0x10(%rsp,%rax,8),%xmm0
addsd  -0x8(%rsp,%rax,8),%xmm0
addsd  (%rsp,%rax,8),%xmm0
addsd  0x8(%rsp,%rax,8),%xmm0
addsd  0x10(%rsp,%rax,8),%xmm0
addsd  0x18(%rsp,%rax,8),%xmm0
addsd  0x20(%rsp,%rax,8),%xmm0
add    $0x8,%rax
cmp    $0x3ef,%rax
jne    1240 <main+0x100>
mulsd  0xd95(%rip),%xmm0
cvttsd2si %xmm0,%esi
lea    0xd92(%rip),%rdi
call   1040 <printf@plt>
movsd  0x20(%rsp),%xmm0
mulsd  0xd77(%rip),%xmm0
cvttsd2si %xmm0,%esi
lea    0xd7c(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0x28(%rsp),%xmm0
mulsd  0xd56(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0x30(%rsp),%xmm0
mulsd  0xd3c(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0x38(%rsp),%xmm0
mulsd  0xd22(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0x40(%rsp),%xmm0
mulsd  0xd08(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0x48(%rsp),%xmm0
mulsd  0xcee(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0x50(%rsp),%xmm0
mulsd  0xcd4(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0x58(%rsp),%xmm0
mulsd  0xcba(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0x60(%rsp),%xmm0
mulsd  0xca0(%rip),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movsd  0xc8c(%rip),%xmm0
mulsd  0x68(%rsp),%xmm0
cvttsd2si %xmm0,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1f60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%.12f\0A\0A\00"
@.str.1 = [7 x i8] c"%.12f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x double]
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 0, i32* %1
store i32 4000000, i32* %2
store i32 0, i32* %4
br label %10
10: ; preds = %17, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 1000
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %15
store double 0.000000e+00, double* %16
br label %17
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %10
20: ; preds = %10
store i32 0, i32* %4
br label %21
21: ; preds = %60, %20
%22 = load i32, i32* %4
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %63
25: ; preds = %21
%26 = load i32, i32* %4
%27 = sitofp i32 %26 to double
%28 = load i32, i32* %2
%29 = sitofp i32 %28 to double
%30 = fdiv double %27, %29
store double %30, double* %5
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
%33 = sitofp i32 %32 to double
%34 = load i32, i32* %2
%35 = sitofp i32 %34 to double
%36 = fdiv double %33, %35
store double %36, double* %6
%37 = load double, double* %5
%38 = load double, double* %5
%39 = fneg double %37
%40 = call double @llvm.fmuladd.f64(double %39, double %38, double 1.000000e+00)
%41 = fptosi double %40 to i32
%42 = call double @sqrt(i32 %41)
store double %42, double* %7
%43 = load double, double* %6
%44 = load double, double* %6
%45 = fneg double %43
%46 = call double @llvm.fmuladd.f64(double %45, double %44, double 1.000000e+00)
%47 = fptosi double %46 to i32
%48 = call double @sqrt(i32 %47)
store double %48, double* %8
%49 = load double, double* %6
%50 = load double, double* %5
%51 = fsub double %49, %50
%52 = load double, double* %7
%53 = load double, double* %8
%54 = fadd double %52, %53
%55 = fmul double %51, %54
%56 = call i64 (...) @omp_get_thread_num()
%57 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %56
%58 = load double, double* %57
%59 = call double @llvm.fmuladd.f64(double %55, double 5.000000e-01, double %58)
store double %59, double* %57
br label %60
60: ; preds = %25
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %21
63: ; preds = %21
store double 0.000000e+00, double* %9
store i32 0, i32* %4
br label %64
64: ; preds = %74, %63
%65 = load i32, i32* %4
%66 = icmp slt i32 %65, 1000
br i1 %66, label %67, label %77
67: ; preds = %64
%68 = load i32, i32* %4
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %69
%71 = load double, double* %70
%72 = load double, double* %9
%73 = fadd double %72, %71
store double %73, double* %9
br label %74
74: ; preds = %67
%75 = load i32, i32* %4
%76 = add nsw i32 %75, 1
store i32 %76, i32* %4
br label %64
77: ; preds = %64
%78 = load double, double* %9
%79 = fmul double %78, 4.000000e+00
%80 = fptosi double %79 to i32
%81 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %80)
store i32 0, i32* %4
br label %82
82: ; preds = %93, %77
%83 = load i32, i32* %4
%84 = icmp slt i32 %83, 10
br i1 %84, label %85, label %96
85: ; preds = %82
%86 = load i32, i32* %4
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [1000 x double], [1000 x double]* %3, i64 0, i64 %87
%89 = load double, double* %88
%90 = fmul double 4.000000e+00, %89
%91 = fptosi double %90 to i32
%92 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %91)
br label %93
93: ; preds = %85
%94 = load i32, i32* %4
%95 = add nsw i32 %94, 1
store i32 %95, i32* %4
br label %82
96: ; preds = %82
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"%.12f\0A\0A\00"
@.str.1 = [7 x i8] c"%.12f\0A\00"
define i32 @main() {
%1 = alloca [1000 x double]
%2 = bitcast [1000 x double]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ %7, %3 ], [ 0, %0 ]
%5 = sitofp i32 %4 to double
%6 = fdiv double %5, 4.000000e+06
%7 = add nuw nsw i32 %4, 1
%8 = sitofp i32 %7 to double
%9 = fdiv double %8, 4.000000e+06
%10 = fneg double %6
%11 = tail call double @llvm.fmuladd.f64(double %10, double %6, double 1.000000e+00)
%12 = fptosi double %11 to i32
%13 = tail call double @sqrt(i32 %12)
%14 = fneg double %9
%15 = tail call double @llvm.fmuladd.f64(double %14, double %9, double 1.000000e+00)
%16 = fptosi double %15 to i32
%17 = tail call double @sqrt(i32 %16)
%18 = fsub double %9, %6
%19 = fadd double %13, %17
%20 = fmul double %18, %19
%21 = tail call i64 (...) @omp_get_thread_num()
%22 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %21
%23 = load double, double* %22
%24 = tail call double @llvm.fmuladd.f64(double %20, double 5.000000e-01, double %23)
store double %24, double* %22
%25 = icmp eq i32 %7, 4000000
br i1 %25, label %26, label %3
26: ; preds = %3, %26
%27 = phi i64 [ %60, %26 ], [ 0, %3 ]
%28 = phi double [ %59, %26 ], [ 0.000000e+00, %3 ]
%29 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %27
%30 = load double, double* %29
%31 = fadd double %28, %30
%32 = or i64 %27, 1
%33 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %32
%34 = load double, double* %33
%35 = fadd double %31, %34
%36 = or i64 %27, 2
%37 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %36
%38 = load double, double* %37
%39 = fadd double %35, %38
%40 = or i64 %27, 3
%41 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %40
%42 = load double, double* %41
%43 = fadd double %39, %42
%44 = or i64 %27, 4
%45 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %44
%46 = load double, double* %45
%47 = fadd double %43, %46
%48 = or i64 %27, 5
%49 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %48
%50 = load double, double* %49
%51 = fadd double %47, %50
%52 = or i64 %27, 6
%53 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %52
%54 = load double, double* %53
%55 = fadd double %51, %54
%56 = or i64 %27, 7
%57 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 %56
%58 = load double, double* %57
%59 = fadd double %55, %58
%60 = add nuw nsw i64 %27, 8
%61 = icmp eq i64 %60, 1000
br i1 %61, label %62, label %26
62: ; preds = %26
%63 = fmul double %59, 4.000000e+00
%64 = fptosi double %63 to i32
%65 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 0
%67 = load double, double* %66
%68 = fmul double %67, 4.000000e+00
%69 = fptosi double %68 to i32
%70 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 1
%72 = load double, double* %71
%73 = fmul double %72, 4.000000e+00
%74 = fptosi double %73 to i32
%75 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %74)
%76 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 2
%77 = load double, double* %76
%78 = fmul double %77, 4.000000e+00
%79 = fptosi double %78 to i32
%80 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %79)
%81 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 3
%82 = load double, double* %81
%83 = fmul double %82, 4.000000e+00
%84 = fptosi double %83 to i32
%85 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %84)
%86 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 4
%87 = load double, double* %86
%88 = fmul double %87, 4.000000e+00
%89 = fptosi double %88 to i32
%90 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %89)
%91 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 5
%92 = load double, double* %91
%93 = fmul double %92, 4.000000e+00
%94 = fptosi double %93 to i32
%95 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %94)
%96 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 6
%97 = load double, double* %96
%98 = fmul double %97, 4.000000e+00
%99 = fptosi double %98 to i32
%100 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %99)
%101 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 7
%102 = load double, double* %101
%103 = fmul double %102, 4.000000e+00
%104 = fptosi double %103 to i32
%105 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %104)
%106 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 8
%107 = load double, double* %106
%108 = fmul double %107, 4.000000e+00
%109 = fptosi double %108 to i32
%110 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %109)
%111 = getelementptr inbounds [1000 x double], [1000 x double]* %1, i64 0, i64 9
%112 = load double, double* %111
%113 = fmul double %112, 4.000000e+00
%114 = fptosi double %113 to i32
%115 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %114)
ret i32 0
}