#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*/ findMinMax(double *, double *, int);
int /*<<< orphan*/ free(double *);
double *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
double *findMinMax2(double **a, double *minmax, int sizeA, int sizeB) {
  double *minmaxes = malloc(sizeA * 2 * sizeof(double));
  printf("malloc successful\n");
  for (int i = 0; i < sizeA; i++) {
    printf("row:%d:%d\n", 2 * i, 2 * sizeA);
    findMinMax(a[i], &minmaxes[i * 2], sizeB);
  }
  printf("findminmax in rows\n");
  findMinMax(minmaxes, minmax, 2 * sizeA);
  printf("find minmax in minmax\n");
  free(minmaxes);
  printf("free\n");
  return minmax;
}


x86 assembly (clang, -O0):
<findMinMax2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11dd <findMinMax2+0x9d>
mov    -0x24(%rbp),%esi
shl    $0x1,%esi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1040 <findMinMax@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1182 <findMinMax2+0x42>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
call   1040 <findMinMax@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findMinMax2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbp
lea    (%r14,%r14,1),%r12d
mov    %edx,%edi
shl    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0xe86(%rip),%rdi
call   1040 <puts@plt>
test   %r14d,%r14d
jle    11d0 <findMinMax2+0x80>
mov    %r14d,%r13d
add    %r13,%r13
xor    %r14d,%r14d
mov    0x8(%rsp),%r15
nopl   (%rax)
lea    0xe59(%rip),%rdi
mov    %r14d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp,%r14,4),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <findMinMax@plt>
add    $0x10,%r15
add    $0x2,%r14
cmp    %r14,%r13
jne    11a0 <findMinMax2+0x50>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <findMinMax@plt>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"malloc successful\0A\00"
@.str.1 = [11 x i8] c"row:%d:%d\0A\00"
@.str.2 = [20 x i8] c"findminmax in rows\0A\00"
@.str.3 = [23 x i8] c"find minmax in minmax\0A\00"
@.str.4 = [6 x i8] c"free\0A\00"
define double* @findMinMax2(double** %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double**
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
store double** %0, double*** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %7
%12 = mul nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = trunc i64 %14 to i32
%16 = call double* @malloc(i32 %15)
store double* %16, double** %9
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %10
br label %18
18: ; preds = %40, %4
%19 = load i32, i32* %10
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = load i32, i32* %10
%24 = mul nsw i32 2, %23
%25 = load i32, i32* %7
%26 = mul nsw i32 2, %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %26)
%28 = load double**, double*** %5
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = load double*, double** %9
%34 = load i32, i32* %10
%35 = mul nsw i32 %34, 2
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %33, i64 %36
%38 = load i32, i32* %8
%39 = call i32 @findMinMax(double* %32, double* %37, i32 %38)
br label %40
40: ; preds = %22
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %18
43: ; preds = %18
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%45 = load double*, double** %9
%46 = load double*, double** %6
%47 = load i32, i32* %7
%48 = mul nsw i32 2, %47
%49 = call i32 @findMinMax(double* %45, double* %46, i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%51 = load double*, double** %9
%52 = call i32 @free(double* %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%54 = load double*, double** %6
ret double* %54
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"row:%d:%d\0A\00"
@str = [18 x i8] c"malloc successful\00"
@str.5 = [19 x i8] c"findminmax in rows\00"
@str.6 = [22 x i8] c"find minmax in minmax\00"
@str.7 = [5 x i8] c"free\00"
define double* @findMinMax2(double** nocapture %0, double* returned %1, i32 %2, i32 %3) {
%5 = shl nsw i32 %2, 1
%6 = shl i32 %2, 4
%7 = tail call double* @malloc(i32 %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = zext i32 %2 to i64
br label %18
12: ; preds = %18, %4
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
%14 = tail call i32 @findMinMax(double* %7, double* %1, i32 %5)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%16 = tail call i32 @free(double* %7)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0))
ret double* %1
18: ; preds = %10, %18
%19 = phi i64 [ 0, %10 ], [ %27, %18 ]
%20 = shl nuw nsw i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %5)
%23 = getelementptr inbounds double*, double** %0, i64 %19
%24 = load double*, double** %23
%25 = getelementptr inbounds double, double* %7, i64 %20
%26 = tail call i32 @findMinMax(double* %24, double* %25, i32 %3)
%27 = add nuw nsw i64 %19, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %12, label %18
}