#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*/ Trap(double, double, int, double *);
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)
  Trap(a, b, n, &global_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    $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
lea    -0x18(%rbp),%rsi
call   1060 <Trap@plt>
mov    -0x2c(%rbp),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
lea    0xe28(%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
movq   $0x0,0x20(%rsp)
cmp    $0x2,%edi
je     117f <main+0x1f>
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    0xec0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5c(%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     11d1 <main+0x71>
mov    (%rbx),%rdi
call   1050 <Usage@plt>
mov    0xc(%rsp),%edi
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
lea    0x20(%rsp),%rsi
call   1070 <Trap@plt>
mov    0xc(%rsp),%esi
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
lea    0xe1f(%rip),%rdi
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 i32 @Trap(double %35, double %36, i32 %37, double* %6)
%39 = load i32, i32* %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load double, double* %7
%42 = load double, double* %8
%43 = load double, double* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), double %41, double %42, double %43)
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 double
%6 = alloca i32
%7 = bitcast double* %3 to i8*
store double 0.000000e+00, double* %3
%8 = bitcast double* %4 to i8*
%9 = bitcast double* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = icmp eq i32 %0, 2
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 @Usage(i8* %13)
br label %15
15: ; preds = %12, %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @strtol(i8* nocapture %17, i32* null, i32 10)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double* %4, double* %5, i32* %6)
%21 = load i32, i32* %6
%22 = srem i32 %21, %18
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %15
%25 = load i8*, i8** %1
%26 = call i32 @Usage(i8* %25)
%27 = load i32, i32* %6
br label %28
28: ; preds = %24, %15
%29 = phi i32 [ %27, %24 ], [ %21, %15 ]
%30 = load double, double* %4
%31 = load double, double* %5
%32 = call i32 @Trap(double %30, double %31, i32 %29, double* %3)
%33 = load i32, i32* %6
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load double, double* %4
%36 = load double, double* %5
%37 = load double, double* %3
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), double %35, double %36, double %37)
ret i32 0
}