#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 float_uniform(int *);
int /*<<< orphan*/ free(int *);
int *perm_uniform(int, int, int *);
void lhs_random(int nvar, int npoint, int *seed, double x[]) {
  int base = 0, i, j, k, *perm;
  double r;
  for (k = i = 0; i < nvar; i++) {
    perm = perm_uniform(npoint, base, seed);
    for (j = 0; j < npoint; j++) {
      r = float_uniform(seed);
      x[k++] = (((double)perm[j]) + r) / ((double)npoint);
    }
    free(perm);
  }
}


x86 assembly (clang, -O0):
<lhs_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f2 <lhs_random+0xc2>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <perm_uniform@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11db <lhs_random+0xab>
mov    -0x10(%rbp),%rdi
call   1050 <float_uniform@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
addsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1181 <lhs_random+0x51>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115b <lhs_random+0x2b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lhs_random>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x18(%rsp)
mov    %esi,0xc(%rsp)
mov    %edi,0x10(%rsp)
test   %edi,%edi
jle    11fa <lhs_random+0xca>
mov    %rdx,%r13
mov    0xc(%rsp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    %eax,%ebx
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    1183 <lhs_random+0x53>
xchg   %ax,%ax
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x1,%r14d
cmp    0x10(%rsp),%r14d
je     11fa <lhs_random+0xca>
mov    0xc(%rsp),%r15d
mov    %r15d,%edi
xor    %esi,%esi
mov    %r13,%rdx
call   1040 <perm_uniform@plt>
mov    %rax,%rbp
test   %r15d,%r15d
jle    1170 <lhs_random+0x40>
mov    %r12d,0x14(%rsp)
movslq %r12d,%rax
mov    0x18(%rsp),%rcx
lea    (%rcx,%rax,8),%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <float_uniform@plt>
xorps  %xmm1,%xmm1
cvtsi2sdl 0x0(%rbp,%r12,4),%xmm1
addsd  %xmm0,%xmm1
divsd  0x20(%rsp),%xmm1
movsd  %xmm1,(%r15,%r12,8)
add    $0x1,%r12
cmp    %r12,%rbx
jne    11c0 <lhs_random+0x90>
mov    0x14(%rsp),%eax
add    %r12d,%eax
mov    %eax,%r12d
jmp    1170 <lhs_random+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @lhs_random(i32 %0, i32 %1, i32* %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store double* %3, double** %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %12
br label %15
15: ; preds = %53, %4
%16 = load i32, i32* %10
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %56
19: ; preds = %15
%20 = load i32, i32* %6
%21 = load i32, i32* %9
%22 = load i32*, i32** %7
%23 = call i32* @perm_uniform(i32 %20, i32 %21, i32* %22)
store i32* %23, i32** %13
store i32 0, i32* %11
br label %24
24: ; preds = %47, %19
%25 = load i32, i32* %11
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %50
28: ; preds = %24
%29 = load i32*, i32** %7
%30 = call double @float_uniform(i32* %29)
store double %30, double* %14
%31 = load i32*, i32** %13
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = sitofp i32 %35 to double
%37 = load double, double* %14
%38 = fadd double %36, %37
%39 = load i32, i32* %6
%40 = sitofp i32 %39 to double
%41 = fdiv double %38, %40
%42 = load double*, double** %8
%43 = load i32, i32* %12
%44 = add nsw i32 %43, 1
store i32 %44, i32* %12
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds double, double* %42, i64 %45
store double %41, double* %46
br label %47
47: ; preds = %28
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %24
50: ; preds = %24
%51 = load i32*, i32** %13
%52 = call i32 @free(i32* %51)
br label %53
53: ; preds = %50
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %15
56: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @lhs_random(i32 %0, i32 %1, i32* %2, double* nocapture writeonly %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %36
6: ; preds = %4
%7 = icmp sgt i32 %1, 0
%8 = sitofp i32 %1 to double
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %6, %31
%11 = phi i32 [ 0, %6 ], [ %34, %31 ]
%12 = phi i32 [ 0, %6 ], [ %32, %31 ]
%13 = tail call i32* @perm_uniform(i32 %1, i32 0, i32* %2)
br i1 %7, label %14, label %31
14: ; preds = %10
%15 = sext i32 %12 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ %15, %14 ], [ %25, %16 ]
%18 = phi i64 [ 0, %14 ], [ %27, %16 ]
%19 = tail call double @float_uniform(i32* %2)
%20 = getelementptr inbounds i32, i32* %13, i64 %18
%21 = load i32, i32* %20
%22 = sitofp i32 %21 to double
%23 = fadd double %19, %22
%24 = fdiv double %23, %8
%25 = add nsw i64 %17, 1
%26 = getelementptr inbounds double, double* %3, i64 %17
store double %24, double* %26
%27 = add nuw nsw i64 %18, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %29, label %16
29: ; preds = %16
%30 = trunc i64 %25 to i32
br label %31
31: ; preds = %29, %10
%32 = phi i32 [ %12, %10 ], [ %30, %29 ]
%33 = tail call i32 @free(i32* %13)
%34 = add nuw nsw i32 %11, 1
%35 = icmp eq i32 %34, %0
br i1 %35, label %36, label %10
36: ; preds = %31, %4
ret void
}