#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 */
char EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(char *, int);
char *parsirajUlaz(int *lengthOfInput) {
  char *S;
  FILE *fp;
  fp = fopen("ulaz.txt", "r");
  if (fp == NULL) {
    printf("ERROR reading the file!(ovo nije kompajler)");
    exit(1);
  }
  char znak = fgetc(fp);
  S = (char *)malloc(sizeof(char));
  int i = 0;
  while (znak != EOF) {
    if (znak == '\n' || znak == '\r' || znak == '\0') {
      znak = fgetc(fp);
      continue;
    }
    S[i] = znak;
    i++;
    znak = fgetc(fp);
    S = (char *)realloc(S, sizeof(char) * (i + 1));
  }
  *lengthOfInput = i + 1;
  S[*lengthOfInput - 1] = '$';
  fclose(fp);
  return S;
}


x86 assembly (clang, -O0):
<parsirajUlaz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <parsirajUlaz+0x44>
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movsbl -0x19(%rbp),%eax
mov    0x2e08(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1266 <parsirajUlaz+0xf6>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     1212 <parsirajUlaz+0xa2>
movsbl -0x19(%rbp),%eax
cmp    $0xd,%eax
je     1212 <parsirajUlaz+0xa2>
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    1223 <parsirajUlaz+0xb3>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
jmp    11d5 <parsirajUlaz+0x65>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
jmp    11d5 <parsirajUlaz+0x65>
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x24,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsirajUlaz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xe78(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     125e <parsirajUlaz+0xee>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0x2e2a(%rip),%rbp
cmp    0x0(%rbp),%bl
jne    11c8 <parsirajUlaz+0x58>
xor    %r13d,%r13d
jmp    1235 <parsirajUlaz+0xc5>
mov    %r14,0x8(%rsp)
xor    %r13d,%r13d
mov    $0x2401,%r14d
cs nopw 0x0(%rax,%rax,1)
cmp    $0xd,%bl
ja     11ff <parsirajUlaz+0x8f>
movzbl %bl,%eax
bt     %rax,%r14
jae    11ff <parsirajUlaz+0x8f>
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%rbp),%al
jne    11e0 <parsirajUlaz+0x70>
jmp    1230 <parsirajUlaz+0xc0>
mov    %bl,(%r15,%r13,1)
mov    %r13,0x10(%rsp)
add    $0x1,%r13
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%rsi
add    $0x2,%esi
mov    %r15,%rdi
call   1070 <realloc@plt>
mov    %rax,%r15
cmp    0x0(%rbp),%bl
jne    11e0 <parsirajUlaz+0x70>
jmp    1230 <parsirajUlaz+0xc0>
mov    0x8(%rsp),%r14
lea    0x1(%r13),%eax
mov    %eax,(%r14)
movslq %r13d,%rax
movb   $0x24,(%r15,%rax,1)
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda6(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"ulaz.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [44 x i8] c"ERROR reading the file!(ovo nije kompajler)\00"
@EOF = global i8 0
define i8* @parsirajUlaz(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i32
store i32* %0, i32** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = call signext i8 @fgetc(i32* %14)
store i8 %15, i8* %5
%16 = call i64 @malloc(i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %3
store i32 0, i32* %6
br label %18
18: ; preds = %39, %36, %13
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %57
24: ; preds = %18
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %36, label %28
28: ; preds = %24
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 13
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i8, i8* %5
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32, %28, %24
%37 = load i32*, i32** %4
%38 = call signext i8 @fgetc(i32* %37)
store i8 %38, i8* %5
br label %18
39: ; preds = %32
%40 = load i8, i8* %5
%41 = load i8*, i8** %3
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
%47 = load i32*, i32** %4
%48 = call signext i8 @fgetc(i32* %47)
store i8 %48, i8* %5
%49 = load i8*, i8** %3
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = mul i64 1, %52
%54 = trunc i64 %53 to i32
%55 = call i64 @realloc(i8* %49, i32 %54)
%56 = inttoptr i64 %55 to i8*
store i8* %56, i8** %3
br label %18
57: ; preds = %18
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
%60 = load i32*, i32** %2
store i32 %59, i32* %60
%61 = load i8*, i8** %3
%62 = load i32*, i32** %2
%63 = load i32, i32* %62
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %61, i64 %65
store i8 36, i8* %66
%67 = load i32*, i32** %4
%68 = call i32 @fclose(i32* %67)
%69 = load i8*, i8** %3
ret i8* %69
}

LLVM IR (-O2):
@.str = [9 x i8] c"ulaz.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [44 x i8] c"ERROR reading the file!(ovo nije kompajler)\00"
@EOF = global i8 0
define i8* @parsirajUlaz(i32* nocapture writeonly %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call signext i8 @fgetc(i32* %2)
%9 = tail call i64 @malloc(i32 1)
%10 = inttoptr i64 %9 to i8*
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %8, %11
br i1 %12, label %38, label %13
13: ; preds = %7, %23
%14 = phi i64 [ %25, %23 ], [ 0, %7 ]
%15 = phi i8 [ %26, %23 ], [ %8, %7 ]
%16 = phi i8* [ %30, %23 ], [ %10, %7 ]
br label %17
17: ; preds = %13, %19
%18 = phi i8 [ %15, %13 ], [ %20, %19 ]
switch i8 %18, label %23 [
i8 13, label %19
i8 10, label %19
i8 0, label %19
]
19: ; preds = %17, %17, %17
%20 = tail call signext i8 @fgetc(i32* %2)
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
br i1 %22, label %36, label %17
23: ; preds = %17
%24 = getelementptr inbounds i8, i8* %16, i64 %14
store i8 %18, i8* %24
%25 = add nuw i64 %14, 1
%26 = tail call signext i8 @fgetc(i32* %2)
%27 = trunc i64 %14 to i32
%28 = add i32 %27, 2
%29 = tail call i64 @realloc(i8* %16, i32 %28)
%30 = inttoptr i64 %29 to i8*
%31 = load i8, i8* @EOF
%32 = icmp eq i8 %26, %31
br i1 %32, label %33, label %13
33: ; preds = %23
%34 = inttoptr i64 %29 to i8*
%35 = trunc i64 %25 to i32
br label %38
36: ; preds = %19
%37 = trunc i64 %14 to i32
br label %38
38: ; preds = %36, %7, %33
%39 = phi i8* [ %34, %33 ], [ %10, %7 ], [ %16, %36 ]
%40 = phi i32 [ %35, %33 ], [ 0, %7 ], [ %37, %36 ]
%41 = add nsw i32 %40, 1
store i32 %41, i32* %0
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 36, i8* %43
%44 = tail call i32 @fclose(i32* %2)
ret i8* %39
}