#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*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void loadmap(int type, char *path_old, int numtilex, int numtiley,
             char *path_new) {
  FILE *old;
  FILE *new;
  old = fopen(path_old, "r");
  new = fopen(path_new, "wb");
  int numtiles = numtilex * numtiley;
  char *temparray = (char *)malloc(numtiles * sizeof(char *));
  int i = 0;
  int v = 0;
  for (i = 0; i < (numtilex * numtiley); i++) {
    if (type == 0) {
      fscanf(old, "%d%*c", &v);
    } else if (type == 1) {
      fscanf(old, "%d", &v);
    } else {
      printf("error,tipo no soportado");
    }
    temparray[i] = v;
  }
  fwrite(temparray, sizeof(char), numtiles, new);
  for (i = 0; i < (numtilex * numtiley); i++) {
    printf("%d", temparray[i]);
  }
  fclose(old);
  fclose(new);
}


x86 assembly (clang, -O0):
<loadmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    125c <loadmap+0xfc>
cmpl   $0x0,-0x4(%rbp)
jne    1208 <loadmap+0xa8>
mov    -0x28(%rbp),%rdi
lea    0xe0b(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <fscanf@plt>
jmp    123e <loadmap+0xde>
cmpl   $0x1,-0x4(%rbp)
jne    122b <loadmap+0xcb>
mov    -0x28(%rbp),%rdi
lea    0xdee(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <fscanf@plt>
jmp    1239 <loadmap+0xd9>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123e <loadmap+0xde>
mov    -0x48(%rbp),%eax
mov    %al,%dl
mov    -0x40(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11d3 <loadmap+0x73>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    12b2 <loadmap+0x152>
mov    -0x40(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1278 <loadmap+0x118>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbx
mov    %ecx,%r14d
mov    %edx,%r13d
mov    %rsi,%rax
mov    %edi,%ebp
lea    0xe7d(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
imul   %r14d,%r13d
lea    0x0(,%r13,8),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
test   %r13d,%r13d
jle    1279 <loadmap+0x119>
mov    %r15,0x10(%rsp)
mov    %r13,0x8(%rsp)
mov    %r13d,%r13d
lea    0x4(%rsp),%r14
xor    %r15d,%r15d
jmp    1200 <loadmap+0xa0>
nopl   0x0(%rax)
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x4(%rsp),%eax
mov    %al,(%rbx,%r15,1)
add    $0x1,%r15
cmp    %r15,%r13
je     1234 <loadmap+0xd4>
cmp    $0x1,%ebp
je     1220 <loadmap+0xc0>
test   %ebp,%ebp
jne    11e0 <loadmap+0x80>
mov    %r12,%rdi
lea    0xdf2(%rip),%rsi
jmp    122a <loadmap+0xca>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
lea    0xde1(%rip),%rsi
mov    %r14,%rdx
call   1050 <fscanf@plt>
jmp    11ee <loadmap+0x8e>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    0x8(%rsp),%rbp
mov    %ebp,%edx
mov    0x10(%rsp),%r15
mov    %r15,%rcx
call   1080 <fwrite@plt>
test   %ebp,%ebp
jle    128c <loadmap+0x12c>
lea    0xdb0(%rip),%r14
xor    %ebp,%ebp
nopl   (%rax)
movsbl (%rbx,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1260 <loadmap+0x100>
jmp    128c <loadmap+0x12c>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r13d,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [6 x i8] c"%d%*c\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [24 x i8] c"error,tipo no soportado\00"
define void @loadmap(i32 %0, i8* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%17 = load i8*, i8** %7
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %11
%19 = load i8*, i8** %10
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %12
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = mul nsw i32 %21, %22
store i32 %23, i32* %13
%24 = load i32, i32* %13
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 8
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %14
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %15
br label %30
30: ; preds = %58, %5
%31 = load i32, i32* %15
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = mul nsw i32 %32, %33
%35 = icmp slt i32 %31, %34
br i1 %35, label %36, label %61
36: ; preds = %30
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32*, i32** %11
%41 = call i32 @fscanf(i32* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %16)
br label %51
42: ; preds = %36
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32*, i32** %11
%47 = call i32 @fscanf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %16)
br label %50
48: ; preds = %42
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
br label %51
51: ; preds = %50, %39
%52 = load i32, i32* %16
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** %14
%55 = load i32, i32* %15
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 %53, i8* %57
br label %58
58: ; preds = %51
%59 = load i32, i32* %15
%60 = add nsw i32 %59, 1
store i32 %60, i32* %15
br label %30
61: ; preds = %30
%62 = load i8*, i8** %14
%63 = load i32, i32* %13
%64 = load i32*, i32** %12
%65 = call i32 @fwrite(i8* %62, i32 1, i32 %63, i32* %64)
store i32 0, i32* %15
br label %66
66: ; preds = %80, %61
%67 = load i32, i32* %15
%68 = load i32, i32* %8
%69 = load i32, i32* %9
%70 = mul nsw i32 %68, %69
%71 = icmp slt i32 %67, %70
br i1 %71, label %72, label %83
72: ; preds = %66
%73 = load i8*, i8** %14
%74 = load i32, i32* %15
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %78)
br label %80
80: ; preds = %72
%81 = load i32, i32* %15
%82 = add nsw i32 %81, 1
store i32 %82, i32* %15
br label %66
83: ; preds = %66
%84 = load i32*, i32** %11
%85 = call i32 @fclose(i32* %84)
%86 = load i32*, i32** %12
%87 = call i32 @fclose(i32* %86)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [6 x i8] c"%d%*c\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [24 x i8] c"error,tipo no soportado\00"
define void @loadmap(i32 %0, i8* nocapture %1, i32 %2, i32 %3, i8* nocapture %4) {
%6 = alloca i32
%7 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = mul nsw i32 %3, %2
%10 = shl i32 %9, 3
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%14 = icmp sgt i32 %9, 0
br i1 %14, label %17, label %15
15: ; preds = %5
%16 = call i32 @fwrite(i8* %12, i32 1, i32 %9, i32* %8)
br label %45
17: ; preds = %5
%18 = zext i32 %9 to i64
br label %19
19: ; preds = %17, %27
%20 = phi i64 [ 0, %17 ], [ %31, %27 ]
switch i32 %0, label %25 [
i32 0, label %21
i32 1, label %23
]
21: ; preds = %19
%22 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %6)
br label %27
23: ; preds = %19
%24 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
br label %27
25: ; preds = %19
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %23, %25, %21
%28 = load i32, i32* %6
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds i8, i8* %12, i64 %20
store i8 %29, i8* %30
%31 = add nuw nsw i64 %20, 1
%32 = icmp eq i64 %31, %18
br i1 %32, label %33, label %19
33: ; preds = %27
%34 = call i32 @fwrite(i8* %12, i32 1, i32 %9, i32* %8)
br i1 %14, label %35, label %45
35: ; preds = %33
%36 = zext i32 %9 to i64
br label %37
37: ; preds = %35, %37
%38 = phi i64 [ 0, %35 ], [ %43, %37 ]
%39 = getelementptr inbounds i8, i8* %12, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %38, 1
%44 = icmp eq i64 %43, %36
br i1 %44, label %45, label %37
45: ; preds = %37, %15, %33
%46 = call i32 @fclose(i32* %7)
%47 = call i32 @fclose(i32* %8)
ret void
}