#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 /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ rand();
int /*<<< orphan*/ stdout;
void rand4d(int dim1, int dim2, int dim3, int dim4, double *a) {
  printf("begin rand4d\n");
  for (int i = 0; i < (dim1 * dim2 * dim3 * dim4); i++)
    a[i] = (double)rand() / RAND_MAX;
  printf(" end  rand4d\n");
  fflush(stdout);
  return;
}


x86 assembly (clang, -O0):
<rand4d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
imul   -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    11a7 <rand4d+0x77>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e60(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <rand4d+0x2b>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand4d>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r13
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%r15d
mov    %edi,%r12d
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
imul   %r15d,%r12d
imul   %r14d,%ebp
imul   %r12d,%ebp
test   %ebp,%ebp
jle    1194 <rand4d+0x64>
mov    %ebp,%ebp
mov    0x2e7a(%rip),%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <rand4d+0x40>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fflush@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"begin rand4d\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.1 = [14 x i8] c" end rand4d\0A\00"
@stdout = global i32 0
define void @rand4d(i32 %0, i32 %1, i32 %2, i32 %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store double* %4, double** %10
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %11
br label %13
13: ; preds = %32, %5
%14 = load i32, i32* %11
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = mul nsw i32 %15, %16
%18 = load i32, i32* %8
%19 = mul nsw i32 %17, %18
%20 = load i32, i32* %9
%21 = mul nsw i32 %19, %20
%22 = icmp slt i32 %14, %21
br i1 %22, label %23, label %35
23: ; preds = %13
%24 = call i64 (...) @rand()
%25 = sitofp i64 %24 to double
%26 = load double, double* @RAND_MAX
%27 = fdiv double %25, %26
%28 = load double*, double** %10
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
store double %27, double* %31
br label %32
32: ; preds = %23
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
store i32 %34, i32* %11
br label %13
35: ; preds = %13
%36 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
ret void
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@stdout = global i32 0
@str = [13 x i8] c"begin rand4d\00"
@str.2 = [13 x i8] c" end rand4d\00"
define void @rand4d(i32 %0, i32 %1, i32 %2, i32 %3, double* nocapture writeonly %4) {
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%7 = mul nsw i32 %1, %0
%8 = mul nsw i32 %7, %2
%9 = mul i32 %8, %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = zext i32 %9 to i64
br label %17
13: ; preds = %17, %5
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.2, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = tail call i32 @fflush(i32 %15)
ret void
17: ; preds = %11, %17
%18 = phi i64 [ 0, %11 ], [ %24, %17 ]
%19 = tail call i64 (...) @rand()
%20 = sitofp i64 %19 to double
%21 = load double, double* @RAND_MAX
%22 = fdiv double %20, %21
%23 = getelementptr inbounds double, double* %4, i64 %18
store double %22, double* %23
%24 = add nuw nsw i64 %18, 1
%25 = icmp eq i64 %24, %12
br i1 %25, label %13, label %17
}