#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*/ TaskA(int **);
int /*<<< orphan*/ TaskB(int **);
int /*<<< orphan*/ TaskC(int **);
int /*<<< orphan*/ TaskD(int **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *);
int main() {
  printf("Matura 2017 Informatyka - Zadanie 6\n");
  FILE *InputFile = fopen("dane.txt", "r");
  if (InputFile == NULL) {
    return 255;
  }
  int PixelIndex = 0;
  int CurrentIndex = 0;
  int PixelBuffer = 0;
  int **PixelStorage = (int **)malloc(200 * sizeof(*PixelStorage));
  while (CurrentIndex < 200) {
    PixelStorage[CurrentIndex] = malloc(320 * sizeof(**PixelStorage));
    while (PixelIndex < 320) {
      fscanf(InputFile, "%d", &PixelBuffer);
      PixelStorage[CurrentIndex][PixelIndex] = PixelBuffer;
      PixelIndex++;
    }
    PixelIndex = 0;
    CurrentIndex++;
  }
  TaskA(PixelStorage);
  TaskB(PixelStorage);
  TaskC(PixelStorage);
  TaskD(PixelStorage);
  fclose(InputFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
call   1060 <printf@plt>
lea    0xe73(%rip),%rdi
lea    0xe75(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d9 <main+0x49>
movl   $0xff,-0x4(%rbp)
jmp    12b0 <main+0x120>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x640,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0xc8,-0x18(%rbp)
jge    127c <main+0xec>
mov    $0x500,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
cmpl   $0x140,-0x14(%rbp)
jge    1267 <main+0xd7>
mov    -0x10(%rbp),%rdi
lea    0xdf6(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <fscanf@plt>
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1222 <main+0x92>
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11fc <main+0x6c>
mov    -0x28(%rbp),%rdi
call   1090 <TaskA@plt>
mov    -0x28(%rbp),%rdi
call   1040 <TaskB@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <TaskC@plt>
mov    -0x28(%rbp),%rdi
call   1030 <TaskD@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4f(%rip),%rdi
lea    0xe51(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1271 <main+0xe1>
mov    %rax,%r13
movl   $0x0,0xc(%rsp)
mov    $0x640,%edi
call   1080 <malloc@plt>
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
lea    0xe22(%rip),%r15
lea    0xc(%rsp),%r12
xchg   %ax,%ax
mov    $0x500,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%rax
mov    %rbx,(%rax,%rbp,8)
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <fscanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,(%rbx,%r14,4)
add    $0x1,%r14
cmp    $0x140,%r14
jne    1210 <main+0x80>
add    $0x1,%rbp
cmp    $0xc8,%rbp
jne    11f0 <main+0x60>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <TaskA@plt>
mov    %rbx,%rdi
call   1050 <TaskB@plt>
mov    %rbx,%rdi
call   10a0 <TaskC@plt>
mov    %rbx,%rdi
call   1040 <TaskD@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    1276 <main+0xe6>
mov    $0xff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Matura 2017 Informatyka - Zadanie 6\0A\00"
@.str.1 = [9 x i8] c"dane.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 255, i32* %1
br label %55
12: ; preds = %0
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%13 = call i32* @malloc(i32 1600)
%14 = bitcast i32* %13 to i32**
store i32** %14, i32*** %6
br label %15
15: ; preds = %41, %12
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 200
br i1 %17, label %18, label %44
18: ; preds = %15
%19 = call i32* @malloc(i32 1280)
%20 = load i32**, i32*** %6
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32*, i32** %20, i64 %22
store i32* %19, i32** %23
br label %24
24: ; preds = %27, %18
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 320
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i32*, i32** %2
%29 = call i32 @fscanf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%30 = load i32, i32* %5
%31 = load i32**, i32*** %6
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
%35 = load i32*, i32** %34
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %30, i32* %38
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %24
41: ; preds = %24
store i32 0, i32* %3
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %15
44: ; preds = %15
%45 = load i32**, i32*** %6
%46 = call i32 @TaskA(i32** %45)
%47 = load i32**, i32*** %6
%48 = call i32 @TaskB(i32** %47)
%49 = load i32**, i32*** %6
%50 = call i32 @TaskC(i32** %49)
%51 = load i32**, i32*** %6
%52 = call i32 @TaskD(i32** %51)
%53 = load i32*, i32** %2
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %1
br label %55
55: ; preds = %44, %11
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"dane.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
@str = [36 x i8] c"Matura 2017 Informatyka - Zadanie 6\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %29, label %5
5: ; preds = %0
%6 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%7 = tail call i32* @malloc(i32 1600)
%8 = bitcast i32* %7 to i32**
br label %9
9: ; preds = %5, %20
%10 = phi i64 [ 0, %5 ], [ %21, %20 ]
%11 = call i32* @malloc(i32 1280)
%12 = getelementptr inbounds i32*, i32** %8, i64 %10
store i32* %11, i32** %12
br label %13
13: ; preds = %9, %13
%14 = phi i64 [ 0, %9 ], [ %18, %13 ]
%15 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%16 = load i32, i32* %1
%17 = getelementptr inbounds i32, i32* %11, i64 %14
store i32 %16, i32* %17
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, 320
br i1 %19, label %20, label %13
20: ; preds = %13
%21 = add nuw nsw i64 %10, 1
%22 = icmp eq i64 %21, 200
br i1 %22, label %23, label %9
23: ; preds = %20
%24 = call i32 @TaskA(i32** %8)
%25 = call i32 @TaskB(i32** %8)
%26 = call i32 @TaskC(i32** %8)
%27 = call i32 @TaskD(i32** %8)
%28 = call i32 @fclose(i32* %3)
br label %29
29: ; preds = %0, %23
%30 = phi i32 [ 0, %23 ], [ 255, %0 ]
ret i32 %30
}