#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free_maze(char **, int);
int /*<<< orphan*/ print_directions(char **, int, int);
int /*<<< orphan*/ print_maze(char **, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_and_alloc_maze(char **, int /*<<< orphan*/ *, int *,
                                       int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  FILE *input = (argc == 1 ? stdin : fopen(argv[1], "r"));
  char *maze[100] = {NULL};
  int w = 0, h = 0;
  read_and_alloc_maze(maze, input, &w, &h);
  fclose(input);
  if (h < 3 || w < 3) {
    fprintf(stderr, "Maze is too small.  Minimum is 3x3 characters.\n");
    free_maze(maze, h);
    return EXIT_FAILURE;
  }
  print_directions(maze, w, h);
  printf("\n--------------------------------------\n");
  print_maze(maze, w, h);
  free_maze(maze, h);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c9 <main+0x39>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x350(%rbp)
jmp    11e4 <main+0x54>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe28(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x350(%rbp)
mov    -0x350(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x340(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1050 <memset@plt>
movl   $0x0,-0x344(%rbp)
movl   $0x0,-0x348(%rbp)
lea    -0x340(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x344(%rbp),%rdx
lea    -0x348(%rbp),%rcx
call   1080 <read_and_alloc_maze@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x3,-0x348(%rbp)
jl     1257 <main+0xc7>
cmpl   $0x3,-0x344(%rbp)
jge    128f <main+0xff>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x340(%rbp),%rdi
mov    -0x348(%rbp),%esi
call   1070 <free_maze@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e9 <main+0x159>
lea    -0x340(%rbp),%rdi
mov    -0x344(%rbp),%esi
mov    -0x348(%rbp),%edx
call   1090 <print_directions@plt>
lea    0xd84(%rip),%rdi
call   1040 <printf@plt>
lea    -0x340(%rbp),%rdi
mov    -0x344(%rbp),%esi
mov    -0x348(%rbp),%edx
call   10b0 <print_maze@plt>
lea    -0x340(%rbp),%rdi
mov    -0x348(%rbp),%esi
call   1070 <free_maze@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x338,%rsp
cmp    $0x1,%edi
jne    11ab <main+0x1b>
mov    0x2e42(%rip),%rax
mov    (%rax),%rbx
jmp    11be <main+0x2e>
mov    0x8(%rsi),%rdi
lea    0xe4a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    $0x320,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <read_and_alloc_maze@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%edx
cmp    $0x3,%edx
jl     1243 <main+0xb3>
mov    0xc(%rsp),%esi
cmp    $0x2,%esi
jle    1243 <main+0xb3>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <print_directions@plt>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
call   10b0 <print_maze@plt>
mov    0x2d87(%rip),%rbx
jmp    125f <main+0xcf>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d71(%rip),%rbx
mov    0x8(%rsp),%esi
lea    0x10(%rsp),%rdi
call   1070 <free_maze@plt>
mov    (%rbx),%eax
add    $0x338,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Maze is too small. Minimum is 3x3 characters.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [41 x i8] c"\0A--------------------------------------\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [100 x i8*]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32*, i32** @stdin
br label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %14, %12
%20 = phi i32* [ %13, %12 ], [ %18, %14 ]
store i32* %20, i32** %6
%21 = bitcast [100 x i8*]* %7 to i8*
store i32 0, i32* %8
store i32 0, i32* %9
%22 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 0
%23 = load i32*, i32** %6
%24 = call i32 @read_and_alloc_maze(i8** %22, i32* %23, i32* %8, i32* %9)
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 3
br i1 %28, label %32, label %29
29: ; preds = %19
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 3
br i1 %31, label %32, label %39
32: ; preds = %29, %19
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%35 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 0
%36 = load i32, i32* %9
%37 = call i32 @free_maze(i8** %35, i32 %36)
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %3
br label %53
39: ; preds = %29
%40 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 0
%41 = load i32, i32* %8
%42 = load i32, i32* %9
%43 = call i32 @print_directions(i8** %40, i32 %41, i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%45 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 0
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = call i32 @print_maze(i8** %45, i32 %46, i32 %47)
%49 = getelementptr inbounds [100 x i8*], [100 x i8*]* %7, i64 0, i64 0
%50 = load i32, i32* %9
%51 = call i32 @free_maze(i8** %49, i32 %50)
%52 = load i32, i32* @EXIT_SUCCESS
store i32 %52, i32* %3
br label %53
53: ; preds = %39, %32
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Maze is too small. Minimum is 3x3 characters.\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [40 x i8] c"\0A--------------------------------------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8*]
%4 = alloca i32
%5 = alloca i32
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = load i32*, i32** @stdin
br label %13
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %9, %7
%14 = phi i32* [ %8, %7 ], [ %12, %9 ]
%15 = bitcast [100 x i8*]* %3 to i8*
%16 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%17 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%18 = getelementptr inbounds [100 x i8*], [100 x i8*]* %3, i64 0, i64 0
%19 = call i32 @read_and_alloc_maze(i8** %18, i32* %14, i32* %4, i32* %5)
%20 = call i32 @fclose(i32* %14)
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 3
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 3
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %29
26: ; preds = %13
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %35
29: ; preds = %13
%30 = call i32 @print_directions(i8** %18, i32 %23, i32 %21)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = call i32 @print_maze(i8** %18, i32 %32, i32 %33)
br label %35
35: ; preds = %29, %26
%36 = phi i32* [ @EXIT_FAILURE, %26 ], [ @EXIT_SUCCESS, %29 ]
%37 = load i32, i32* %5
%38 = call i32 @free_maze(i8** %18, i32 %37)
%39 = load i32, i32* %36
ret i32 %39
}