#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 */
double RAND_MAX;
int *malloc(int);
int /*<<< orphan*/ pthread_exit(void *);
scalar_t__ rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
void *calculate_PI(void *arg) {
  int *points_to_generate = (int *)arg;
  int i;
  int *in_circle = malloc(sizeof(int));
  double x, y, point;
  srand((unsigned)time(NULL));
  for (i = 0; i < *points_to_generate; i++) {
    x = (double)rand() / RAND_MAX;
    y = (double)rand() / RAND_MAX;
    point = x * x + y * y;
    if (point <= 1.0)
      (*in_circle)++;
  }
  pthread_exit((void *)in_circle);
}


x86 assembly (clang, -O0):
<calculate_PI>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    1222 <calculate_PI+0xd2>
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e3d(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e21(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe07(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     120f <calculate_PI+0xbf>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1214 <calculate_PI+0xc4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <calculate_PI+0x39>
mov    -0x28(%rbp),%rdi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_PI>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
cmpl   $0x0,(%r15)
jle    11e8 <calculate_PI+0x98>
mov    0x2e66(%rip),%rbx
xor    %ebp,%ebp
jmp    1198 <calculate_PI+0x48>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    (%r15),%ebp
jge    11e8 <calculate_PI+0x98>
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%rbx),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%rbx),%xmm0
mulsd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe24(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1190 <calculate_PI+0x40>
addl   $0x1,(%r14)
jmp    1190 <calculate_PI+0x40>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <pthread_exit@plt>

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i8* @calculate_PI(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %4
%12 = call i32* @malloc(i32 4)
store i32* %12, i32** %6
%13 = call i64 @time(i32* null)
%14 = trunc i64 %13 to i32
%15 = call i32 @srand(i32 %14)
store i32 0, i32* %5
br label %16
16: ; preds = %43, %1
%17 = load i32, i32* %5
%18 = load i32*, i32** %4
%19 = load i32, i32* %18
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %46
21: ; preds = %16
%22 = call i64 (...) @rand()
%23 = sitofp i64 %22 to double
%24 = load double, double* @RAND_MAX
%25 = fdiv double %23, %24
store double %25, double* %7
%26 = call i64 (...) @rand()
%27 = sitofp i64 %26 to double
%28 = load double, double* @RAND_MAX
%29 = fdiv double %27, %28
store double %29, double* %8
%30 = load double, double* %7
%31 = load double, double* %7
%32 = load double, double* %8
%33 = load double, double* %8
%34 = fmul double %32, %33
%35 = call double @llvm.fmuladd.f64(double %30, double %31, double %34)
store double %35, double* %9
%36 = load double, double* %9
%37 = fcmp ole double %36, 1.000000e+00
br i1 %37, label %38, label %42
38: ; preds = %21
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
store i32 %41, i32* %39
br label %42
42: ; preds = %38, %21
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %16
46: ; preds = %16
%47 = load i32*, i32** %6
%48 = bitcast i32* %47 to i8*
%49 = call i32 @pthread_exit(i8* %48)
%50 = load i8*, i8** %2
ret i8* %50
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define noalias i8* @calculate_PI(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = tail call i32* @malloc(i32 4)
%4 = tail call i64 @time(i32* null)
%5 = trunc i64 %4 to i32
%6 = tail call i32 @srand(i32 %5)
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %1, %25
%10 = phi i32 [ %26, %25 ], [ 0, %1 ]
%11 = tail call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = load double, double* @RAND_MAX
%14 = fdiv double %12, %13
%15 = tail call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = load double, double* @RAND_MAX
%18 = fdiv double %16, %17
%19 = fmul double %18, %18
%20 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %19)
%21 = fcmp ugt double %20, 1.000000e+00
br i1 %21, label %25, label %22
22: ; preds = %9
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %25
25: ; preds = %9, %22
%26 = add nuw nsw i32 %10, 1
%27 = load i32, i32* %2
%28 = icmp slt i32 %26, %27
br i1 %28, label %9, label %29
29: ; preds = %25, %1
%30 = bitcast i32* %3 to i8*
%31 = tail call i32 @pthread_exit(i8* %30)
ret i8* undef
}