#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__ calloc(int, int);
scalar_t__ malloc(int);
int **merge_matrix_alloc(int l, int c) {
  int **M;
  int i;
  M = (int **)malloc(2 * l * sizeof(int *));
  for (i = 0; i < 2 * c; i++) {
    M[i] = (int *)calloc(sizeof(int), c);
  }
  return (M);
}


x86 assembly (clang, -O0):
<merge_matrix_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    1187 <merge_matrix_alloc+0x67>
mov    -0x8(%rbp),%esi
mov    $0x4,%edi
call   1030 <calloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <merge_matrix_alloc+0x2c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_matrix_alloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
shl    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    116a <merge_matrix_alloc+0x4a>
lea    (%r14,%r14,1),%eax
cmp    $0x2,%eax
mov    $0x1,%r12d
cmovge %eax,%r12d
xor    %ebx,%ebx
xchg   %ax,%ax
mov    $0x4,%edi
mov    %r14d,%esi
call   1030 <calloc@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <merge_matrix_alloc+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32** @merge_matrix_alloc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = mul nsw i32 2, %7
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32**
store i32** %13, i32*** %5
store i32 0, i32* %6
br label %14
14: ; preds = %27, %2
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = mul nsw i32 2, %16
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = load i32, i32* %4
%21 = call i64 @calloc(i32 4, i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = load i32**, i32*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
store i32* %22, i32** %26
br label %27
27: ; preds = %19
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %14
30: ; preds = %14
%31 = load i32**, i32*** %5
ret i32** %31
}

LLVM IR (-O2):
define i32** @merge_matrix_alloc(i32 %0, i32 %1) {
%3 = shl i32 %0, 4
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i32**
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = shl nuw i32 %1, 1
%9 = call i32 @llvm.smax.i32(i32 %8, i32 1)
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %16, %11 ]
%13 = tail call i64 @calloc(i32 4, i32 %1)
%14 = inttoptr i64 %13 to i32*
%15 = getelementptr inbounds i32*, i32** %5, i64 %12
store i32* %14, i32** %15
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, %10
br i1 %17, label %18, label %11
18: ; preds = %11, %2
ret i32** %5
}