#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 M_PI;
scalar_t__ RAND_MAX;
double acos(int);
double cos(double);
scalar_t__ rand();
int /*<<< orphan*/ salpeter(int, double *, double, double, int);
double sin(double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void generate_uniform(int N, double *x, double *y, double *z, double *m,
                      double R) {
  salpeter(N, m, 2.37, 0.2, 20.);
  int i;
  double r, p, x1, x2, phi, theta;
  srand(time(NULL));
  for (i = 0; i < N; i++) {
    r = 0;
    p = 1;
    while (p > r * r) {
      r = (double)rand() / (double)RAND_MAX;
      p = (double)rand() / (double)RAND_MAX;
    }
    x1 = (double)rand() / (double)RAND_MAX;
    x2 = (double)rand() / (double)RAND_MAX;
    theta = acos(1 - 2 * x1);
    phi = 2 * M_PI * x2;
    x[i] = r * R * sin(theta) * cos(phi);
    y[i] = r * R * sin(theta) * sin(phi);
    z[i] = r * R * cos(theta);
  }
}


x86 assembly (clang, -O0):
<generate_uniform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
movsd  0xe5e(%rip),%xmm0
movsd  0xe5e(%rip),%xmm1
mov    $0x14,%edx
call   1080 <salpeter@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    13b1 <generate_uniform+0x241>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe29(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    124c <generate_uniform+0xdc>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2dc8(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2da7(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    11ec <generate_uniform+0x7c>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2d81(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2d60(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xd71(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <acos@plt>
movsd  %xmm0,-0x68(%rbp)
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x60(%rbp),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x68(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
call   1070 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11cb <generate_uniform+0x5b>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_uniform>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,0x20(%rsp)
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebp
movsd  0xe69(%rip),%xmm0
movsd  0xe69(%rip),%xmm1
mov    %r8,%rsi
mov    $0x14,%edx
call   1080 <salpeter@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
test   %ebp,%ebp
jle    1326 <generate_uniform+0x1b6>
mov    %ebp,%ebp
mov    0x2e15(%rip),%rbx
xor    %r13d,%r13d
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
divsd  %xmm1,%xmm0
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
ja     11d0 <generate_uniform+0x60>
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xda2(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <acos@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rsp),%xmm1
mulsd  0x20(%rsp),%xmm1
movsd  %xmm1,(%rsp)
call   1050 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1070 <cos@plt>
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%r12,%r13,8)
movsd  0x10(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%r15,%r13,8)
movsd  0x10(%rsp),%xmm0
call   1070 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%r14,%r13,8)
add    $0x1,%r13
cmp    %rbp,%r13
jne    11d0 <generate_uniform+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@M_PI = global i32 0
define void @generate_uniform(i32 %0, double* %1, double* %2, double* %3, double* %4, double %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store i32 %0, i32* %7
store double* %1, double** %8
store double* %2, double** %9
store double* %3, double** %10
store double* %4, double** %11
store double %5, double* %12
%20 = load i32, i32* %7
%21 = load double*, double** %11
%22 = call i32 @salpeter(i32 %20, double* %21, double 2.370000e+00, double 2.000000e-01, i32 20)
%23 = call i32 @time(i32* null)
%24 = call i32 @srand(i32 %23)
store i32 0, i32* %13
br label %25
25: ; preds = %103, %6
%26 = load i32, i32* %13
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %106
29: ; preds = %25
store double 0.000000e+00, double* %14
store double 1.000000e+00, double* %15
br label %30
30: ; preds = %36, %29
%31 = load double, double* %15
%32 = load double, double* %14
%33 = load double, double* %14
%34 = fmul double %32, %33
%35 = fcmp ogt double %31, %34
br i1 %35, label %36, label %47
36: ; preds = %30
%37 = call i64 (...) @rand()
%38 = sitofp i64 %37 to double
%39 = load i64, i64* @RAND_MAX
%40 = sitofp i64 %39 to double
%41 = fdiv double %38, %40
store double %41, double* %14
%42 = call i64 (...) @rand()
%43 = sitofp i64 %42 to double
%44 = load i64, i64* @RAND_MAX
%45 = sitofp i64 %44 to double
%46 = fdiv double %43, %45
store double %46, double* %15
br label %30
47: ; preds = %30
%48 = call i64 (...) @rand()
%49 = sitofp i64 %48 to double
%50 = load i64, i64* @RAND_MAX
%51 = sitofp i64 %50 to double
%52 = fdiv double %49, %51
store double %52, double* %16
%53 = call i64 (...) @rand()
%54 = sitofp i64 %53 to double
%55 = load i64, i64* @RAND_MAX
%56 = sitofp i64 %55 to double
%57 = fdiv double %54, %56
store double %57, double* %17
%58 = load double, double* %16
%59 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %58, double 1.000000e+00)
%60 = fptosi double %59 to i32
%61 = call double @acos(i32 %60)
store double %61, double* %19
%62 = load i32, i32* @M_PI
%63 = mul nsw i32 2, %62
%64 = sitofp i32 %63 to double
%65 = load double, double* %17
%66 = fmul double %64, %65
store double %66, double* %18
%67 = load double, double* %14
%68 = load double, double* %12
%69 = fmul double %67, %68
%70 = load double, double* %19
%71 = call double @sin(double %70)
%72 = fmul double %69, %71
%73 = load double, double* %18
%74 = call double @cos(double %73)
%75 = fmul double %72, %74
%76 = load double*, double** %8
%77 = load i32, i32* %13
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %76, i64 %78
store double %75, double* %79
%80 = load double, double* %14
%81 = load double, double* %12
%82 = fmul double %80, %81
%83 = load double, double* %19
%84 = call double @sin(double %83)
%85 = fmul double %82, %84
%86 = load double, double* %18
%87 = call double @sin(double %86)
%88 = fmul double %85, %87
%89 = load double*, double** %9
%90 = load i32, i32* %13
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds double, double* %89, i64 %91
store double %88, double* %92
%93 = load double, double* %14
%94 = load double, double* %12
%95 = fmul double %93, %94
%96 = load double, double* %19
%97 = call double @cos(double %96)
%98 = fmul double %95, %97
%99 = load double*, double** %10
%100 = load i32, i32* %13
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds double, double* %99, i64 %101
store double %98, double* %102
br label %103
103: ; preds = %47
%104 = load i32, i32* %13
%105 = add nsw i32 %104, 1
store i32 %105, i32* %13
br label %25
106: ; preds = %25
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@M_PI = global i32 0
define void @generate_uniform(i32 %0, double* nocapture writeonly %1, double* nocapture writeonly %2, double* nocapture writeonly %3, double* %4, double %5) {
%7 = tail call i32 @salpeter(i32 %0, double* %4, double 2.370000e+00, double 2.000000e-01, i32 20)
%8 = tail call i32 @time(i32* null)
%9 = tail call i32 @srand(i32 %8)
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %62
11: ; preds = %6
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %11, %28
%14 = phi i64 [ 0, %11 ], [ %60, %28 ]
br label %15
15: ; preds = %13, %15
%16 = tail call i64 (...) @rand()
%17 = sitofp i64 %16 to double
%18 = load i64, i64* @RAND_MAX
%19 = sitofp i64 %18 to double
%20 = fdiv double %17, %19
%21 = tail call i64 (...) @rand()
%22 = sitofp i64 %21 to double
%23 = load i64, i64* @RAND_MAX
%24 = sitofp i64 %23 to double
%25 = fdiv double %22, %24
%26 = fmul double %20, %20
%27 = fcmp ogt double %25, %26
br i1 %27, label %15, label %28
28: ; preds = %15
%29 = tail call i64 (...) @rand()
%30 = sitofp i64 %29 to double
%31 = load i64, i64* @RAND_MAX
%32 = sitofp i64 %31 to double
%33 = fdiv double %30, %32
%34 = tail call i64 (...) @rand()
%35 = sitofp i64 %34 to double
%36 = load i64, i64* @RAND_MAX
%37 = sitofp i64 %36 to double
%38 = fdiv double %35, %37
%39 = tail call double @llvm.fmuladd.f64(double %33, double -2.000000e+00, double 1.000000e+00)
%40 = fptosi double %39 to i32
%41 = tail call double @acos(i32 %40)
%42 = load i32, i32* @M_PI
%43 = shl nsw i32 %42, 1
%44 = sitofp i32 %43 to double
%45 = fmul double %38, %44
%46 = fmul double %20, %5
%47 = tail call double @sin(double %41)
%48 = fmul double %46, %47
%49 = tail call double @cos(double %45)
%50 = fmul double %48, %49
%51 = getelementptr inbounds double, double* %1, i64 %14
store double %50, double* %51
%52 = tail call double @sin(double %41)
%53 = fmul double %46, %52
%54 = tail call double @sin(double %45)
%55 = fmul double %53, %54
%56 = getelementptr inbounds double, double* %2, i64 %14
store double %55, double* %56
%57 = tail call double @cos(double %41)
%58 = fmul double %46, %57
%59 = getelementptr inbounds double, double* %3, i64 %14
store double %58, double* %59
%60 = add nuw nsw i64 %14, 1
%61 = icmp eq i64 %60, %12
br i1 %61, label %62, label %13
62: ; preds = %28, %6
ret void
}