#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 */
float *arange(float, float, float, int *);
float **cartesian_product(float **, int *, int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int *zeros_i(int);
int main() {
  float **A, **B;
  int *np, *c;
  int i, j;
  bool test;
  int ndim = 1;
  int ncom;
  float plow[1] = {1};
  float phigh[1] = {4};
  float pdel[1] = {1};
  A = (float **)malloc(ndim * sizeof(float *));
  c = zeros_i(ndim);
  np = (int *)malloc(ndim * sizeof(int));
  for (i = 0; i < ndim; i++) {
    A[i] = arange(plow[i], phigh[i], pdel[i], &np[i]);
  }
  printf("Parameters\n");
  printf("==========\n");
  for (i = 0; i < ndim; i++) {
    printf("{ ");
    for (j = 0; j < np[i]; j++) {
      if (j == np[i] - 1) {
        printf("%f", A[i][j]);
      } else {
        printf("%f, ", A[i][j]);
      }
    }
    printf(" }\n");
  }
  B = cartesian_product(A, np, &ncom, ndim);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    0xe94(%rip),%eax
mov    %eax,-0x40(%rbp)
mov    0xe8f(%rip),%eax
mov    %eax,-0x44(%rbp)
mov    0xe82(%rip),%eax
mov    %eax,-0x48(%rbp)
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%edi
call   1060 <zeros_i@plt>
mov    %rax,-0x28(%rbp)
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1215 <main+0xc5>
movslq -0x2c(%rbp),%rax
movss  -0x40(%rbp,%rax,4),%xmm0
movslq -0x2c(%rbp),%rax
movss  -0x44(%rbp,%rax,4),%xmm1
movslq -0x2c(%rbp),%rax
movss  -0x48(%rbp,%rax,4),%xmm2
mov    -0x20(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1050 <arange@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ba <main+0x6a>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1308 <main+0x1b8>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x20(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    12ec <main+0x19c>
mov    -0x30(%rbp),%eax
mov    -0x20(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    (%rcx,%rdx,4),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12b2 <main+0x162>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd7d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12d9 <main+0x189>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd54(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12de <main+0x18e>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1259 <main+0x109>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1238 <main+0xe8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%ecx
lea    -0x3c(%rbp),%rdx
call   1070 <cartesian_product@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    $0x1,%edi
call   1070 <zeros_i@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
movss  0xe67(%rip),%xmm1
movss  0xe63(%rip),%xmm0
movaps %xmm0,%xmm2
mov    %rax,%rdi
call   1060 <arange@plt>
mov    %rax,(%r14)
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%eax
test   %eax,%eax
jle    121c <main+0xbc>
xor    %ebx,%ebx
lea    0xe26(%rip),%r12
lea    0xe22(%rip),%r13
nopl   0x0(%rax)
add    $0xffffffff,%eax
cmp    %rax,%rbx
mov    (%r14),%rax
movss  (%rax,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r13,%rdi
cmove  %r12,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
movslq (%r15),%rax
cmp    %rax,%rbx
jl     11f0 <main+0x90>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%ecx
call   1080 <cartesian_product@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.plow = [1 x float] [float 1.000000e+00]
@__const.main.phigh = [1 x float] [float 4.000000e+00]
@__const.main.pdel = [1 x float] [float 1.000000e+00]
@.str = [12 x i8] c"Parameters\0A\00"
@.str.1 = [12 x i8] c"==========\0A\00"
@.str.2 = [3 x i8] c"{ \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [5 x i8] c"%f, \00"
@.str.5 = [4 x i8] c" }\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float**
%3 = alloca float**
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1 x float]
%12 = alloca [1 x float]
%13 = alloca [1 x float]
store i32 0, i32* %1
store i32 1, i32* %9
%14 = bitcast [1 x float]* %11 to i8*
%15 = bitcast [1 x float]* %12 to i8*
%16 = bitcast [1 x float]* %13 to i8*
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to float**
store float** %22, float*** %2
%23 = load i32, i32* %9
%24 = call i32* @zeros_i(i32 %23)
store i32* %24, i32** %5
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %4
store i32 0, i32* %6
br label %31
31: ; preds = %57, %0
%32 = load i32, i32* %6
%33 = load i32, i32* %9
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %60
35: ; preds = %31
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1 x float], [1 x float]* %11, i64 0, i64 %37
%39 = load float, float* %38
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [1 x float], [1 x float]* %12, i64 0, i64 %41
%43 = load float, float* %42
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1 x float], [1 x float]* %13, i64 0, i64 %45
%47 = load float, float* %46
%48 = load i32*, i32** %4
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
%52 = call float* @arange(float %39, float %43, float %47, i32* %51)
%53 = load float**, float*** %2
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds float*, float** %53, i64 %55
store float* %52, float** %56
br label %57
57: ; preds = %35
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
br label %31
60: ; preds = %31
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %63
63: ; preds = %116, %60
%64 = load i32, i32* %6
%65 = load i32, i32* %9
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %119
67: ; preds = %63
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %7
br label %69
69: ; preds = %111, %67
%70 = load i32, i32* %7
%71 = load i32*, i32** %4
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
%75 = load i32, i32* %74
%76 = icmp slt i32 %70, %75
br i1 %76, label %77, label %114
77: ; preds = %69
%78 = load i32, i32* %7
%79 = load i32*, i32** %4
%80 = load i32, i32* %6
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %79, i64 %81
%83 = load i32, i32* %82
%84 = sub nsw i32 %83, 1
%85 = icmp eq i32 %78, %84
br i1 %85, label %86, label %98
86: ; preds = %77
%87 = load float**, float*** %2
%88 = load i32, i32* %6
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds float*, float** %87, i64 %89
%91 = load float*, float** %90
%92 = load i32, i32* %7
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds float, float* %91, i64 %93
%95 = load float, float* %94
%96 = fpext float %95 to double
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), double %96)
br label %110
98: ; preds = %77
%99 = load float**, float*** %2
%100 = load i32, i32* %6
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds float*, float** %99, i64 %101
%103 = load float*, float** %102
%104 = load i32, i32* %7
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds float, float* %103, i64 %105
%107 = load float, float* %106
%108 = fpext float %107 to double
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), double %108)
br label %110
110: ; preds = %98, %86
br label %111
111: ; preds = %110
%112 = load i32, i32* %7
%113 = add nsw i32 %112, 1
store i32 %113, i32* %7
br label %69
114: ; preds = %69
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %116
116: ; preds = %114
%117 = load i32, i32* %6
%118 = add nsw i32 %117, 1
store i32 %118, i32* %6
br label %63
119: ; preds = %63
%120 = load float**, float*** %2
%121 = load i32*, i32** %4
%122 = load i32, i32* %9
%123 = call float** @cartesian_product(float** %120, i32* %121, i32* %10, i32 %122)
store float** %123, float*** %3
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"{ \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [5 x i8] c"%f, \00"
@str = [11 x i8] c"Parameters\00"
@str.6 = [11 x i8] c"==========\00"
@str.7 = [3 x i8] c" }\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 @malloc(i32 8)
%4 = inttoptr i64 %3 to float**
%5 = tail call i32* @zeros_i(i32 1)
%6 = tail call i64 @malloc(i32 4)
%7 = inttoptr i64 %6 to i32*
%8 = tail call float* @arange(float 1.000000e+00, float 4.000000e+00, float 1.000000e+00, i32* %7)
store float* %8, float** %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %7
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %0, %14
%15 = phi i64 [ %26, %14 ], [ 0, %0 ]
%16 = phi i32 [ %27, %14 ], [ %12, %0 ]
%17 = add nsw i32 %16, -1
%18 = zext i32 %17 to i64
%19 = icmp eq i64 %15, %18
%20 = load float*, float** %4
%21 = getelementptr inbounds float, float* %20, i64 %15
%22 = load float, float* %21
%23 = fpext float %22 to double
%24 = select i1 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %24, double %23)
%26 = add nuw nsw i64 %15, 1
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %14, label %30
30: ; preds = %14, %0
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0))
%32 = call float** @cartesian_product(float** %4, i32* %7, i32* %1, i32 1)
ret i32 0
}