#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 */
scalar_t__ EOF;
char **alloc_memory(long, char *, int /*<<< orphan*/ **);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free_array(char **, long);
scalar_t__ getc(int /*<<< orphan*/ *);
int process_arguments(int, char **, long *, int /*<<< orphan*/ **);
int process_input(char **, long, char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  long lines_sum = 10;
  FILE *file = NULL;
  int ARG = process_arguments(argc, argv, &lines_sum, &file);
  if (ARG != argc)
    return 1;
  if (file == NULL)
    file = stdin;
  if (lines_sum == 0) {
    while (getc(file) != EOF)
      ;
    return 0;
  }
  char **strings = alloc_memory(lines_sum, argv[3], &file);
  if (strings == NULL)
    return 1;
  int sum = process_input(strings, lines_sum, argv[3], &file);
  if (sum == -1)
    return 1;
  if (file != stdin && fclose(file) == EOF)
    fprintf(stderr, "[WARNING] Nepodarilo sa zatvorit subor \n");
  free_array(strings, lines_sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xa,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <process_arguments@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     11c5 <main+0x55>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <main+0x160>
cmpq   $0x0,-0x20(%rbp)
jne    11de <main+0x6e>
mov    0x2e11(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <main+0xa8>
jmp    11ee <main+0x7e>
mov    -0x20(%rbp),%rdi
call   1080 <getc@plt>
mov    0x2de2(%rip),%rcx
cmp    (%rcx),%rax
je     120c <main+0x9c>
jmp    11ee <main+0x7e>
movl   $0x0,-0x4(%rbp)
jmp    12d0 <main+0x160>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <alloc_memory@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1248 <main+0xd8>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <main+0x160>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    -0x20(%rbp),%rcx
call   1090 <process_input@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    127a <main+0x10a>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <main+0x160>
mov    -0x20(%rbp),%rax
mov    0x2d63(%rip),%rcx
cmp    (%rcx),%rax
je     12bc <main+0x14c>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d42(%rip),%rcx
cmp    (%rcx),%rax
jne    12bc <main+0x14c>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <free_array@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0xa,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1060 <process_arguments@plt>
mov    $0x1,%r15d
cmp    %ebp,%eax
jne    1250 <main+0xe0>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
jne    11c7 <main+0x57>
mov    0x2e29(%rip),%rax
mov    (%rax),%rdi
mov    %rdi,0x8(%rsp)
mov    0x10(%rsp),%rax
test   %rax,%rax
je     125e <main+0xee>
mov    0x18(%rbx),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1070 <alloc_memory@plt>
test   %rax,%rax
je     1250 <main+0xe0>
mov    %rax,%r14
mov    0x10(%rsp),%rsi
mov    0x18(%rbx),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1090 <process_input@plt>
cmp    $0xffffffff,%eax
je     1250 <main+0xe0>
mov    0x8(%rsp),%rdi
mov    0x2dd3(%rip),%rax
cmp    (%rax),%rdi
je     1240 <main+0xd0>
call   1030 <fclose@plt>
mov    0x2dba(%rip),%rcx
cmp    (%rcx),%rax
jne    1240 <main+0xd0>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1040 <free_array@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
call   1080 <getc@plt>
mov    0x2d76(%rip),%rbx
xor    %r15d,%r15d
nopl   (%rax)
cmp    (%rbx),%rax
je     1250 <main+0xe0>
mov    0x8(%rsp),%rdi
call   1080 <getc@plt>
jmp    1270 <main+0x100>

LLVM IR (-O0):
@stdin = global i32* null
@EOF = global i64 0
@stderr = global i32 0
@.str = [41 x i8] c"[WARNING] Nepodarilo sa zatvorit subor \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 10, i64* %6
store i32* null, i32** %7
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @process_arguments(i32 %11, i8** %12, i64* %6, i32** %7)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = load i32, i32* %4
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 1, i32* %3
br label %69
18: ; preds = %2
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i32*, i32** @stdin
store i32* %22, i32** %7
br label %23
23: ; preds = %21, %18
%24 = load i64, i64* %6
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %23
br label %27
27: ; preds = %32, %26
%28 = load i32*, i32** %7
%29 = call i64 @getc(i32* %28)
%30 = load i64, i64* @EOF
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %27
br label %27
33: ; preds = %27
store i32 0, i32* %3
br label %69
34: ; preds = %23
%35 = load i64, i64* %6
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 3
%38 = load i8*, i8** %37
%39 = call i8** @alloc_memory(i64 %35, i8* %38, i32** %7)
store i8** %39, i8*** %9
%40 = load i8**, i8*** %9
%41 = icmp eq i8** %40, null
br i1 %41, label %42, label %43
42: ; preds = %34
store i32 1, i32* %3
br label %69
43: ; preds = %34
%44 = load i8**, i8*** %9
%45 = load i64, i64* %6
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = call i32 @process_input(i8** %44, i64 %45, i8* %48, i32** %7)
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %53
52: ; preds = %43
store i32 1, i32* %3
br label %69
53: ; preds = %43
%54 = load i32*, i32** %7
%55 = load i32*, i32** @stdin
%56 = icmp ne i32* %54, %55
br i1 %56, label %57, label %65
57: ; preds = %53
%58 = load i32*, i32** %7
%59 = call i64 @fclose(i32* %58)
%60 = load i64, i64* @EOF
%61 = icmp eq i64 %59, %60
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %65
65: ; preds = %62, %57, %53
%66 = load i8**, i8*** %9
%67 = load i64, i64* %6
%68 = call i32 @free_array(i8** %66, i64 %67)
store i32 0, i32* %3
br label %69
69: ; preds = %65, %52, %42, %33, %17
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@stdin = global i32* null
@EOF = global i64 0
@stderr = global i32 0
@.str = [41 x i8] c"[WARNING] Nepodarilo sa zatvorit subor \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = bitcast i64* %3 to i8*
store i64 10, i64* %3
%6 = bitcast i32** %4 to i8*
store i32* null, i32** %4
%7 = call i32 @process_arguments(i32 %0, i8** %1, i64* %3, i32** %4)
%8 = icmp eq i32 %7, %0
br i1 %8, label %9, label %51
9: ; preds = %2
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i32*, i32** @stdin
store i32* %13, i32** %4
br label %14
14: ; preds = %12, %9
%15 = phi i32* [ %13, %12 ], [ %10, %9 ]
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = call i64 @getc(i32* %15)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %51, label %22
22: ; preds = %18, %22
%23 = load i32*, i32** %4
%24 = call i64 @getc(i32* %23)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %51, label %22
27: ; preds = %14
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = call i8** @alloc_memory(i64 %16, i8* %29, i32** %4)
%31 = icmp eq i8** %30, null
br i1 %31, label %51, label %32
32: ; preds = %27
%33 = load i64, i64* %3
%34 = load i8*, i8** %28
%35 = call i32 @process_input(i8** %30, i64 %33, i8* %34, i32** %4)
%36 = icmp eq i32 %35, -1
br i1 %36, label %51, label %37
37: ; preds = %32
%38 = load i32*, i32** %4
%39 = load i32*, i32** @stdin
%40 = icmp eq i32* %38, %39
br i1 %40, label %48, label %41
41: ; preds = %37
%42 = call i64 @fclose(i32* %38)
%43 = load i64, i64* @EOF
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %45, %41, %37
%49 = load i64, i64* %3
%50 = call i32 @free_array(i8** %30, i64 %49)
br label %51
51: ; preds = %22, %18, %27, %32, %48, %2
%52 = phi i32 [ 1, %2 ], [ 1, %27 ], [ 0, %48 ], [ 1, %32 ], [ 0, %18 ], [ 0, %22 ]
ret i32 %52
}