#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 fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int *read_cell_node_map_2D(char *filename, int *cells, int *cell_size) {
  int *res;
  int len, size, a, i;
  FILE *f;
  f = fopen(filename, "r");
  if (fscanf(f, "%d %d %d\n", &len, &size, &a) == -1)
    printf("Error reading file %s \n", filename);
  *cells = len;
  *cell_size = size;
  res = (int *)malloc(sizeof(int) * len * size);
  for (i = 0; i < len * size; i += size) {
    if (fscanf(f, "%d %d %d %d\n", &a, &res[i], &res[i + 1], &res[i + 2]) == -1)
      printf("Error reading file %s \n", filename);
  }
  fclose(f);
  for (i = 0; i < len * size; i++)
    res[i]--;
  return res;
}


x86 assembly (clang, -O0):
<read_cell_node_map_2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe9a(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    11af <read_cell_node_map_2D+0x5f>
mov    -0x8(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
movslq -0x28(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    126c <read_cell_node_map_2D+0x11c>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rcx
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x20(%rbp),%r8
mov    -0x30(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%r8
mov    -0x20(%rbp),%r9
mov    -0x30(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%r9
lea    0xde5(%rip),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    1259 <read_cell_node_map_2D+0x109>
mov    -0x8(%rbp),%rsi
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
jmp    125e <read_cell_node_map_2D+0x10e>
mov    -0x28(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    11e3 <read_cell_node_map_2D+0x93>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    12ad <read_cell_node_map_2D+0x15d>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0xffffffff,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    127c <read_cell_node_map_2D+0x12c>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cell_node_map_2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xea0(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x14(%rsp),%r8
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    11aa <read_cell_node_map_2D+0x5a>
lea    0xe60(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    0x10(%rsp),%edi
mov    %edi,0x0(%rbp)
mov    0xc(%rsp),%eax
mov    %eax,(%rbx)
imul   %eax,%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%eax
imul   0x10(%rsp),%eax
test   %eax,%eax
jle    1239 <read_cell_node_map_2D+0xe9>
lea    0xe41(%rip),%r12
lea    0x14(%rsp),%r13
xor    %ebp,%ebp
jmp    11ff <read_cell_node_map_2D+0xaf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0xc(%rsp),%eax
add    %eax,%ebp
imul   0x10(%rsp),%eax
cmp    %eax,%ebp
jge    1239 <read_cell_node_map_2D+0xe9>
movslq %ebp,%rax
lea    (%rbx,%rax,4),%rcx
lea    (%rbx,%rax,4),%r8
add    $0x4,%r8
lea    0x8(%rbx,%rax,4),%r9
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    11f0 <read_cell_node_map_2D+0xa0>
lea    0xdd3(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    11f0 <read_cell_node_map_2D+0xa0>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
imul   0x10(%rsp),%eax
test   %eax,%eax
jle    126b <read_cell_node_map_2D+0x11b>
xor    %eax,%eax
addl   $0xffffffff,(%rbx,%rax,4)
add    $0x1,%rax
movslq 0x10(%rsp),%rcx
movslq 0xc(%rsp),%rdx
imul   %rcx,%rdx
cmp    %rdx,%rax
jl     1250 <read_cell_node_map_2D+0x100>
mov    %rbx,%rax
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 = [10 x i8] c"%d %d %d\0A\00"
@.str.2 = [24 x i8] c"Error reading file %s \0A\00"
@.str.3 = [13 x i8] c"%d %d %d %d\0A\00"
define i32* @read_cell_node_map_2D(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%13 = load i8*, i8** %4
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
%15 = load i32*, i32** %12
%16 = call i32 (i32*, i8*, i32*, i32*, i32*, ...) @fscanf(i32* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %8, i32* %9, i32* %10)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %3
%22 = load i32, i32* %8
%23 = load i32*, i32** %5
store i32 %22, i32* %23
%24 = load i32, i32* %9
%25 = load i32*, i32** %6
store i32 %24, i32* %25
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = mul i64 4, %27
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = mul i64 %28, %30
%32 = trunc i64 %31 to i32
%33 = call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to i32*
store i32* %34, i32** %7
store i32 0, i32* %11
br label %35
35: ; preds = %63, %21
%36 = load i32, i32* %11
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = mul nsw i32 %37, %38
%40 = icmp slt i32 %36, %39
br i1 %40, label %41, label %67
41: ; preds = %35
%42 = load i32*, i32** %12
%43 = load i32*, i32** %7
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32*, i32** %7
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %47, i64 %50
%52 = load i32*, i32** %7
%53 = load i32, i32* %11
%54 = add nsw i32 %53, 2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %52, i64 %55
%57 = call i32 (i32*, i8*, i32*, i32*, i32*, ...) @fscanf(i32* %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32* %10, i32* %46, i32* %51, i32* %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %41
%60 = load i8*, i8** %4
%61 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %59, %41
br label %63
63: ; preds = %62
%64 = load i32, i32* %9
%65 = load i32, i32* %11
%66 = add nsw i32 %65, %64
store i32 %66, i32* %11
br label %35
67: ; preds = %35
%68 = load i32*, i32** %12
%69 = call i32 @fclose(i32* %68)
store i32 0, i32* %11
br label %70
70: ; preds = %83, %67
%71 = load i32, i32* %11
%72 = load i32, i32* %8
%73 = load i32, i32* %9
%74 = mul nsw i32 %72, %73
%75 = icmp slt i32 %71, %74
br i1 %75, label %76, label %86
76: ; preds = %70
%77 = load i32*, i32** %7
%78 = load i32, i32* %11
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
%81 = load i32, i32* %80
%82 = add nsw i32 %81, -1
store i32 %82, i32* %80
br label %83
83: ; preds = %76
%84 = load i32, i32* %11
%85 = add nsw i32 %84, 1
store i32 %85, i32* %11
br label %70
86: ; preds = %70
%87 = load i32*, i32** %7
ret i32* %87
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"%d %d %d\0A\00"
@.str.2 = [24 x i8] c"Error reading file %s \0A\00"
@.str.3 = [13 x i8] c"%d %d %d %d\0A\00"
define i32* @read_cell_node_map_2D(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i32*, i8*, i32*, i32*, i32*, ...) @fscanf(i32* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %3
%16 = load i32, i32* %4
store i32 %16, i32* %1
%17 = load i32, i32* %5
store i32 %17, i32* %2
%18 = shl i32 %16, 2
%19 = mul i32 %18, %17
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i32*
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = mul nsw i32 %23, %22
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %46
26: ; preds = %15, %40
%27 = phi i32 [ %42, %40 ], [ 0, %15 ]
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %21, i64 %28
%30 = add nsw i32 %27, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %21, i64 %31
%33 = add nsw i32 %27, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %21, i64 %34
%36 = call i32 (i32*, i8*, i32*, i32*, i32*, ...) @fscanf(i32* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32* %6, i32* %29, i32* %32, i32* %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %26
%39 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %40
40: ; preds = %26, %38
%41 = load i32, i32* %5
%42 = add nsw i32 %41, %27
%43 = load i32, i32* %4
%44 = mul nsw i32 %41, %43
%45 = icmp slt i32 %42, %44
br i1 %45, label %26, label %46
46: ; preds = %40, %15
%47 = call i32 @fclose(i32* %10)
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = mul nsw i32 %49, %48
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %63
52: ; preds = %46, %52
%53 = phi i64 [ %57, %52 ], [ 0, %46 ]
%54 = getelementptr inbounds i32, i32* %21, i64 %53
%55 = load i32, i32* %54
%56 = add nsw i32 %55, -1
store i32 %56, i32* %54
%57 = add nuw nsw i64 %53, 1
%58 = load i32, i32* %4
%59 = load i32, i32* %5
%60 = mul nsw i32 %59, %58
%61 = sext i32 %60 to i64
%62 = icmp slt i64 %57, %61
br i1 %62, label %52, label %63
63: ; preds = %52, %46
ret i32* %21
}