#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);
int searchMatrix(int **, int, int, int);
int main(int argc, char *argv[]) {
  int a[][4] = {{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 50}};
  int **matrix;
  matrix = (int **)malloc(3 * sizeof(int *));
  int i;
  for (i = 0; i < 3; i++) {
    matrix[i] = (int *)a + 4 * i;
  }
  int target = 1;
  printf("target = %d, bool = %d\n", target,
         searchMatrix(matrix, 1, 1, target));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x30,%edx
call   1050 <memcpy@plt>
mov    $0x18,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x3,-0x4c(%rbp)
jge    11b7 <main+0x77>
lea    -0x40(%rbp),%rdx
mov    -0x4c(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdx
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1180 <main+0x40>
movl   $0x1,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%ecx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <searchMatrix@plt>
mov    -0x54(%rbp),%esi
mov    %eax,%edx
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%r14
lea    0x10(%rsp),%rbx
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rsp,%rcx
mov    %rcx,(%rax)
mov    %rbx,0x8(%rax)
mov    %r14,0x10(%rax)
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1040 <searchMatrix@plt>
lea    0xe96(%rip),%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.a = [3 x [4 x i32]] [[4 x i32] [i32 1, i32 3, i32 5, i32 7], [4 x i32] [i32 10, i32 11, i32 16, i32 20], [4 x i32] [i32 23, i32 30, i32 34, i32 50]]
@.str = [24 x i8] c"target = %d, bool = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x [4 x i32]]
%7 = alloca i32**
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [3 x [4 x i32]]* %6 to i8*
%11 = call i64 @malloc(i32 24)
%12 = inttoptr i64 %11 to i32**
store i32** %12, i32*** %7
store i32 0, i32* %8
br label %13
13: ; preds = %27, %2
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %6, i64 0, i64 0
%18 = bitcast [4 x i32]* %17 to i32*
%19 = load i32, i32* %8
%20 = mul nsw i32 4, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %18, i64 %21
%23 = load i32**, i32*** %7
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
store i32* %22, i32** %26
br label %27
27: ; preds = %16
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %13
30: ; preds = %13
store i32 1, i32* %9
%31 = load i32, i32* %9
%32 = load i32**, i32*** %7
%33 = load i32, i32* %9
%34 = call i32 @searchMatrix(i32** %32, i32 1, i32 1, i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %34)
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [3 x [4 x i32]] [[4 x i32] [i32 1, i32 3, i32 5, i32 7], [4 x i32] [i32 10, i32 11, i32 16, i32 20], [4 x i32] [i32 23, i32 30, i32 34, i32 50]]
@.str = [24 x i8] c"target = %d, bool = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [3 x [4 x i32]]
%4 = bitcast [3 x [4 x i32]]* %3 to i8*
%5 = tail call i64 @malloc(i32 24)
%6 = inttoptr i64 %5 to i32**
%7 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0, i64 0
store i32* %7, i32** %6
%8 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0, i64 4
%9 = getelementptr inbounds i32*, i32** %6, i64 1
store i32* %8, i32** %9
%10 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0, i64 8
%11 = getelementptr inbounds i32*, i32** %6, i64 2
store i32* %10, i32** %11
%12 = call i32 @searchMatrix(i32** %6, i32 1, i32 1, i32 1)
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 1, i32 %12)
ret i32 0
}