#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__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int searchMatrix(int **, int, int, int);
int main(void) {
  int **arr = (int **)malloc(sizeof(int *) * 3);
  for (int i = 0; i < 3; i++) {
    arr[i] = (int *)malloc(sizeof(int) * 4);
    for (int j = 0; j < 4; j++) {
      arr[i][j] = i * 4 + j;
    }
  }
  printf("%d\n", searchMatrix(arr, 3, 4, 12));
  printf("%d\n", searchMatrix(arr, 3, 4, 10));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11c5 <main+0x95>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    11b2 <main+0x82>
mov    -0x14(%rbp),%edx
shl    $0x2,%edx
add    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117e <main+0x4e>
jmp    11b7 <main+0x87>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <main+0x24>
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0xc,%ecx
call   1040 <searchMatrix@plt>
mov    %eax,%esi
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0xa,%ecx
call   1040 <searchMatrix@plt>
mov    %eax,%esi
lea    0xdf4(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
movaps 0xeab(%rip),%xmm0
movups %xmm0,(%rax)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rbx)
movaps 0xea3(%rip),%xmm0
movups %xmm0,(%rax)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rbx)
movaps 0xe9b(%rip),%xmm0
movups %xmm0,(%rax)
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0xc,%ecx
call   1040 <searchMatrix@plt>
lea    0xe8a(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0xa,%ecx
call   1040 <searchMatrix@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 i64 @malloc(i32 24)
%6 = inttoptr i64 %5 to i32**
store i32** %6, i32*** %2
store i32 0, i32* %3
br label %7
7: ; preds = %37, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %40
10: ; preds = %7
%11 = call i64 @malloc(i32 16)
%12 = inttoptr i64 %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
store i32 0, i32* %4
br label %17
17: ; preds = %33, %10
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 4
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i32, i32* %3
%22 = mul nsw i32 %21, 4
%23 = load i32, i32* %4
%24 = add nsw i32 %22, %23
%25 = load i32**, i32*** %2
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32*, i32** %25, i64 %27
%29 = load i32*, i32** %28
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %24, i32* %32
br label %33
33: ; preds = %20
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %17
36: ; preds = %17
br label %37
37: ; preds = %36
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %7
40: ; preds = %7
%41 = load i32**, i32*** %2
%42 = call i32 @searchMatrix(i32** %41, i32 3, i32 4, i32 12)
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i32**, i32*** %2
%45 = call i32 @searchMatrix(i32** %44, i32 3, i32 4, i32 10)
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 24)
%2 = inttoptr i64 %1 to i32**
%3 = tail call i64 @malloc(i32 16)
%4 = inttoptr i64 %3 to i32*
store i32* %4, i32** %2
%5 = inttoptr i64 %3 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %5
%6 = tail call i64 @malloc(i32 16)
%7 = inttoptr i64 %6 to i32*
%8 = getelementptr inbounds i32*, i32** %2, i64 1
store i32* %7, i32** %8
%9 = inttoptr i64 %6 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %9
%10 = tail call i64 @malloc(i32 16)
%11 = inttoptr i64 %10 to i32*
%12 = getelementptr inbounds i32*, i32** %2, i64 2
store i32* %11, i32** %12
%13 = inttoptr i64 %10 to <4 x i32>*
store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32>* %13
%14 = tail call i32 @searchMatrix(i32** %2, i32 3, i32 4, i32 12)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = tail call i32 @searchMatrix(i32** %2, i32 3, i32 4, i32 10)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
ret i32 0
}