#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(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
double func(double);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int recs = 100000000;
  const char *name = argv[0];
  int c;
  while ((c = getopt(argc, argv, "n:")) != -1) {
    switch (c) {
    case 'n':
      recs = atoi(optarg);
      break;
    case '?':
    default:
      fprintf(stderr, "Usage: %s -n [NUMBER_OF_RECTANGLES]\n", name);
      return -1;
    }
  }
  argc - +optind;
  argv += optind;
  double width;
  width = 1.0 / recs;
  int first = 0, last = recs;
  double sum = 0.0;
  int i = 0;
  for (i = first; i != last; ++i) {
    sum += func(width * i) * width * 4.0;
  }
  printf(" --- %s --- \n", name);
  printf("Number of processes: %d\n", 1);
  printf("Threads per process: %d\n", 1);
  printf("Rectangles         : %d\n", recs);
  printf("pi is approximately: %f\n", sum);
  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)
movl   $0x5f5e100,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe8a(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1201 <main+0xb1>
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
sub    $0x3f,%eax
je     11d2 <main+0x82>
jmp    11ab <main+0x5b>
mov    -0x48(%rbp),%eax
sub    $0x6e,%eax
jne    11d7 <main+0x87>
jmp    11bc <main+0x6c>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    11fc <main+0xac>
jmp    11d7 <main+0x87>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe28(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <main+0x1b3>
jmp    1178 <main+0x28>
mov    0x2dd8(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xdd7(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     12a0 <main+0x150>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x44(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1050 <func@plt>
mulsd  -0x30(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  0xd83(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1254 <main+0x104>
mov    -0x20(%rbp),%rsi
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd8d(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd93(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xd9c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    (%rsi),%r14
mov    $0x5f5e100,%r15d
lea    0xe9d(%rip),%r12
mov    0x2e7e(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1060 <getopt@plt>
cmp    $0x6e,%eax
jne    11a0 <main+0x50>
mov    0x0(%r13),%edi
call   1070 <atoi@plt>
mov    %eax,%r15d
jmp    1180 <main+0x30>
cmp    $0xffffffff,%eax
jne    1226 <main+0xd6>
test   %r15d,%r15d
je     1245 <main+0xf5>
cvtsi2sd %r15d,%xmm0
movsd  0xe41(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xorpd  %xmm1,%xmm1
mov    %r15d,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
nopl   0x0(%rax)
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <func@plt>
mulsd  0x8(%rsp),%xmm0
mulsd  0xe05(%rip),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm1
addsd  0xde1(%rip),%xmm1
add    $0xffffffff,%ebx
jne    11e0 <main+0x90>
jmp    124e <main+0xfe>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    12ab <main+0x15b>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
lea    0xde3(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdde(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xde4(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdea(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdf2(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"n:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"Usage: %s -n [NUMBER_OF_RECTANGLES]\0A\00"
@optind = global i32 0
@.str.2 = [14 x i8] c" --- %s --- \0A\00"
@.str.3 = [25 x i8] c"Number of processes: %d\0A\00"
@.str.4 = [25 x i8] c"Threads per process: %d\0A\00"
@.str.5 = [25 x i8] c"Rectangles : %d\0A\00"
@.str.6 = [25 x i8] c"pi is approximately: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100000000, i32* %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
store i8* %16, i8** %7
br label %17
17: ; preds = %32, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %8
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = load i32, i32* %8
switch i32 %23, label %28 [
i32 110, label %24
i32 63, label %27
]
24: ; preds = %22
%25 = load i32, i32* @optarg
%26 = call i32 @atoi(i32 %25)
store i32 %26, i32* %6
br label %32
27: ; preds = %22
br label %28
28: ; preds = %22, %27
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %7
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 -1, i32* %3
br label %72
32: ; preds = %24
br label %17
33: ; preds = %17
%34 = load i32, i32* %4
%35 = load i32, i32* @optind
%36 = sub nsw i32 %34, %35
%37 = load i32, i32* @optind
%38 = load i8**, i8*** %5
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8*, i8** %38, i64 %39
store i8** %40, i8*** %5
%41 = load i32, i32* %6
%42 = sitofp i32 %41 to double
%43 = fdiv double 1.000000e+00, %42
store double %43, double* %9
store i32 0, i32* %10
%44 = load i32, i32* %6
store i32 %44, i32* %11
store double 0.000000e+00, double* %12
store i32 0, i32* %13
%45 = load i32, i32* %10
store i32 %45, i32* %13
br label %46
46: ; preds = %60, %33
%47 = load i32, i32* %13
%48 = load i32, i32* %11
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %63
50: ; preds = %46
%51 = load double, double* %9
%52 = load i32, i32* %13
%53 = sitofp i32 %52 to double
%54 = fmul double %51, %53
%55 = call double @func(double %54)
%56 = load double, double* %9
%57 = fmul double %55, %56
%58 = load double, double* %12
%59 = call double @llvm.fmuladd.f64(double %57, double 4.000000e+00, double %58)
store double %59, double* %12
br label %60
60: ; preds = %50
%61 = load i32, i32* %13
%62 = add nsw i32 %61, 1
store i32 %62, i32* %13
br label %46
63: ; preds = %46
%64 = load i8*, i8** %7
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 1)
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 1)
%68 = load i32, i32* %6
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %68)
%70 = load double, double* %12
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), double %70)
store i32 0, i32* %3
br label %72
72: ; preds = %63, %28
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [3 x i8] c"n:\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"Usage: %s -n [NUMBER_OF_RECTANGLES]\0A\00"
@optind = global i32 0
@.str.2 = [14 x i8] c" --- %s --- \0A\00"
@.str.3 = [25 x i8] c"Number of processes: %d\0A\00"
@.str.4 = [25 x i8] c"Threads per process: %d\0A\00"
@.str.5 = [25 x i8] c"Rectangles : %d\0A\00"
@.str.6 = [25 x i8] c"pi is approximately: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
br label %4
4: ; preds = %7, %2
%5 = phi i32 [ 100000000, %2 ], [ %9, %7 ]
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %10 [
i32 -1, label %13
i32 110, label %7
]
7: ; preds = %4
%8 = load i32, i32* @optarg
%9 = tail call i32 @atoi(i32 %8)
br label %4
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %34
13: ; preds = %4
%14 = sitofp i32 %5 to double
%15 = fdiv double 1.000000e+00, %14
%16 = icmp eq i32 %5, 0
br i1 %16, label %27, label %17
17: ; preds = %13, %17
%18 = phi i32 [ %25, %17 ], [ 0, %13 ]
%19 = phi double [ %24, %17 ], [ 0.000000e+00, %13 ]
%20 = sitofp i32 %18 to double
%21 = fmul double %15, %20
%22 = tail call double @func(double %21)
%23 = fmul double %15, %22
%24 = tail call double @llvm.fmuladd.f64(double %23, double 4.000000e+00, double %19)
%25 = add nuw nsw i32 %18, 1
%26 = icmp eq i32 %25, %5
br i1 %26, label %27, label %17
27: ; preds = %17, %13
%28 = phi double [ 0.000000e+00, %13 ], [ %24, %17 ]
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 1)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 1)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %5)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), double %28)
br label %34
34: ; preds = %27, %10
%35 = phi i32 [ -1, %10 ], [ 0, %27 ]
ret i32 %35
}