#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 = 0.0;
  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]);
#pragma omp parallel num_threads(thread_count) reduction(+ : global_result)
  global_result += Local_trap(a, b, n);
  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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1184 <main+0x34>
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    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe61(%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     11df <main+0x8f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <Usage@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x2c(%rbp),%edi
call   1060 <Local_trap@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
lea    0xe1d(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %6
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @Usage(i8* %16)
br label %18
18: ; preds = %13, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strtol(i8* %21, i32* null, i32 10)
store i32 %22, i32* %10
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double* %7, double* %8, i32* %9)
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = srem i32 %25, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %18
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @Usage(i8* %32)
br label %34
34: ; preds = %29, %18
%35 = load double, double* %7
%36 = load double, double* %8
%37 = load i32, i32* %9
%38 = call i64 @Local_trap(double %35, double %36, i32 %37)
%39 = sitofp i64 %38 to double
%40 = load double, double* %6
%41 = fadd double %40, %39
store double %41, double* %6
%42 = load i32, i32* %9
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load double, double* %7
%45 = load double, double* %8
%46 = load double, double* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), double %44, double %45, double %46)
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
}