#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 *);
long long atoll(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, long long);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ stderr;
int main(int argc, char **args) {
  int task_id;
  int total_tasks;
  long long int n;
  long long int i;
  double l_sum, x, h;
  task_id = atoi(args[1]);
  total_tasks = atoi(args[2]);
  n = atoll(args[3]);
  fprintf(stderr, "task_id=%d total_tasks=%d n=%lld\n", task_id, total_tasks,
          n);
  h = 1.0 / n;
  l_sum = 0.0;
  for (i = task_id; i < n; i += total_tasks) {
    x = (i + 0.5) * h;
    l_sum += 4.0 / (1.0 + x * x);
  }
  l_sum *= h;
  printf("%0.12g\n", l_sum);
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <atoll@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xe4c(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movslq -0x14(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1238 <main+0xf8>
cvtsi2sdq -0x28(%rbp),%xmm0
movsd  0xe27(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xdf3(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xdef(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movslq -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11cd <main+0x8d>
movsd  -0x40(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
call   1040 <atoll@plt>
mov    %rax,%rbx
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    %rbx,%r8
call   1050 <fprintf@plt>
cvtsi2sd %rbx,%xmm2
movsd  0xe6c(%rip),%xmm1
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
movslq %ebp,%rax
xorpd  %xmm2,%xmm2
cmp    %rax,%rbx
jle    11ec <main+0xac>
movslq %r14d,%rcx
xorpd  %xmm2,%xmm2
movsd  0xe51(%rip),%xmm3
movsd  0xe51(%rip),%xmm4
nop
xorps  %xmm5,%xmm5
cvtsi2sd %rax,%xmm5
addsd  %xmm3,%xmm5
mulsd  %xmm0,%xmm5
mulsd  %xmm5,%xmm5
addsd  %xmm1,%xmm5
movapd %xmm4,%xmm6
divsd  %xmm5,%xmm6
addsd  %xmm6,%xmm2
add    %rcx,%rax
cmp    %rbx,%rax
jl     11c0 <main+0x80>
mulsd  %xmm2,%xmm0
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"task_id=%d total_tasks=%d n=%lld\0A\00"
@.str.1 = [8 x i8] c"%0.12g\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 i64
%9 = alloca i64
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %7
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 3
%23 = load i8*, i8** %22
%24 = call i64 @atoll(i8* %23)
store i64 %24, i64* %8
%25 = load i32, i32* @stderr
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = load i64, i64* %8
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27, i64 %28)
%30 = load i64, i64* %8
%31 = sitofp i64 %30 to double
%32 = fdiv double 1.000000e+00, %31
store double %32, double* %12
store double 0.000000e+00, double* %10
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
store i64 %34, i64* %9
br label %35
35: ; preds = %51, %2
%36 = load i64, i64* %9
%37 = load i64, i64* %8
%38 = icmp slt i64 %36, %37
br i1 %38, label %39, label %56
39: ; preds = %35
%40 = load i64, i64* %9
%41 = sitofp i64 %40 to double
%42 = fadd double %41, 5.000000e-01
%43 = load double, double* %12
%44 = fmul double %42, %43
store double %44, double* %11
%45 = load double, double* %11
%46 = load double, double* %11
%47 = call double @llvm.fmuladd.f64(double %45, double %46, double 1.000000e+00)
%48 = fdiv double 4.000000e+00, %47
%49 = load double, double* %10
%50 = fadd double %49, %48
store double %50, double* %10
br label %51
51: ; preds = %39
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = load i64, i64* %9
%55 = add nsw i64 %54, %53
store i64 %55, i64* %9
br label %35
56: ; preds = %35
%57 = load double, double* %12
%58 = load double, double* %10
%59 = fmul double %58, %57
store double %59, double* %10
%60 = load double, double* %10
%61 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %60)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"task_id=%d total_tasks=%d n=%lld\0A\00"
@.str.1 = [8 x i8] c"%0.12g\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i64 @atoll(i8* %10)
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8, i64 %11)
%14 = sitofp i64 %11 to double
%15 = fdiv double 1.000000e+00, %14
%16 = sext i32 %5 to i64
%17 = icmp sgt i64 %11, %16
br i1 %17, label %18, label %31
18: ; preds = %2
%19 = sext i32 %8 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ %16, %18 ], [ %29, %20 ]
%22 = phi double [ 0.000000e+00, %18 ], [ %28, %20 ]
%23 = sitofp i64 %21 to double
%24 = fadd double %23, 5.000000e-01
%25 = fmul double %15, %24
%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 %22, %27
%29 = add nsw i64 %21, %19
%30 = icmp slt i64 %29, %11
br i1 %30, label %20, label %31
31: ; preds = %20, %2
%32 = phi double [ 0.000000e+00, %2 ], [ %28, %20 ]
%33 = fmul double %15, %32
%34 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %33)
ret i32 0
}