#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*/ fprintf(int /*<<< orphan*/, char *, size_t);
int /*<<< orphan*/ free(size_t *);
size_t *malloc(int);
int /*<<< orphan*/ memset(size_t *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ stderr;
bool initMatrix(size_t **matrix, size_t nbLines) {
  size_t i;
  for (i = 0; i < nbLines; i++) {
    matrix[i] = malloc(sizeof(size_t) * nbLines);
    if (!matrix[i]) {
      fprintf(stderr, "Can not allocate memory for row %zu of matrix\n", i);
      for (; i >= 0; i--)
        free(matrix[i]);
      return false;
    } else {
      memset(matrix[i], 0, nbLines);
    }
  }
  return true;
}


x86 assembly (clang, -O0):
<initMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1216 <initMatrix+0xd6>
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11e9 <initMatrix+0xa9>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
cmpq   $0x0,-0x20(%rbp)
jb     11dd <initMatrix+0x9d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11b0 <initMatrix+0x70>
movl   $0x0,-0x4(%rbp)
jmp    121d <initMatrix+0xdd>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
jmp    1205 <initMatrix+0xc5>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1158 <initMatrix+0x18>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initMatrix>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1189 <initMatrix+0x49>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x0(,%rsi,8),%ebp
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1199 <initMatrix+0x59>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
add    $0x1,%r15
add    $0x8,%rbx
cmp    %r15,%r14
jne    1160 <initMatrix+0x20>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   1030 <free@plt>
add    $0xfffffffffffffff8,%rbx
jmp    11c0 <initMatrix+0x80>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"Can not allocate memory for row %zu of matrix\0A\00"
define i32 @initMatrix(i64** %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64**
%5 = alloca i64
%6 = alloca i64
store i64** %0, i64*** %4
store i64 %1, i64* %5
store i64 0, i64* %6
br label %7
7: ; preds = %49, %2
%8 = load i64, i64* %6
%9 = load i64, i64* %5
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %52
11: ; preds = %7
%12 = load i64, i64* %5
%13 = mul i64 8, %12
%14 = trunc i64 %13 to i32
%15 = call i64* @malloc(i32 %14)
%16 = load i64**, i64*** %4
%17 = load i64, i64* %6
%18 = getelementptr inbounds i64*, i64** %16, i64 %17
store i64* %15, i64** %18
%19 = load i64**, i64*** %4
%20 = load i64, i64* %6
%21 = getelementptr inbounds i64*, i64** %19, i64 %20
%22 = load i64*, i64** %21
%23 = icmp ne i64* %22, null
br i1 %23, label %41, label %24
24: ; preds = %11
%25 = load i32, i32* @stderr
%26 = load i64, i64* %6
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %37, %24
%29 = load i64, i64* %6
%30 = icmp uge i64 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = load i64**, i64*** %4
%33 = load i64, i64* %6
%34 = getelementptr inbounds i64*, i64** %32, i64 %33
%35 = load i64*, i64** %34
%36 = call i32 @free(i64* %35)
br label %37
37: ; preds = %31
%38 = load i64, i64* %6
%39 = add i64 %38, -1
store i64 %39, i64* %6
br label %28
40: ; preds = %28
store i32 0, i32* %3
br label %53
41: ; preds = %11
%42 = load i64**, i64*** %4
%43 = load i64, i64* %6
%44 = getelementptr inbounds i64*, i64** %42, i64 %43
%45 = load i64*, i64** %44
%46 = load i64, i64* %5
%47 = call i32 @memset(i64* %45, i32 0, i64 %46)
br label %48
48: ; preds = %41
br label %49
49: ; preds = %48
%50 = load i64, i64* %6
%51 = add i64 %50, 1
store i64 %51, i64* %6
br label %7
52: ; preds = %7
store i32 1, i32* %3
br label %53
53: ; preds = %52, %40
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"Can not allocate memory for row %zu of matrix\0A\00"
define i32 @initMatrix(i64** nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %25, label %4
4: ; preds = %2
%5 = trunc i64 %1 to i32
%6 = shl i32 %5, 3
br label %7
7: ; preds = %4, %21
%8 = phi i64 [ 0, %4 ], [ %23, %21 ]
%9 = tail call i64* @malloc(i32 %6)
%10 = getelementptr inbounds i64*, i64** %0, i64 %8
store i64* %9, i64** %10
%11 = icmp eq i64* %9, null
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 %8)
br label %15
15: ; preds = %15, %12
%16 = phi i64 [ %8, %12 ], [ %20, %15 ]
%17 = getelementptr inbounds i64*, i64** %0, i64 %16
%18 = load i64*, i64** %17
%19 = tail call i32 @free(i64* %18)
%20 = add i64 %16, -1
br label %15
21: ; preds = %7
%22 = tail call i32 @memset(i64* %9, i32 0, i64 %1)
%23 = add nuw i64 %8, 1
%24 = icmp eq i64 %23, %1
br i1 %24, label %25, label %7
25: ; preds = %21, %2
ret i32 1
}