#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*/ addRow(int **, int *, int ****, char *);
int countCols(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int isValidRow(int, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stdin;
int scanAll(int *numRows, int *numCols, int ***head) {
  char *line;
  line = (char *)malloc(sizeof(char) * 201);
  fgets(line, 201, stdin);
  *numCols = countCols(line);
  addRow(&numRows, numCols, &head, line);
  int counter;
  for (counter = 0; counter < 100; ++counter) {
    fgets(line, 201, stdin);
    if (1 == isValidRow(*numCols, line))
      addRow(&numRows, numCols, &head, line);
  }
  free(line);
  return 1;
}


x86 assembly (clang, -O0):
<scanAll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0xc9,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    $0xc9,%esi
call   1050 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1070 <countCols@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rdx
call   1040 <addRow@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    122d <scanAll+0xcd>
mov    -0x20(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    $0xc9,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
call   1080 <isValidRow@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    121a <scanAll+0xba>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rdx
call   1040 <addRow@plt>
jmp    121f <scanAll+0xbf>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c6 <scanAll+0x66>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scanAll>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    $0xc9,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x2e59(%rip),%r13
mov    0x0(%r13),%edx
mov    %rax,%rdi
mov    $0xc9,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1070 <countCols@plt>
mov    %eax,(%r14)
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <addRow@plt>
mov    $0x64,%ebp
jmp    11d5 <scanAll+0x75>
nopl   (%rax)
add    $0xffffffff,%ebp
je     1209 <scanAll+0xa9>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0xc9,%esi
call   1050 <fgets@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
call   1080 <isValidRow@plt>
cmp    $0x1,%eax
jne    11d0 <scanAll+0x70>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <addRow@plt>
jmp    11d0 <scanAll+0x70>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @scanAll(i32* %0, i32* %1, i32*** %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32***
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32*** %2, i32**** %6
%9 = call i64 @malloc(i32 201)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 201, i32 %12)
%14 = load i8*, i8** %7
%15 = call i32 @countCols(i8* %14)
%16 = load i32*, i32** %5
store i32 %15, i32* %16
%17 = load i32*, i32** %5
%18 = load i8*, i8** %7
%19 = call i32 @addRow(i32** %4, i32* %17, i32**** %6, i8* %18)
store i32 0, i32* %8
br label %20
20: ; preds = %37, %3
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 100
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i8*, i8** %7
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %24, i32 201, i32 %25)
%27 = load i32*, i32** %5
%28 = load i32, i32* %27
%29 = load i8*, i8** %7
%30 = call i32 @isValidRow(i32 %28, i8* %29)
%31 = icmp eq i32 1, %30
br i1 %31, label %32, label %36
32: ; preds = %23
%33 = load i32*, i32** %5
%34 = load i8*, i8** %7
%35 = call i32 @addRow(i32** %4, i32* %33, i32**** %6, i8* %34)
br label %36
36: ; preds = %32, %23
br label %37
37: ; preds = %36
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %20
40: ; preds = %20
%41 = load i8*, i8** %7
%42 = call i32 @free(i8* %41)
ret i32 1
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @scanAll(i32* %0, i32* %1, i32*** %2) {
%4 = alloca i32*
%5 = alloca i32***
store i32* %0, i32** %4
store i32*** %2, i32**** %5
%6 = tail call i64 @malloc(i32 201)
%7 = inttoptr i64 %6 to i8*
%8 = load i32, i32* @stdin
%9 = tail call i32 @fgets(i8* %7, i32 201, i32 %8)
%10 = tail call i32 @countCols(i8* %7)
store i32 %10, i32* %1
%11 = call i32 @addRow(i32** %4, i32* %1, i32**** %5, i8* %7)
br label %12
12: ; preds = %3, %21
%13 = phi i32 [ 0, %3 ], [ %22, %21 ]
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %7, i32 201, i32 %14)
%16 = load i32, i32* %1
%17 = call i32 @isValidRow(i32 %16, i8* %7)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @addRow(i32** %4, i32* %1, i32**** %5, i8* %7)
br label %21
21: ; preds = %12, %19
%22 = add nuw nsw i32 %13, 1
%23 = icmp eq i32 %22, 100
br i1 %23, label %24, label %12
24: ; preds = %21
%25 = call i32 @free(i8* %7)
ret i32 1
}