#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int read_map(int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ setbuffer(int /*<<< orphan*/, int /*<<< orphan*/ *,
                             int /*<<< orphan*/);
int shoot_laser(char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char *src_file;
  FILE *fh;
  setbuffer(stdout, NULL, 0);
  if (argc > 1) {
    src_file = argv[1];
    fh = fopen(src_file, "r");
  } else {
    fh = stdin;
  }
  if (fh == NULL) {
    fprintf(stderr, "%s: cannot access '%s'\n", "laserLANG", src_file);
    return 1;
  }
  char map[256][256];
  int rc = read_map(fh, map);
  fclose(fh);
  if (rc != 0) {
    fprintf(stderr, "%s: error in program\n", "laserLANG");
    return rc;
  }
  return shoot_laser(map);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <setbuffer@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11bc <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    11ca <main+0x6a>
mov    0x2e25(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1203 <main+0xa3>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rcx
lea    0xe19(%rip),%rsi
lea    0xe2a(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126a <main+0x10a>
mov    -0x20(%rbp),%rdi
lea    -0x10020(%rbp),%rsi
call   1030 <read_map@plt>
mov    %eax,-0x10024(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x10024(%rbp)
je     125b <main+0xfb>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
lea    0xdd4(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x10024(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    126a <main+0x10a>
lea    -0x10020(%rbp),%rdi
call   1060 <shoot_laser@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x10008,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <setbuffer@plt>
cmp    $0x2,%ebp
jl     11d9 <main+0x79>
mov    0x8(%rbx),%rbp
lea    0xe70(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     11e8 <main+0x88>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <read_map@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %ebp,%ebp
je     1210 <main+0xb0>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
lea    0xe4a(%rip),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    121a <main+0xba>
mov    0x2e08(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    11a0 <main+0x40>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
lea    0xe1b(%rip),%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebp
jmp    121a <main+0xba>
mov    %rsp,%rdi
call   1060 <shoot_laser@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x10008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@stderr = global i32 0
@.str.1 = [24 x i8] c"%s: cannot access '%s'\0A\00"
@.str.2 = [10 x i8] c"laserLANG\00"
@.str.3 = [22 x i8] c"%s: error in program\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [256 x [256 x i8]]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @stdout
%11 = call i32 @setbuffer(i32 %10, i32* null, i32 0)
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %7
br label %22
20: ; preds = %2
%21 = load i32*, i32** @stdin
store i32* %21, i32** %7
br label %22
22: ; preds = %20, %14
%23 = load i32*, i32** %7
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %6
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %46
29: ; preds = %22
%30 = load i32*, i32** %7
%31 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %8, i64 0, i64 0
%32 = bitcast [256 x i8]* %31 to i8**
%33 = call i32 @read_map(i32* %30, i8** %32)
store i32 %33, i32* %9
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %29
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* %9
store i32 %41, i32* %3
br label %46
42: ; preds = %29
%43 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %8, i64 0, i64 0
%44 = bitcast [256 x i8]* %43 to i8**
%45 = call i32 @shoot_laser(i8** %44)
store i32 %45, i32* %3
br label %46
46: ; preds = %42, %38, %25
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [2 x i8] c"r\00"
@stdin = global i32* null
@stderr = global i32 0
@.str.1 = [24 x i8] c"%s: cannot access '%s'\0A\00"
@.str.2 = [10 x i8] c"laserLANG\00"
@.str.3 = [22 x i8] c"%s: error in program\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x [256 x i8]]
%4 = load i32, i32* @stdout
%5 = tail call i32 @setbuffer(i32 %4, i32* null, i32 0)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %2
%12 = load i32*, i32** @stdin
br label %13
13: ; preds = %11, %7
%14 = phi i8* [ %9, %7 ], [ undef, %11 ]
%15 = phi i32* [ %10, %7 ], [ %12, %11 ]
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %33
20: ; preds = %13
%21 = getelementptr inbounds [256 x [256 x i8]], [256 x [256 x i8]]* %3, i64 0, i64 0, i64 0
%22 = bitcast [256 x [256 x i8]]* %3 to i8**
%23 = call i32 @read_map(i32* %15, i8** %22)
%24 = call i32 @fclose(i32* %15)
%25 = icmp eq i32 %23, 0
br i1 %25, label %29, label %26
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %31
29: ; preds = %20
%30 = call i32 @shoot_laser(i8** %22)
br label %31
31: ; preds = %29, %26
%32 = phi i32 [ %23, %26 ], [ %30, %29 ]
br label %33
33: ; preds = %31, %17
%34 = phi i32 [ 1, %17 ], [ %32, %31 ]
ret i32 %34
}