#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 */
scalar_t__ Local_trap(double, double, int);
int /*<<< orphan*/ Usage(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, double *, double *, int *);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  double global_result;
  double a, b;
  int n;
  int thread_count;
  if (argc != 2)
    Usage(argv[0]);
  thread_count = strtol(argv[1], NULL, 10);
  printf("Enter a, b, and n\n");
  scanf("%lf %lf %d", &a, &b, &n);
  if (n % thread_count != 0)
    Usage(argv[0]);
  global_result = 0.0;
#pragma omp parallel num_threads(thread_count)
  {
    double my_result = 0.0;
    my_result += Local_trap(a, b, n);
#pragma omp critical
    global_result += my_result;
  }
  printf("With n = %d trapezoids, our estimate\n", n);
  printf("of the integral from %f to %f = %.14e\n", a, b, global_result);
  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)
je     117c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <Usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x30(%rbp)
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe69(%rip),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1070 <scanf@plt>
mov    -0x2c(%rbp),%eax
cltd
idivl  -0x30(%rbp)
cmp    $0x0,%edx
je     11d7 <main+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <Usage@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x2c(%rbp),%edi
call   1060 <Local_trap@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
lea    0xe06(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1176 <main+0x16>
mov    (%rbx),%rdi
call   1050 <Usage@plt>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ebp
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe65(%rip),%rdi
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
mov    %edi,%eax
cltd
idiv   %ebp
test   %edx,%edx
je     11c8 <main+0x68>
mov    (%rbx),%rdi
call   1050 <Usage@plt>
mov    0xc(%rsp),%edi
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1070 <Local_trap@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    0xc(%rsp),%esi
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
lea    0xe25(%rip),%rdi
movsd  0x20(%rsp),%xmm2
mov    $0x3,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter a, b, and n\0A\00"
@.str.1 = [11 x i8] c"%lf %lf %d\00"
@.str.2 = [38 x i8] c"With n = %d trapezoids, our estimate\0A\00"
@.str.3 = [39 x i8] c"of the integral from %f to %f = %.14e\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @Usage(i8* %17)
br label %19
19: ; preds = %14, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strtol(i8* %22, i32* null, i32 10)
store i32 %23, i32* %10
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double* %7, double* %8, i32* %9)
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = srem i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %19
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @Usage(i8* %33)
br label %35
35: ; preds = %30, %19
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %11
%36 = load double, double* %7
%37 = load double, double* %8
%38 = load i32, i32* %9
%39 = call i64 @Local_trap(double %36, double %37, i32 %38)
%40 = sitofp i64 %39 to double
%41 = load double, double* %11
%42 = fadd double %41, %40
store double %42, double* %11
%43 = load double, double* %11
%44 = load double, double* %6
%45 = fadd double %44, %43
store double %45, double* %6
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = load double, double* %7
%49 = load double, double* %8
%50 = load double, double* %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), double %48, double %49, double %50)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"%lf %lf %d\00"
@.str.2 = [38 x i8] c"With n = %d trapezoids, our estimate\0A\00"
@.str.3 = [39 x i8] c"of the integral from %f to %f = %.14e\0A\00"
@str = [18 x i8] c"Enter a, b, and n\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = bitcast double* %3 to i8*
%7 = bitcast double* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @Usage(i8* %11)
br label %13
13: ; preds = %10, %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strtol(i8* nocapture %15, i32* null, i32 10)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double* %3, double* %4, i32* %5)
%19 = load i32, i32* %5
%20 = srem i32 %19, %16
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %13
%23 = load i8*, i8** %1
%24 = call i32 @Usage(i8* %23)
%25 = load i32, i32* %5
br label %26
26: ; preds = %22, %13
%27 = phi i32 [ %25, %22 ], [ %19, %13 ]
%28 = load double, double* %3
%29 = load double, double* %4
%30 = call i64 @Local_trap(double %28, double %29, i32 %27)
%31 = sitofp i64 %30 to double
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load double, double* %3
%35 = load double, double* %4
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), double %34, double %35, double %31)
ret i32 0
}