#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*/ SEEK_SET;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, unsigned char *, size_t);
int loadMap(char *filename, int *w, int *h, int *s, int *t, char **savemap) {
  FILE *f;
  size_t fpos;
  unsigned char buffer[1024];
  char *tmpmap;
  f = fopen(filename, "rb");
  if (f == NULL)
    return 1;
  fpos = fread(buffer, 1, 8, f);
  *w = (int)(buffer[0] | buffer[1] << 8);
  *h = (int)(buffer[2] | buffer[3] << 8);
  *s = (int)(buffer[4] | buffer[5] << 8);
  *t = (int)(buffer[6] | buffer[7] << 8);
  tmpmap = (char *)calloc(*w * *h, sizeof(char));
  if (tmpmap == NULL)
    return 1;
  fseek(f, fpos, SEEK_SET);
  fpos += fread(buffer, 1, (size_t)*w, f);
  while (!feof(f)) {
    memcpy((tmpmap + fpos - *w - 8), buffer, (size_t)*w);
    fseek(f, fpos, SEEK_SET);
    fpos += fread(buffer, 1, (size_t)*w, f);
  }
  fclose(f);
  *savemap = tmpmap;
  return 0;
}


x86 assembly (clang, -O0):
<loadMap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11be <loadMap+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    135e <loadMap+0x1ee>
lea    -0x450(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1030 <fread@plt>
mov    %rax,-0x48(%rbp)
movzbl -0x450(%rbp),%ecx
movzbl -0x44f(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x44e(%rbp),%ecx
movzbl -0x44d(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x44c(%rbp),%ecx
movzbl -0x44b(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x44a(%rbp),%ecx
movzbl -0x449(%rbp),%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
imul   (%rax),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x458(%rbp)
cmpq   $0x0,-0x458(%rbp)
jne    1278 <loadMap+0x108>
movl   $0x1,-0x4(%rbp)
jmp    135e <loadMap+0x1ee>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    0x2d59(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    -0x450(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12d0 <loadMap+0x160>
jmp    1340 <loadMap+0x1d0>
mov    -0x458(%rbp),%rdi
add    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
add    $0xfffffffffffffff8,%rdi
lea    -0x450(%rbp),%rsi
mov    -0x18(%rbp),%rax
movslq (%rax),%rdx
call   1070 <memcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    0x2cd0(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    -0x450(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    12b2 <loadMap+0x142>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x458(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadMap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %r9,%rbx
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%r15
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12bb <loadMap+0x14b>
mov    %rax,%r13
mov    %rbx,0x18(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x1,%ebx
mov    $0x8,%edx
mov    $0x1,%esi
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rax,0x10(%rsp)
movzwl 0x20(%rsp),%eax
mov    %eax,(%r15)
movzwl 0x22(%rsp),%eax
mov    %eax,0x0(%rbp)
movzwl 0x24(%rsp),%eax
mov    %eax,(%r14)
movzwl 0x26(%rsp),%eax
mov    %eax,(%r12)
mov    0x0(%rbp),%edi
imul   (%r15),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     12c0 <loadMap+0x150>
mov    %rax,0x8(%rsp)
mov    0x2dcb(%rip),%r14
mov    (%r14),%edx
mov    %r13,%rdi
mov    0x10(%rsp),%rbp
mov    %rbp,%rsi
call   1080 <fseek@plt>
movslq (%r15),%rdx
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    %r13,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    12a2 <loadMap+0x132>
add    %rbp,%rbx
mov    0x8(%rsp),%r12
add    $0xfffffffffffffff8,%r12
lea    0x20(%rsp),%rbp
nopl   (%rax)
movslq (%r15),%rdx
lea    (%r12,%rbx,1),%rdi
sub    %rdx,%rdi
mov    %rbp,%rsi
call   1070 <memcpy@plt>
mov    (%r14),%edx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <fseek@plt>
movslq (%r15),%rdx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r13,%rcx
call   1030 <fread@plt>
add    %rax,%rbx
mov    %r13,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1260 <loadMap+0xf0>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    0x18(%rsp),%rax
mov    0x8(%rsp),%rcx
mov    %rcx,(%rax)
xor    %ebx,%ebx
jmp    12c0 <loadMap+0x150>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @loadMap(i8* %0, i32* %1, i32* %2, i32* %3, i32* %4, i8** %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8**
%14 = alloca i32*
%15 = alloca i64
%16 = alloca [1024 x i8]
%17 = alloca i8*
store i8* %0, i8** %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i8** %5, i8*** %13
%18 = load i8*, i8** %8
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %14
%20 = load i32*, i32** %14
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %6
store i32 1, i32* %7
br label %123
23: ; preds = %6
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%25 = load i32*, i32** %14
%26 = call i64 @fread(i8* %24, i32 1, i64 8, i32* %25)
store i64 %26, i64* %15
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 1
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = shl i32 %32, 8
%34 = or i32 %29, %33
%35 = load i32*, i32** %9
store i32 %34, i32* %35
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 2
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 3
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = shl i32 %41, 8
%43 = or i32 %38, %42
%44 = load i32*, i32** %10
store i32 %43, i32* %44
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 4
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 5
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = shl i32 %50, 8
%52 = or i32 %47, %51
%53 = load i32*, i32** %11
store i32 %52, i32* %53
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 6
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 7
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = shl i32 %59, 8
%61 = or i32 %56, %60
%62 = load i32*, i32** %12
store i32 %61, i32* %62
%63 = load i32*, i32** %9
%64 = load i32, i32* %63
%65 = load i32*, i32** %10
%66 = load i32, i32* %65
%67 = mul nsw i32 %64, %66
%68 = call i64 @calloc(i32 %67, i32 1)
%69 = inttoptr i64 %68 to i8*
store i8* %69, i8** %17
%70 = load i8*, i8** %17
%71 = icmp eq i8* %70, null
br i1 %71, label %72, label %73
72: ; preds = %23
store i32 1, i32* %7
br label %123
73: ; preds = %23
%74 = load i32*, i32** %14
%75 = load i64, i64* %15
%76 = load i32, i32* @SEEK_SET
%77 = call i32 @fseek(i32* %74, i64 %75, i32 %76)
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%79 = load i32*, i32** %9
%80 = load i32, i32* %79
%81 = sext i32 %80 to i64
%82 = load i32*, i32** %14
%83 = call i64 @fread(i8* %78, i32 1, i64 %81, i32* %82)
%84 = load i64, i64* %15
%85 = add i64 %84, %83
store i64 %85, i64* %15
br label %86
86: ; preds = %91, %73
%87 = load i32*, i32** %14
%88 = call i32 @feof(i32* %87)
%89 = icmp ne i32 %88, 0
%90 = xor i1 %89, true
br i1 %90, label %91, label %118
91: ; preds = %86
%92 = load i8*, i8** %17
%93 = load i64, i64* %15
%94 = getelementptr inbounds i8, i8* %92, i64 %93
%95 = load i32*, i32** %9
%96 = load i32, i32* %95
%97 = sext i32 %96 to i64
%98 = sub i64 0, %97
%99 = getelementptr inbounds i8, i8* %94, i64 %98
%100 = getelementptr inbounds i8, i8* %99, i64 -8
%101 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%102 = load i32*, i32** %9
%103 = load i32, i32* %102
%104 = sext i32 %103 to i64
%105 = call i32 @memcpy(i8* %100, i8* %101, i64 %104)
%106 = load i32*, i32** %14
%107 = load i64, i64* %15
%108 = load i32, i32* @SEEK_SET
%109 = call i32 @fseek(i32* %106, i64 %107, i32 %108)
%110 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%111 = load i32*, i32** %9
%112 = load i32, i32* %111
%113 = sext i32 %112 to i64
%114 = load i32*, i32** %14
%115 = call i64 @fread(i8* %110, i32 1, i64 %113, i32* %114)
%116 = load i64, i64* %15
%117 = add i64 %116, %115
store i64 %117, i64* %15
br label %86
118: ; preds = %86
%119 = load i32*, i32** %14
%120 = call i32 @fclose(i32* %119)
%121 = load i8*, i8** %17
%122 = load i8**, i8*** %13
store i8* %121, i8** %122
store i32 0, i32* %7
br label %123
123: ; preds = %118, %72, %22
%124 = load i32, i32* %7
ret i32 %124
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
define i32 @loadMap(i8* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i8** nocapture writeonly %5) {
%7 = alloca [1024 x i8]
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %79, label %11
11: ; preds = %6
%12 = call i64 @fread(i8* %8, i32 1, i64 8, i32* %9)
%13 = load i8, i8* %8
%14 = zext i8 %13 to i32
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = shl nuw nsw i32 %17, 8
%19 = or i32 %18, %14
store i32 %19, i32* %1
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 2
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 3
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = shl nuw nsw i32 %25, 8
%27 = or i32 %26, %22
store i32 %27, i32* %2
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 4
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 5
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = shl nuw nsw i32 %33, 8
%35 = or i32 %34, %30
store i32 %35, i32* %3
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 6
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 7
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = shl nuw nsw i32 %41, 8
%43 = or i32 %42, %38
store i32 %43, i32* %4
%44 = load i32, i32* %1
%45 = load i32, i32* %2
%46 = mul nsw i32 %45, %44
%47 = tail call i64 @calloc(i32 %46, i32 1)
%48 = inttoptr i64 %47 to i8*
%49 = icmp eq i64 %47, 0
br i1 %49, label %79, label %50
50: ; preds = %11
%51 = load i32, i32* @SEEK_SET
%52 = tail call i32 @fseek(i32* %9, i64 %12, i32 %51)
%53 = load i32, i32* %1
%54 = sext i32 %53 to i64
%55 = call i64 @fread(i8* %8, i32 1, i64 %54, i32* %9)
%56 = call i32 @feof(i32* %9)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %77
58: ; preds = %50
%59 = add i64 %55, %12
%60 = getelementptr inbounds i8, i8* %48, i64 -8
br label %61
61: ; preds = %58, %61
%62 = phi i64 [ %74, %61 ], [ %59, %58 ]
%63 = load i32, i32* %1
%64 = sext i32 %63 to i64
%65 = sub nsw i64 0, %64
%66 = getelementptr inbounds i8, i8* %60, i64 %62
%67 = getelementptr inbounds i8, i8* %66, i64 %65
%68 = call i32 @memcpy(i8* %67, i8* %8, i64 %64)
%69 = load i32, i32* @SEEK_SET
%70 = call i32 @fseek(i32* %9, i64 %62, i32 %69)
%71 = load i32, i32* %1
%72 = sext i32 %71 to i64
%73 = call i64 @fread(i8* %8, i32 1, i64 %72, i32* %9)
%74 = add i64 %73, %62
%75 = call i32 @feof(i32* %9)
%76 = icmp eq i32 %75, 0
br i1 %76, label %61, label %77
77: ; preds = %61, %50
%78 = call i32 @fclose(i32* %9)
store i8* %48, i8** %5
br label %79
79: ; preds = %11, %6, %77
%80 = phi i32 [ 0, %77 ], [ 1, %6 ], [ 1, %11 ]
ret i32 %80
}