#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 /*<<< orphan*/ free(double *);
size_t ind2D(int, int, int, int);
double *make2Darray(int, int);
double *reduce2Darray(double *array, int old_nrow, int old_ncol, int new_nrow,
                      int new_ncol) {
  double *tmp_array = make2Darray(new_nrow, new_ncol);
  int ii, jj;
  for (ii = 0; ii < new_nrow; ii++) {
    for (jj = 0; ii < new_ncol; jj++) {
      tmp_array[ind2D(ii, jj, new_nrow, new_ncol)] =
          array[ind2D(ii, jj, old_nrow, old_ncol)];
    }
  }
  free(array);
  return tmp_array;
}


x86 assembly (clang, -O0):
<reduce2Darray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <make2Darray@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f3 <reduce2Darray+0xc3>
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e0 <reduce2Darray+0xb0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1040 <ind2D@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <ind2D@plt>
movsd  -0x38(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1172 <reduce2Darray+0x42>
jmp    11e5 <reduce2Darray+0xb5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115f <reduce2Darray+0x2f>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reduce2Darray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r13
mov    %ecx,%edi
mov    %r8d,%esi
call   1050 <make2Darray@plt>
test   %r12d,%r12d
jle    116e <reduce2Darray+0x3e>
xor    %r14d,%r14d
nopl   (%rax)
cmp    %r15d,%r14d
jl     118b <reduce2Darray+0x5b>
add    $0x1,%r14d
cmp    %r14d,%r12d
jne    1160 <reduce2Darray+0x30>
mov    %r13,%rdi
mov    %rax,%rbx
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,0xc(%rsp)
mov    %r15d,0x8(%rsp)
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %rax,%r12
call   1040 <ind2D@plt>
movsd  0x0(%r13,%rax,8),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r14d,%edi
mov    %r15d,%esi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
call   1040 <ind2D@plt>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r12,%rax,8)
mov    %r12,%rax
add    $0x1,%r15d
jmp    11a0 <reduce2Darray+0x70>

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

LLVM IR (-O2):
define double* @reduce2Darray(double* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call double* @make2Darray(i32 %3, i32 %4)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %22
8: ; preds = %5, %19
%9 = phi i32 [ %20, %19 ], [ 0, %5 ]
%10 = icmp slt i32 %9, %4
br i1 %10, label %11, label %19
11: ; preds = %8, %11
%12 = phi i32 [ %18, %11 ], [ 0, %8 ]
%13 = tail call i64 @ind2D(i32 %9, i32 %12, i32 %1, i32 %2)
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = tail call i64 @ind2D(i32 %9, i32 %12, i32 %3, i32 %4)
%17 = getelementptr inbounds double, double* %6, i64 %16
store double %15, double* %17
%18 = add nuw nsw i32 %12, 1
br label %11
19: ; preds = %8
%20 = add nuw nsw i32 %9, 1
%21 = icmp eq i32 %20, %3
br i1 %21, label %22, label %8
22: ; preds = %19, %5
%23 = tail call i32 @free(double* %0)
ret double* %6
}