#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*/ displayMatrix(int **);
int /*<<< orphan*/ genMatrix(int **);
int getInput();
int /*<<< orphan*/ printf(char *, char *, int, char *, int, int);
int /*<<< orphan*/ puts(char *);
int searchMatrix(int, int *, int, int, int **);
int /*<<< orphan*/ sortMatrix(int, int, int **);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  srand(time(NULL));
  int array[20][20] = {0};
  int searchedNumPosition[2] = {20 * 20 - 1, 0};
  int input;
  genMatrix(array);
  puts("\nUn-sorted randomly generated matrix of values:");
  displayMatrix(array);
  sortMatrix(20, 20, array);
  puts("\nSorted previously generated matrix of values:");
  displayMatrix(array);
  puts("");
  input = getInput();
  if (searchMatrix(input, searchedNumPosition, 20, 20, array) == 1) {
    printf("\n%s %d %s [%d][%d]\n", "The number", input, "is found at position",
           searchedNumPosition[0], searchedNumPosition[1]);
  } else {
    printf("\n%s %d %s [%d][%d]\n", "The number", input,
           "is not found. Default position", searchedNumPosition[0],
           searchedNumPosition[1]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
lea    -0x650(%rbp),%rdi
xor    %esi,%esi
mov    $0x640,%edx
call   1080 <memset@plt>
mov    0xe24(%rip),%rax
mov    %rax,-0x658(%rbp)
lea    -0x650(%rbp),%rdi
call   1030 <genMatrix@plt>
lea    0xe12(%rip),%rdi
call   1040 <puts@plt>
lea    -0x650(%rbp),%rdi
call   10c0 <displayMatrix@plt>
lea    -0x650(%rbp),%rdx
mov    $0x14,%esi
mov    %esi,%edi
call   1050 <sortMatrix@plt>
lea    0xe17(%rip),%rdi
call   1040 <puts@plt>
lea    -0x650(%rbp),%rdi
call   10c0 <displayMatrix@plt>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1070 <getInput@plt>
mov    %eax,-0x65c(%rbp)
mov    -0x65c(%rbp),%edi
lea    -0x658(%rbp),%rsi
lea    -0x650(%rbp),%r8
mov    $0x14,%ecx
mov    %ecx,%edx
call   1090 <searchMatrix@plt>
cmp    $0x1,%eax
jne    12a7 <main+0x107>
mov    -0x65c(%rbp),%edx
mov    -0x658(%rbp),%r8d
mov    -0x654(%rbp),%r9d
lea    0xdd8(%rip),%rdi
lea    0xde5(%rip),%rsi
lea    0xde9(%rip),%rcx
call   1060 <printf@plt>
jmp    12d5 <main+0x135>
mov    -0x65c(%rbp),%edx
mov    -0x658(%rbp),%r8d
mov    -0x654(%rbp),%r9d
lea    0xda5(%rip),%rdi
lea    0xdb2(%rip),%rsi
lea    0xdcb(%rip),%rcx
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x658,%rsp
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   10b0 <srand@plt>
lea    0x10(%rsp),%rbx
mov    $0x640,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
movq   $0x18f,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <genMatrix@plt>
lea    0xe0d(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10d0 <displayMatrix@plt>
mov    $0x14,%edi
mov    $0x14,%esi
mov    %rbx,%rdx
call   1060 <sortMatrix@plt>
lea    0xe17(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10d0 <displayMatrix@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1080 <getInput@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x14,%edx
mov    $0x14,%ecx
mov    %rbx,%r8
call   10a0 <searchMatrix@plt>
cmp    $0x1,%eax
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%r9d
lea    0xe18(%rip),%rax
lea    0xe26(%rip),%rcx
cmove  %rax,%rcx
lea    0xde7(%rip),%rdi
lea    0xdf4(%rip),%rsi
mov    %ebp,%edx
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x658,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.searchedNumPosition = [2 x i32] [i32 399, i32 0]
@.str = [48 x i8] c"\0AUn-sorted randomly generated matrix of values:\00"
@.str.1 = [47 x i8] c"\0ASorted previously generated matrix of values:\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [20 x i8] c"\0A%s %d %s [%d][%d]\0A\00"
@.str.4 = [11 x i8] c"The number\00"
@.str.5 = [21 x i8] c"is found at position\00"
@.str.6 = [31 x i8] c"is not found. Default position\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x [20 x i32]]
%3 = alloca [2 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = bitcast [20 x [20 x i32]]* %2 to i8*
%8 = bitcast [2 x i32]* %3 to i8*
%9 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %2, i64 0, i64 0
%10 = bitcast [20 x i32]* %9 to i32**
%11 = call i32 @genMatrix(i32** %10)
%12 = call i32 @puts(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %2, i64 0, i64 0
%14 = bitcast [20 x i32]* %13 to i32**
%15 = call i32 @displayMatrix(i32** %14)
%16 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %2, i64 0, i64 0
%17 = bitcast [20 x i32]* %16 to i32**
%18 = call i32 @sortMatrix(i32 20, i32 20, i32** %17)
%19 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %2, i64 0, i64 0
%21 = bitcast [20 x i32]* %20 to i32**
%22 = call i32 @displayMatrix(i32** %21)
%23 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 (...) @getInput()
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%27 = getelementptr inbounds [20 x [20 x i32]], [20 x [20 x i32]]* %2, i64 0, i64 0
%28 = bitcast [20 x i32]* %27 to i32**
%29 = call i32 @searchMatrix(i32 %25, i32* %26, i32 20, i32 20, i32** %28)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %38
31: ; preds = %0
%32 = load i32, i32* %4
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %34, i32 %36)
br label %45
38: ; preds = %0
%39 = load i32, i32* %4
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%41 = load i32, i32* %40
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %41, i32 %43)
br label %45
45: ; preds = %38, %31
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [48 x i8] c"\0AUn-sorted randomly generated matrix of values:\00"
@.str.1 = [47 x i8] c"\0ASorted previously generated matrix of values:\00"
@.str.3 = [20 x i8] c"\0A%s %d %s [%d][%d]\0A\00"
@.str.4 = [11 x i8] c"The number\00"
@.str.5 = [21 x i8] c"is found at position\00"
@.str.6 = [31 x i8] c"is not found. Default position\00"
define i32 @main() {
%1 = alloca [20 x [20 x i32]]
%2 = alloca i64
%3 = bitcast i64* %2 to [2 x i32]*
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
%6 = bitcast [20 x [20 x i32]]* %1 to i8*
%7 = bitcast i64* %2 to i8*
store i64 399, i64* %2
%8 = bitcast [20 x [20 x i32]]* %1 to i32**
%9 = call i32 @genMatrix(i32** %8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @displayMatrix(i32** %8)
%12 = call i32 @sortMatrix(i32 20, i32 20, i32** %8)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @displayMatrix(i32** %8)
%15 = call i32 @putchar(i32 10)
%16 = call i32 (...) @getInput()
%17 = bitcast i64* %2 to i32*
%18 = call i32 @searchMatrix(i32 %16, i32* %17, i32 20, i32 20, i32** %8)
%19 = icmp eq i32 %18, 1
%20 = load i32, i32* %17
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%22 = load i32, i32* %21
%23 = select i1 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0)
%24 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %16, i8* %23, i32 %20, i32 %22)
ret i32 0
}