#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(char *);
double drand48();
int /*<<< orphan*/ exit(int);
float *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand48(int);
int main(int argc, char **argv) {
  int n_points;
  int seed;
  float *x;
  float *y;
  int i;
  int n_in;
  float integral;
  if (argc != 3) {
    printf("%s\n", "USAGE: ./pi.x n_points seed");
    exit(1);
  }
  n_points = atoi(argv[1]);
  seed = atoi(argv[2]);
  printf("Using %d points to integrate\n", n_points);
  printf("Expected value %f\n", 3.1459);
  if (!(x = malloc(n_points * sizeof(float)))) {
    printf("problem with memory allocation\n");
    exit(1);
  }
  if (!(y = malloc(n_points * sizeof(float)))) {
    printf("problem with memory allocation\n");
    exit(1);
  }
  srand48(seed);
  n_in = 0;
  for (i = 0; i < n_points; i++) {
    x[i] = 2.0 * (drand48() - 0.5);
    y[i] = 2.0 * (drand48() - 0.5);
    if ((x[i] * x[i] + y[i] * y[i]) < 1.0) {
      n_in++;
    }
  }
  integral = 4.0 * n_in / n_points;
  printf("integral %f\n", integral);
  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   $0x3,-0x8(%rbp)
je     119f <main+0x3f>
lea    0xea1(%rip),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8f(%rip),%rdi
movsd  0xe21(%rip),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121b <main+0xbb>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1250 <main+0xf0>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%edi
call   1050 <srand48@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1346 <main+0x1e6>
mov    $0x0,%al
call   1080 <drand48@plt>
movaps %xmm0,%xmm1
movsd  0xd9c(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xd88(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    $0x0,%al
call   1080 <drand48@plt>
movaps %xmm0,%xmm1
movsd  0xd69(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xd55(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xcf0(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1333 <main+0x1d3>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1338 <main+0x1d8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1266 <main+0x106>
cvtsi2sdl -0x30(%rbp),%xmm1
movsd  0xcb5(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd20(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    12d2 <main+0x162>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
lea    0xe93(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea0(%rip),%rdi
movsd  0xe42(%rip),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0x0(,%r14,4),%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     12c9 <main+0x159>
mov    %rax,%r15
mov    %ebx,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     12c9 <main+0x159>
mov    %rax,%r12
mov    %ebp,%edi
call   1060 <srand48@plt>
test   %r14d,%r14d
jle    1292 <main+0x122>
mov    %r14d,%r13d
xor    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <drand48@plt>
movsd  0xde9(%rip),%xmm1
addsd  %xmm1,%xmm0
addsd  %xmm0,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x4(%rsp)
movss  %xmm0,(%r15,%rbp,4)
xor    %eax,%eax
call   1090 <drand48@plt>
addsd  0xdc2(%rip),%xmm0
addsd  %xmm0,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%r12,%rbp,4)
mulss  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
mulss  %xmm1,%xmm1
addss  %xmm0,%xmm1
xor    %eax,%eax
movss  0xda8(%rip),%xmm0
ucomiss %xmm1,%xmm0
seta   %al
add    %eax,%ebx
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1210 <main+0xa0>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0xd80(%rip),%xmm0
jmp    1296 <main+0x126>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb8(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda6(%rip),%rdi
jmp    12d9 <main+0x169>
lea    0xd43(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [28 x i8] c"USAGE: ./pi.x n_points seed\00"
@.str.2 = [30 x i8] c"Using %d points to integrate\0A\00"
@.str.3 = [19 x i8] c"Expected value %f\0A\00"
@.str.4 = [32 x i8] c"problem with memory allocation\0A\00"
@.str.5 = [13 x i8] c"integral %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca float*
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
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 %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double 3.145900e+00)
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call float* @malloc(i32 %33)
store float* %34, float** %8
%35 = icmp ne float* %34, null
br i1 %35, label %39, label %36
36: ; preds = %18
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %18
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = mul i64 %41, 4
%43 = trunc i64 %42 to i32
%44 = call float* @malloc(i32 %43)
store float* %44, float** %9
%45 = icmp ne float* %44, null
br i1 %45, label %49, label %46
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %39
%50 = load i32, i32* %7
%51 = call i32 @srand48(i32 %50)
store i32 0, i32* %11
store i32 0, i32* %10
br label %52
52: ; preds = %101, %49
%53 = load i32, i32* %10
%54 = load i32, i32* %6
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %104
56: ; preds = %52
%57 = call double (...) @drand48()
%58 = fsub double %57, 5.000000e-01
%59 = fmul double 2.000000e+00, %58
%60 = fptrunc double %59 to float
%61 = load float*, float** %8
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds float, float* %61, i64 %63
store float %60, float* %64
%65 = call double (...) @drand48()
%66 = fsub double %65, 5.000000e-01
%67 = fmul double 2.000000e+00, %66
%68 = fptrunc double %67 to float
%69 = load float*, float** %9
%70 = load i32, i32* %10
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds float, float* %69, i64 %71
store float %68, float* %72
%73 = load float*, float** %8
%74 = load i32, i32* %10
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds float, float* %73, i64 %75
%77 = load float, float* %76
%78 = load float*, float** %8
%79 = load i32, i32* %10
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds float, float* %78, i64 %80
%82 = load float, float* %81
%83 = load float*, float** %9
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds float, float* %83, i64 %85
%87 = load float, float* %86
%88 = load float*, float** %9
%89 = load i32, i32* %10
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds float, float* %88, i64 %90
%92 = load float, float* %91
%93 = fmul float %87, %92
%94 = call float @llvm.fmuladd.f32(float %77, float %82, float %93)
%95 = fpext float %94 to double
%96 = fcmp olt double %95, 1.000000e+00
br i1 %96, label %97, label %100
97: ; preds = %56
%98 = load i32, i32* %11
%99 = add nsw i32 %98, 1
store i32 %99, i32* %11
br label %100
100: ; preds = %97, %56
br label %101
101: ; preds = %100
%102 = load i32, i32* %10
%103 = add nsw i32 %102, 1
store i32 %103, i32* %10
br label %52
104: ; preds = %52
%105 = load i32, i32* %11
%106 = sitofp i32 %105 to double
%107 = fmul double 4.000000e+00, %106
%108 = load i32, i32* %6
%109 = sitofp i32 %108 to double
%110 = fdiv double %107, %109
%111 = fptrunc double %110 to float
store float %111, float* %12
%112 = load float, float* %12
%113 = fpext float %112 to double
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), double %113)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"USAGE: ./pi.x n_points seed\00"
@.str.2 = [30 x i8] c"Using %d points to integrate\0A\00"
@.str.3 = [19 x i8] c"Expected value %f\0A\00"
@.str.5 = [13 x i8] c"integral %f\0A\00"
@str.6 = [31 x i8] c"problem with memory allocation\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 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double 3.145900e+00)
%16 = shl i32 %10, 2
%17 = tail call float* @malloc(i32 %16)
%18 = icmp eq float* %17, null
br i1 %18, label %19, label %22
19: ; preds = %7
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.6, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %7
%23 = tail call float* @malloc(i32 %16)
%24 = icmp eq float* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.6, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = tail call i32 @srand48(i32 %13)
%30 = icmp sgt i32 %10, 0
br i1 %30, label %31, label %56
31: ; preds = %28
%32 = zext i32 %10 to i64
br label %33
33: ; preds = %31, %33
%34 = phi i64 [ 0, %31 ], [ %51, %33 ]
%35 = phi i32 [ 0, %31 ], [ %50, %33 ]
%36 = tail call double (...) @drand48()
%37 = fadd double %36, -5.000000e-01
%38 = fmul double %37, 2.000000e+00
%39 = fptrunc double %38 to float
%40 = getelementptr inbounds float, float* %17, i64 %34
store float %39, float* %40
%41 = tail call double (...) @drand48()
%42 = fadd double %41, -5.000000e-01
%43 = fmul double %42, 2.000000e+00
%44 = fptrunc double %43 to float
%45 = getelementptr inbounds float, float* %23, i64 %34
store float %44, float* %45
%46 = fmul float %44, %44
%47 = tail call float @llvm.fmuladd.f32(float %39, float %39, float %46)
%48 = fcmp olt float %47, 1.000000e+00
%49 = zext i1 %48 to i32
%50 = add nuw nsw i32 %35, %49
%51 = add nuw nsw i64 %34, 1
%52 = icmp eq i64 %51, %32
br i1 %52, label %53, label %33
53: ; preds = %33
%54 = sitofp i32 %50 to double
%55 = fmul double %54, 4.000000e+00
br label %56
56: ; preds = %53, %28
%57 = phi double [ 0.000000e+00, %28 ], [ %55, %53 ]
%58 = sitofp i32 %10 to double
%59 = fdiv double %57, %58
%60 = fptrunc double %59 to float
%61 = fpext float %60 to double
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), double %61)
ret i32 0
}