#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 atoi(char *);
int /*<<< orphan*/ compareValues(int **, char, int, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanAll(int *, int *, int ***);
int main(int argc, char *argv[]) {
  int rows, cols, **head, colToSort;
  char flag;
  flag = 'a';
  colToSort = 1;
  rows = 0;
  cols = 0;
  head = (int **)malloc(sizeof(int *));
  *head = (int *)malloc(sizeof(int));
  if (argc >= 2 && argv[1][1] == 'c')
    colToSort = atoi(argv[2]);
  if (argc >= 4 && argv[3][1] == 'd')
    flag = 'd';
  printf("starting scanall\n");
  scanAll(&rows, &cols, &head);
  printf("sorting the array\n");
  compareValues(head, flag, colToSort, cols, rows);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x61,-0x25(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x2,-0x8(%rbp)
jl     11d0 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x63,%eax
jne    11d0 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11f3 <main+0xa3>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    11f3 <main+0xa3>
movb   $0x64,-0x25(%rbp)
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <scanAll@plt>
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x25(%rbp),%al
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
movsbl %al,%esi
call   1030 <compareValues@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x10(%rsp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx)
mov    $0x61,%r15b
mov    $0x1,%ebx
cmp    $0x2,%ebp
jl     11cf <main+0x7f>
mov    0x8(%r14),%rax
mov    $0x1,%ebx
cmpb   $0x63,0x1(%rax)
jne    11b5 <main+0x65>
mov    0x10(%r14),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
cmp    $0x4,%ebp
jb     11cf <main+0x7f>
mov    0x18(%r14),%rax
xor    %ecx,%ecx
cmpb   $0x64,0x1(%rax)
sete   %cl
lea    (%rcx,%rcx,2),%r15d
add    $0x61,%r15d
lea    0xe2a(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1050 <scanAll@plt>
lea    0xe1b(%rip),%rdi
call   1040 <puts@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
movsbl %r15b,%esi
mov    %ebx,%edx
call   1030 <compareValues@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"starting scanall\0A\00"
@.str.1 = [19 x i8] c"sorting the array\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32**
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 97, i8* %10
store i32 1, i32* %9
store i32 0, i32* %6
store i32 0, i32* %7
%11 = call i64 @malloc(i32 8)
%12 = inttoptr i64 %11 to i32**
store i32** %12, i32*** %8
%13 = call i64 @malloc(i32 4)
%14 = inttoptr i64 %13 to i32*
%15 = load i32**, i32*** %8
store i32* %14, i32** %15
%16 = load i32, i32* %4
%17 = icmp sge i32 %16, 2
br i1 %17, label %18, label %31
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 99
br i1 %25, label %26, label %31
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %9
br label %31
31: ; preds = %26, %18, %2
%32 = load i32, i32* %4
%33 = icmp sge i32 %32, 4
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 3
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 100
br i1 %41, label %42, label %43
42: ; preds = %34
store i8 100, i8* %10
br label %43
43: ; preds = %42, %34, %31
%44 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%45 = call i32 @scanAll(i32* %6, i32* %7, i32*** %8)
%46 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%47 = load i32**, i32*** %8
%48 = load i8, i8* %10
%49 = load i32, i32* %9
%50 = load i32, i32* %7
%51 = load i32, i32* %6
%52 = call i32 @compareValues(i32** %47, i8 signext %48, i32 %49, i32 %50, i32 %51)
ret i32 0
}

LLVM IR (-O2):
@str = [17 x i8] c"starting scanall\00"
@str.2 = [18 x i8] c"sorting the array\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32*** %5 to i8*
store i32 0, i32* %3
store i32 0, i32* %4
%9 = tail call i64 @malloc(i32 8)
%10 = inttoptr i64 %9 to i32**
store i32** %10, i32*** %5
%11 = tail call i64 @malloc(i32 4)
%12 = inttoptr i64 %11 to i32*
store i32* %12, i32** %10
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %34
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 99
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
br label %24
24: ; preds = %20, %14
%25 = phi i32 [ %23, %20 ], [ 1, %14 ]
%26 = icmp ugt i32 %0, 3
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 100
%33 = select i1 %32, i8 100, i8 97
br label %34
34: ; preds = %2, %27, %24
%35 = phi i32 [ %25, %24 ], [ %25, %27 ], [ 1, %2 ]
%36 = phi i8 [ 97, %24 ], [ %33, %27 ], [ 97, %2 ]
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%38 = call i32 @scanAll(i32* %3, i32* %4, i32*** %5)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
%40 = load i32**, i32*** %5
%41 = load i32, i32* %4
%42 = load i32, i32* %3
%43 = call i32 @compareValues(i32** %40, i8 signext %36, i32 %35, i32 %41, i32 %42)
ret i32 0
}