#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 Check_sum(long, int);
double Sum(long, int);
int /*<<< orphan*/ Usage(char *);
double fabs(double);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double, ...);
void *strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  double global_result;
  long n;
  int thread_count;
  double start, finish;
  double error, check;
  if (argc != 3)
    Usage(argv[0]);
  thread_count = strtol(argv[1], NULL, 10);
  n = strtol(argv[2], NULL, 10);
  start = omp_get_wtime();
  global_result = Sum(n, thread_count);
  finish = omp_get_wtime();
  check = Check_sum(n, thread_count);
  error = fabs(global_result - check);
  printf("Result = %.14e\n", global_result);
  printf("Check = %.14e\n", check);
  printf("With n = %ld terms, the error is %.14e\n", n, error);
  printf("Elapsed time = %e seconds\n", finish - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <Usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <Sum@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1080 <Check_sum@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movaps 0xdf6(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xdf1(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xdee(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
lea    0xde4(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
lea    0xdf4(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     1177 <main+0x17>
mov    (%rbx),%rdi
call   1060 <Usage@plt>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x18(%rsp)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <Sum@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <Check_sum@plt>
movapd %xmm0,%xmm2
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
andpd  0xe0f(%rip),%xmm1
movapd %xmm1,0x20(%rsp)
lea    0xe12(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe14(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
lea    0xe07(%rip),%rdi
movaps 0x20(%rsp),%xmm1
mov    $0x2,%al
call   1040 <printf@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
lea    0xe10(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Result = %.14e\0A\00"
@.str.1 = [15 x i8] c"Check = %.14e\0A\00"
@.str.2 = [40 x i8] c"With n = %ld terms, the error is %.14e\0A\00"
@.str.3 = [27 x i8] c"Elapsed time = %e seconds\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i64
%8 = alloca i32
%9 = alloca double
%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 i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @Usage(i8* %18)
br label %20
20: ; preds = %15, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i8* @strtol(i8* %23, i32* null, i32 10)
%25 = ptrtoint i8* %24 to i32
store i32 %25, i32* %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i8* @strtol(i8* %28, i32* null, i32 10)
%30 = ptrtoint i8* %29 to i64
store i64 %30, i64* %7
%31 = call double (...) @omp_get_wtime()
store double %31, double* %9
%32 = load i64, i64* %7
%33 = load i32, i32* %8
%34 = call double @Sum(i64 %32, i32 %33)
store double %34, double* %6
%35 = call double (...) @omp_get_wtime()
store double %35, double* %10
%36 = load i64, i64* %7
%37 = load i32, i32* %8
%38 = call double @Check_sum(i64 %36, i32 %37)
store double %38, double* %12
%39 = load double, double* %6
%40 = load double, double* %12
%41 = fsub double %39, %40
%42 = call double @llvm.fabs.f64(double %41)
store double %42, double* %11
%43 = load double, double* %6
%44 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double %43)
%45 = load double, double* %12
%46 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %45)
%47 = load i64, i64* %7
%48 = sitofp i64 %47 to double
%49 = load double, double* %11
%50 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), double %48, double %49)
%51 = load double, double* %10
%52 = load double, double* %9
%53 = fsub double %51, %52
%54 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %53)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Result = %.14e\0A\00"
@.str.1 = [15 x i8] c"Check = %.14e\0A\00"
@.str.2 = [40 x i8] c"With n = %ld terms, the error is %.14e\0A\00"
@.str.3 = [27 x i8] c"Elapsed time = %e seconds\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @Usage(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = ptrtoint i8* %10 to i64
%12 = trunc i64 %11 to i32
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i8* @strtol(i8* nocapture %14, i32* null, i32 10)
%16 = ptrtoint i8* %15 to i64
%17 = tail call double (...) @omp_get_wtime()
%18 = tail call double @Sum(i64 %16, i32 %12)
%19 = tail call double (...) @omp_get_wtime()
%20 = tail call double @Check_sum(i64 %16, i32 %12)
%21 = fsub double %18, %20
%22 = tail call double @llvm.fabs.f64(double %21)
%23 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double %18)
%24 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %20)
%25 = sitofp i64 %16 to double
%26 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), double %25, double %22)
%27 = fsub double %19, %17
%28 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), double %27)
ret i32 0
}