int main(void) {
  int **matrix = (int **)malloc(sizeof(int *) * 5);
  for (int i = 0; i < 5; i++) {
    matrix[i] = (int *)malloc(sizeof(int) * 5);
  }
  matrix[0][0] = 1;
  matrix[0][1] = 4;
  matrix[0][2] = 7;
  matrix[0][3] = 11;
  matrix[0][4] = 15;
  matrix[1][0] = 2;
  matrix[1][1] = 5;
  matrix[1][2] = 8;
  matrix[1][3] = 12;
  matrix[1][4] = 19;
  matrix[2][0] = 3;
  matrix[2][1] = 6;
  matrix[2][2] = 9;
  matrix[2][3] = 16;
  matrix[2][4] = 22;
  matrix[3][0] = 10;
  matrix[3][1] = 13;
  matrix[3][2] = 14;
  matrix[3][3] = 17;
  matrix[3][4] = 24;
  matrix[4][0] = 18;
  matrix[4][1] = 21;
  matrix[4][2] = 23;
  matrix[4][3] = 26;
  matrix[4][4] = 30;
  printf("%d\n", searchMatrix(matrix, 5, 5, 5));
  printf("%d\n", searchMatrix(matrix, 5, 5, 20));
  for (int i = 0; i < 5; i++) {
    free(matrix[i]);
  }
  free(matrix);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1195 <main+0x55>
mov    $0x14,%edi
call   1060 <malloc@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    1164 <main+0x24>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x4,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x7,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0xb,0xc(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0xf,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x2,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x5,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x8,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0xc,0xc(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x13,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x3,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x6,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x9,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x10,0xc(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x16,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0xa,(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0xd,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0xe,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x11,0xc(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x18,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movl   $0x12,(%rax)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movl   $0x15,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movl   $0x17,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movl   $0x1a,0xc(%rax)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movl   $0x1e,0x10(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x5,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
mov    $0x0,%al
call   1050 <searchMatrix@plt>
mov    %eax,%esi
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x5,%edx
mov    $0x14,%ecx
mov    %edx,%esi
mov    $0x0,%al
call   1050 <searchMatrix@plt>
mov    %eax,%esi
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    137d <main+0x23d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1354 <main+0x214>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,(%rbx)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x8(%rbx)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,0x10(%rbx)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %rax,0x18(%rbx)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,0x20(%rbx)
movaps 0xe52(%rip),%xmm0
movups %xmm0,(%r14)
movl   $0xf,0x10(%r14)
movaps 0xe4f(%rip),%xmm0
movups %xmm0,(%r15)
movl   $0x13,0x10(%r15)
movaps 0xe4c(%rip),%xmm0
movups %xmm0,(%r12)
movl   $0x16,0x10(%r12)
movaps 0xe47(%rip),%xmm0
movups %xmm0,0x0(%r13)
movl   $0x18,0x10(%r13)
movaps 0xe43(%rip),%xmm0
movups %xmm0,(%rax)
movl   $0x1e,0x10(%rax)
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x5,%edx
mov    $0x5,%ecx
xor    %eax,%eax
call   1050 <searchMatrix@plt>
lea    0xe29(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x5,%edx
mov    $0x14,%ecx
xor    %eax,%eax
call   1050 <searchMatrix@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    0x8(%rbx),%rdi
call   1030 <free@plt>
mov    0x10(%rbx),%rdi
call   1030 <free@plt>
mov    0x18(%rbx),%rdi
call   1030 <free@plt>
mov    0x20(%rbx),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32**
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i8* @malloc(i64 40)
%6 = bitcast i8* %5 to i32**
store i32** %6, i32*** %2
store i32 0, i32* %3
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 5
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = call i8* @malloc(i64 20)
%12 = bitcast i8* %11 to i32*
%13 = load i32**, i32*** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32*, i32** %13, i64 %15
store i32* %12, i32** %16
br label %17
17: ; preds = %10
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %7
20: ; preds = %7
%21 = load i32**, i32*** %2
%22 = getelementptr inbounds i32*, i32** %21, i64 0
%23 = load i32*, i32** %22
%24 = getelementptr inbounds i32, i32* %23, i64 0
store i32 1, i32* %24
%25 = load i32**, i32*** %2
%26 = getelementptr inbounds i32*, i32** %25, i64 0
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 1
store i32 4, i32* %28
%29 = load i32**, i32*** %2
%30 = getelementptr inbounds i32*, i32** %29, i64 0
%31 = load i32*, i32** %30
%32 = getelementptr inbounds i32, i32* %31, i64 2
store i32 7, i32* %32
%33 = load i32**, i32*** %2
%34 = getelementptr inbounds i32*, i32** %33, i64 0
%35 = load i32*, i32** %34
%36 = getelementptr inbounds i32, i32* %35, i64 3
store i32 11, i32* %36
%37 = load i32**, i32*** %2
%38 = getelementptr inbounds i32*, i32** %37, i64 0
%39 = load i32*, i32** %38
%40 = getelementptr inbounds i32, i32* %39, i64 4
store i32 15, i32* %40
%41 = load i32**, i32*** %2
%42 = getelementptr inbounds i32*, i32** %41, i64 1
%43 = load i32*, i32** %42
%44 = getelementptr inbounds i32, i32* %43, i64 0
store i32 2, i32* %44
%45 = load i32**, i32*** %2
%46 = getelementptr inbounds i32*, i32** %45, i64 1
%47 = load i32*, i32** %46
%48 = getelementptr inbounds i32, i32* %47, i64 1
store i32 5, i32* %48
%49 = load i32**, i32*** %2
%50 = getelementptr inbounds i32*, i32** %49, i64 1
%51 = load i32*, i32** %50
%52 = getelementptr inbounds i32, i32* %51, i64 2
store i32 8, i32* %52
%53 = load i32**, i32*** %2
%54 = getelementptr inbounds i32*, i32** %53, i64 1
%55 = load i32*, i32** %54
%56 = getelementptr inbounds i32, i32* %55, i64 3
store i32 12, i32* %56
%57 = load i32**, i32*** %2
%58 = getelementptr inbounds i32*, i32** %57, i64 1
%59 = load i32*, i32** %58
%60 = getelementptr inbounds i32, i32* %59, i64 4
store i32 19, i32* %60
%61 = load i32**, i32*** %2
%62 = getelementptr inbounds i32*, i32** %61, i64 2
%63 = load i32*, i32** %62
%64 = getelementptr inbounds i32, i32* %63, i64 0
store i32 3, i32* %64
%65 = load i32**, i32*** %2
%66 = getelementptr inbounds i32*, i32** %65, i64 2
%67 = load i32*, i32** %66
%68 = getelementptr inbounds i32, i32* %67, i64 1
store i32 6, i32* %68
%69 = load i32**, i32*** %2
%70 = getelementptr inbounds i32*, i32** %69, i64 2
%71 = load i32*, i32** %70
%72 = getelementptr inbounds i32, i32* %71, i64 2
store i32 9, i32* %72
%73 = load i32**, i32*** %2
%74 = getelementptr inbounds i32*, i32** %73, i64 2
%75 = load i32*, i32** %74
%76 = getelementptr inbounds i32, i32* %75, i64 3
store i32 16, i32* %76
%77 = load i32**, i32*** %2
%78 = getelementptr inbounds i32*, i32** %77, i64 2
%79 = load i32*, i32** %78
%80 = getelementptr inbounds i32, i32* %79, i64 4
store i32 22, i32* %80
%81 = load i32**, i32*** %2
%82 = getelementptr inbounds i32*, i32** %81, i64 3
%83 = load i32*, i32** %82
%84 = getelementptr inbounds i32, i32* %83, i64 0
store i32 10, i32* %84
%85 = load i32**, i32*** %2
%86 = getelementptr inbounds i32*, i32** %85, i64 3
%87 = load i32*, i32** %86
%88 = getelementptr inbounds i32, i32* %87, i64 1
store i32 13, i32* %88
%89 = load i32**, i32*** %2
%90 = getelementptr inbounds i32*, i32** %89, i64 3
%91 = load i32*, i32** %90
%92 = getelementptr inbounds i32, i32* %91, i64 2
store i32 14, i32* %92
%93 = load i32**, i32*** %2
%94 = getelementptr inbounds i32*, i32** %93, i64 3
%95 = load i32*, i32** %94
%96 = getelementptr inbounds i32, i32* %95, i64 3
store i32 17, i32* %96
%97 = load i32**, i32*** %2
%98 = getelementptr inbounds i32*, i32** %97, i64 3
%99 = load i32*, i32** %98
%100 = getelementptr inbounds i32, i32* %99, i64 4
store i32 24, i32* %100
%101 = load i32**, i32*** %2
%102 = getelementptr inbounds i32*, i32** %101, i64 4
%103 = load i32*, i32** %102
%104 = getelementptr inbounds i32, i32* %103, i64 0
store i32 18, i32* %104
%105 = load i32**, i32*** %2
%106 = getelementptr inbounds i32*, i32** %105, i64 4
%107 = load i32*, i32** %106
%108 = getelementptr inbounds i32, i32* %107, i64 1
store i32 21, i32* %108
%109 = load i32**, i32*** %2
%110 = getelementptr inbounds i32*, i32** %109, i64 4
%111 = load i32*, i32** %110
%112 = getelementptr inbounds i32, i32* %111, i64 2
store i32 23, i32* %112
%113 = load i32**, i32*** %2
%114 = getelementptr inbounds i32*, i32** %113, i64 4
%115 = load i32*, i32** %114
%116 = getelementptr inbounds i32, i32* %115, i64 3
store i32 26, i32* %116
%117 = load i32**, i32*** %2
%118 = getelementptr inbounds i32*, i32** %117, i64 4
%119 = load i32*, i32** %118
%120 = getelementptr inbounds i32, i32* %119, i64 4
store i32 30, i32* %120
%121 = load i32**, i32*** %2
%122 = call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @searchMatrix to i32 (i32**, i32, i32, i32, ...)*)(i32** %121, i32 5, i32 5, i32 5)
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %122)
%124 = load i32**, i32*** %2
%125 = call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @searchMatrix to i32 (i32**, i32, i32, i32, ...)*)(i32** %124, i32 5, i32 5, i32 20)
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %125)
store i32 0, i32* %4
br label %127
127: ; preds = %137, %20
%128 = load i32, i32* %4
%129 = icmp slt i32 %128, 5
br i1 %129, label %130, label %140
130: ; preds = %127
%131 = load i32**, i32*** %2
%132 = load i32, i32* %4
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i32*, i32** %131, i64 %133
%135 = load i32*, i32** %134
%136 = bitcast i32* %135 to i8*
br label %137
137: ; preds = %130
%138 = load i32, i32* %4
%139 = add nsw i32 %138, 1
store i32 %139, i32* %4
br label %127
140: ; preds = %127
%141 = load i32**, i32*** %2
%142 = bitcast i32** %141 to i8*
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(40) i8* @malloc(i64 40)
%2 = bitcast i8* %1 to i32**
%3 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%4 = bitcast i8* %1 to i8**
store i8* %3, i8** %4
%5 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%6 = getelementptr inbounds i32*, i32** %2, i64 1
%7 = bitcast i32** %6 to i8**
store i8* %5, i8** %7
%8 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%9 = getelementptr inbounds i32*, i32** %2, i64 2
%10 = bitcast i32** %9 to i8**
store i8* %8, i8** %10
%11 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%12 = getelementptr inbounds i32*, i32** %2, i64 3
%13 = bitcast i32** %12 to i8**
store i8* %11, i8** %13
%14 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%15 = getelementptr inbounds i32*, i32** %2, i64 4
%16 = bitcast i32** %15 to i8**
store i8* %14, i8** %16
%17 = bitcast i8* %3 to i32*
%18 = bitcast i8* %3 to <4 x i32>*
store <4 x i32> <i32 1, i32 4, i32 7, i32 11>, <4 x i32>* %18
%19 = getelementptr inbounds i32, i32* %17, i64 4
store i32 15, i32* %19
%20 = bitcast i8* %5 to i32*
%21 = bitcast i8* %5 to <4 x i32>*
store <4 x i32> <i32 2, i32 5, i32 8, i32 12>, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %20, i64 4
store i32 19, i32* %22
%23 = bitcast i8* %8 to i32*
%24 = bitcast i8* %8 to <4 x i32>*
store <4 x i32> <i32 3, i32 6, i32 9, i32 16>, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %23, i64 4
store i32 22, i32* %25
%26 = bitcast i8* %11 to i32*
%27 = bitcast i8* %11 to <4 x i32>*
store <4 x i32> <i32 10, i32 13, i32 14, i32 17>, <4 x i32>* %27
%28 = getelementptr inbounds i32, i32* %26, i64 4
store i32 24, i32* %28
%29 = bitcast i8* %14 to i32*
%30 = bitcast i8* %14 to <4 x i32>*
store <4 x i32> <i32 18, i32 21, i32 23, i32 26>, <4 x i32>* %30
%31 = getelementptr inbounds i32, i32* %29, i64 4
store i32 30, i32* %31
%32 = tail call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @searchMatrix to i32 (i32**, i32, i32, i32, ...)*)(i32** %2, i32 5, i32 5, i32 5)
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
%34 = tail call i32 (i32**, i32, i32, i32, ...) bitcast (i32 (...)* @searchMatrix to i32 (i32**, i32, i32, i32, ...)*)(i32** %2, i32 5, i32 5, i32 20)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i8*, i8** %4
tail call void @free(i8* %36)
%37 = load i8*, i8** %7
tail call void @free(i8* %37)
%38 = load i8*, i8** %10
tail call void @free(i8* %38)
%39 = load i8*, i8** %13
tail call void @free(i8* %39)
%40 = load i8*, i8** %16
tail call void @free(i8* %40)
tail call void @free(i8* %1)
ret i32 0
}