#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(double *, char, int);
int /*<<< orphan*/ set(double *, int, int, int, int, double);
double *np_array(int szx, int szy, double init) {
  double *r;
  int sz;
  sz = szx * szy * sizeof(double);
  r = (double *)malloc(sz);
  if (init == 0)
    memset(r, '\0', sz);
  else
    for (int i = 0; i < szx; i++)
      for (int j = 0; j < szy; j++)
        set(r, i, j, szx, szy, init);
  return r;
}


x86 assembly (clang, -O0):
<np_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118a <np_array+0x5a>
jp     118a <np_array+0x5a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
jmp    11f1 <np_array+0xc1>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ec <np_array+0xbc>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d9 <np_array+0xa9>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%r8d
movsd  -0x10(%rbp),%xmm0
call   1050 <set@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a4 <np_array+0x74>
jmp    11de <np_array+0xae>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1191 <np_array+0x61>
jmp    11f1 <np_array+0xc1>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<np_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %esi,%ebp
mov    %edi,%r15d
mov    %edi,%ebx
imul   %esi,%ebx
shl    $0x3,%ebx
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    1187 <np_array+0x57>
jp     1187 <np_array+0x57>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <memset@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r15d,%r15d
jle    1177 <np_array+0x47>
xor    %r12d,%r12d
jmp    11a9 <np_array+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    %r15d,%r12d
je     1177 <np_array+0x47>
test   %ebp,%ebp
jle    11a0 <np_array+0x70>
xor    %ebx,%ebx
nop
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
movsd  0x8(%rsp),%xmm0
call   1050 <set@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    11b0 <np_array+0x80>
jmp    11a0 <np_array+0x70>

LLVM IR (-O0):
define double* @np_array(i32 %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store double %2, double* %6
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = mul nsw i32 %11, %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = trunc i64 %15 to i32
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %7
%20 = load double, double* %6
%21 = fcmp oeq double %20, 0.000000e+00
br i1 %21, label %22, label %26
22: ; preds = %3
%23 = load double*, double** %7
%24 = load i32, i32* %8
%25 = call i32 @memset(double* %23, i8 signext 0, i32 %24)
br label %52
26: ; preds = %3
store i32 0, i32* %9
br label %27
27: ; preds = %48, %26
%28 = load i32, i32* %9
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %51
31: ; preds = %27
store i32 0, i32* %10
br label %32
32: ; preds = %44, %31
%33 = load i32, i32* %10
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %47
36: ; preds = %32
%37 = load double*, double** %7
%38 = load i32, i32* %9
%39 = load i32, i32* %10
%40 = load i32, i32* %4
%41 = load i32, i32* %5
%42 = load double, double* %6
%43 = call i32 @set(double* %37, i32 %38, i32 %39, i32 %40, i32 %41, double %42)
br label %44
44: ; preds = %36
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %32
47: ; preds = %32
br label %48
48: ; preds = %47
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %27
51: ; preds = %27
br label %52
52: ; preds = %51, %22
%53 = load double*, double** %7
ret double* %53
}

LLVM IR (-O2):
define double* @np_array(i32 %0, i32 %1, double %2) {
%4 = shl i32 %0, 3
%5 = mul i32 %4, %1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = fcmp oeq double %2, 0.000000e+00
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %25
11: ; preds = %9
%12 = icmp sgt i32 %1, 0
br label %15
13: ; preds = %3
%14 = tail call i32 @memset(double* %7, i8 signext 0, i32 %5)
br label %25
15: ; preds = %11, %17
%16 = phi i32 [ 0, %11 ], [ %18, %17 ]
br i1 %12, label %20, label %17
17: ; preds = %20, %15
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i32 %18, %0
br i1 %19, label %25, label %15
20: ; preds = %15, %20
%21 = phi i32 [ %23, %20 ], [ 0, %15 ]
%22 = tail call i32 @set(double* %7, i32 %16, i32 %21, i32 %0, i32 %1, double %2)
%23 = add nuw nsw i32 %21, 1
%24 = icmp eq i32 %23, %1
br i1 %24, label %17, label %20
25: ; preds = %17, %9, %13
ret double* %7
}