#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 /*<<< orphan*/ acc_device_nvidia;
int acc_get_num_devices(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double);
int main(void) {
  double pi = 0.0f;
  long long i;
  int change = 0;
  printf("Number of devices: %d\n", acc_get_num_devices(acc_device_nvidia));
#pragma acc parallel
  {
    change = 1;
#pragma acc loop reduction(+ : pi) private(i)
    for (i = 0; i < 20000; i++) {
      double t = (double)((i + 0.5) / 20000);
      pi += 4.0 / (1.0 + t * t);
    }
  }
  printf("Change: %d\n", change);
  printf("pi=%11.10f\n", pi / 20000);
  pi = 0.0;
  for (i = 0; i < 20000; i++) {
    double t = (double)((i + 0.5) / 20000);
    pi += 4.0 / (1.0 + t * t);
  }
  printf("pi=%11.10f\n", pi / 20000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
call   1040 <acc_get_num_devices@plt>
cvtsi2sd %eax,%xmm0
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x4e20,-0x18(%rbp)
jge    11dd <main+0xbd>
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe6d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe5e(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe4a(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116b <main+0x4b>
cvtsi2sdl -0x1c(%rbp),%xmm0
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe05(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x4e20,-0x18(%rbp)
jge    128d <main+0x16d>
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  0xde1(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xdbd(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xdae(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xd9a(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    121b <main+0xfb>
movsd  -0x10(%rbp),%xmm0
movsd  0xd66(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd9e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2eb8(%rip),%rax
mov    (%rax),%edi
call   1040 <acc_get_num_devices@plt>
cvtsi2sd %eax,%xmm0
lea    0xee6(%rip),%rdi
call   1030 <printf@plt>
xorpd  %xmm4,%xmm4
xor    %eax,%eax
movsd  0xec3(%rip),%xmm0
movsd  0xec3(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
addsd  0xe90(%rip),%xmm2
divsd  0xe90(%rip),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm3,%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm4
add    $0x1,%rax
cmp    $0x4e20,%rax
jne    1160 <main+0x40>
lea    0xe98(%rip),%rdi
movsd  %xmm4,(%rsp)
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
divsd  0xe52(%rip),%xmm0
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe4e(%rip),%xmm6
movsd  0xe3e(%rip),%xmm5
movsd  0xe2e(%rip),%xmm4
movsd  0xe1e(%rip),%xmm3
xorpd  %xmm0,%xmm0
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm3,%xmm1
divsd  %xmm4,%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm5,%xmm1
movapd %xmm6,%xmm2
divsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
add    $0x1,%rax
cmp    $0x4e20,%rax
jne    11f0 <main+0xd0>
divsd  0xde0(%rip),%xmm0
lea    0xe14(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [23 x i8] c"Number of devices: %d\0A\00"
@acc_device_nvidia = global i32 0
@.str.1 = [12 x i8] c"Change: %d\0A\00"
@.str.2 = [12 x i8] c"pi=%11.10f\0A\00"
define i32 @main() {
%1 = load i32, i32* @acc_device_nvidia
%2 = tail call i32 @acc_get_num_devices(i32 %1)
%3 = sitofp i32 %2 to double
%4 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), double %3)
br label %5
5: ; preds = %0, %5
%6 = phi double [ 0.000000e+00, %0 ], [ %13, %5 ]
%7 = phi i64 [ 0, %0 ], [ %14, %5 ]
%8 = sitofp i64 %7 to double
%9 = fadd double %8, 5.000000e-01
%10 = fdiv double %9, 2.000000e+04
%11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double 1.000000e+00)
%12 = fdiv double 4.000000e+00, %11
%13 = fadd double %6, %12
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, 20000
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+00)
%18 = fdiv double %13, 2.000000e+04
%19 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %18)
br label %20
20: ; preds = %16, %20
%21 = phi double [ 0.000000e+00, %16 ], [ %28, %20 ]
%22 = phi i64 [ 0, %16 ], [ %29, %20 ]
%23 = sitofp i64 %22 to double
%24 = fadd double %23, 5.000000e-01
%25 = fdiv double %24, 2.000000e+04
%26 = tail call double @llvm.fmuladd.f64(double %25, double %25, double 1.000000e+00)
%27 = fdiv double 4.000000e+00, %26
%28 = fadd double %21, %27
%29 = add nuw nsw i64 %22, 1
%30 = icmp eq i64 %29, 20000
br i1 %30, label %31, label %20
31: ; preds = %20
%32 = fdiv double %28, 2.000000e+04
%33 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %32)
ret i32 0
}