double **HTS_realloc_matrix(double **pp, const int x, const int y) {
  int i;
  double **p = pp;
  p = (double **)realloc(p, x * sizeof(double *));
  for (i = 0; i < x; i++)
    p[i] = (double *)realloc(p[i], y * sizeof(double));
  return p;
}


x86 assembly (clang, -O0):
<HTS_realloc_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0xc(%rbp),%rsi
shl    $0x3,%rsi
call   1030 <realloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1188 <HTS_realloc_matrix+0x78>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
movslq -0x10(%rbp),%rsi
shl    $0x3,%rsi
call   1030 <realloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <HTS_realloc_matrix+0x36>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTS_realloc_matrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
movslq %esi,%rbp
lea    0x0(,%rbp,8),%rsi
call   1030 <realloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    1159 <HTS_realloc_matrix+0x49>
movslq %r14d,%r14
shl    $0x3,%r14
mov    %r15d,%r15d
xor    %ebp,%ebp
mov    (%rbx,%rbp,8),%rdi
mov    %r14,%rsi
call   1030 <realloc@plt>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1140 <HTS_realloc_matrix+0x30>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double** @HTS_realloc_matrix(double** %0, i32 %1, i32 %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double**
store double** %0, double*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load double**, double*** %4
store double** %9, double*** %8
%10 = load double**, double*** %8
%11 = bitcast double** %10 to i8*
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = call i8* @realloc(i8* %11, i64 %14)
%16 = bitcast i8* %15 to double**
store double** %16, double*** %8
store i32 0, i32* %7
br label %17
17: ; preds = %37, %3
%18 = load i32, i32* %7
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %40
21: ; preds = %17
%22 = load double**, double*** %8
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double*, double** %22, i64 %24
%26 = load double*, double** %25
%27 = bitcast double* %26 to i8*
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 8
%31 = call i8* @realloc(i8* %27, i64 %30)
%32 = bitcast i8* %31 to double*
%33 = load double**, double*** %8
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double*, double** %33, i64 %35
store double* %32, double** %36
br label %37
37: ; preds = %21
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %17
40: ; preds = %17
%41 = load double**, double*** %8
ret double** %41
}

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