#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*/ displayMap();
int /*<<< orphan*/ getc(int /*<<< orphan*/);
int locatePath();
int parseMap();
int /*<<< orphan*/ printf(char *, ...);
int readMap();
int /*<<< orphan*/ stdin;
int writeMap();
int main() {
  int i, j, steps = 0;
  int flag;
  flag = readMap();
  if (flag == -1) {
    printf("\nerror reading map..\naborting..\n");
    getc(stdin);
    return -1;
  }
  flag = parseMap();
  steps = locatePath();
  if (steps <= 0) {
    printf("\npath broken!!\nnothing to write in the file..\n");
  } else {
    printf("\nnumber of P's between E and X = %d\n", steps);
    flag = writeMap();
    if (flag == -1) {
      printf("\nerror writing file..\naborting..\n");
      getc(stdin);
      return -1;
    }
    displayMap();
  }
  printf("\n\npress a key to exit..\n\n");
  getc(stdin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <readMap@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c2 <main+0x52>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1090 <getc@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <main+0xfa>
mov    $0x0,%al
call   1070 <parseMap@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1080 <locatePath@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     11f3 <main+0x83>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1247 <main+0xd7>
mov    -0x10(%rbp),%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <writeMap@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1240 <main+0xd0>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1090 <getc@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <main+0xfa>
mov    $0x0,%al
call   1060 <displayMap@plt>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1090 <getc@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <readMap@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     11c9 <main+0x49>
xor    %eax,%eax
call   1080 <parseMap@plt>
xor    %eax,%eax
call   1090 <locatePath@plt>
test   %eax,%eax
jle    11d2 <main+0x52>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <writeMap@plt>
cmp    $0xffffffff,%eax
je     11e9 <main+0x69>
xor    %eax,%eax
call   1070 <displayMap@plt>
jmp    11de <main+0x5e>
lea    0xebd(%rip),%rdi
jmp    11f0 <main+0x70>
lea    0xe86(%rip),%rdi
call   1040 <puts@plt>
lea    0xe40(%rip),%rdi
xor    %ebx,%ebx
jmp    11f0 <main+0x70>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   10a0 <getc@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"\0Aerror reading map..\0Aaborting..\0A\00"
@stdin = global i32 0
@.str.1 = [47 x i8] c"\0Apath broken!!\0Anothing to write in the file..\0A\00"
@.str.2 = [37 x i8] c"\0Anumber of P's between E and X = %d\0A\00"
@.str.3 = [34 x i8] c"\0Aerror writing file..\0Aaborting..\0A\00"
@.str.4 = [26 x i8] c"\0A\0Apress a key to exit..\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%6 = call i32 (...) @readMap()
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdin
%12 = call i32 @getc(i32 %11)
store i32 -1, i32* %1
br label %36
13: ; preds = %0
%14 = call i32 (...) @parseMap()
store i32 %14, i32* %5
%15 = call i32 (...) @locatePath()
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %32
20: ; preds = %13
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 (...) @writeMap()
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = call i32 @getc(i32 %28)
store i32 -1, i32* %1
br label %36
30: ; preds = %20
%31 = call i32 (...) @displayMap()
br label %32
32: ; preds = %30, %18
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = call i32 @getc(i32 %34)
store i32 0, i32* %1
br label %36
36: ; preds = %32, %26, %9
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.2 = [37 x i8] c"\0Anumber of P's between E and X = %d\0A\00"
@str = [25 x i8] c"\0A\0Apress a key to exit..\0A\00"
@str.5 = [33 x i8] c"\0Aerror writing file..\0Aaborting..\00"
@str.6 = [46 x i8] c"\0Apath broken!!\0Anothing to write in the file..\00"
@str.7 = [32 x i8] c"\0Aerror reading map..\0Aaborting..\00"
define i32 @main() {
%1 = tail call i32 (...) @readMap()
%2 = icmp eq i32 %1, -1
br i1 %2, label %15, label %3
3: ; preds = %0
%4 = tail call i32 (...) @parseMap()
%5 = tail call i32 (...) @locatePath()
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.6, i64 0, i64 0))
br label %15
9: ; preds = %3
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%11 = tail call i32 (...) @writeMap()
%12 = icmp eq i32 %11, -1
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 (...) @displayMap()
br label %15
15: ; preds = %7, %13, %9, %0
%16 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0), %0 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0), %13 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0), %7 ]
%17 = phi i32 [ -1, %0 ], [ -1, %9 ], [ 0, %13 ], [ 0, %7 ]
%18 = tail call i32 @puts(i8* dereferenceable(1) %16)
%19 = load i32, i32* @stdin
%20 = tail call i32 @getc(i32 %19)
ret i32 %17
}