#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, char *);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int main() {
  char linija[81], *c;
  FILE *vlezna, *izlezna;
  if ((vlezna = fopen("vlezna.txt", "r")) == NULL) {
    printf("Datotekata %s ne mozhe da se otvori.\n", "vlezna.txt");
    return -1;
  }
  if ((izlezna = fopen("izlezna.txt", "w")) == NULL) {
    printf("Datotekata %s ne mozhe da se otvori.\n", "izlezna.txt");
    return -1;
  }
  while ((fgets(linija, 81, vlezna)) != NULL) {
    int br = strlen(linija);
    fprintf(izlezna, "%d\n%s", br, linija);
  }
  fclose(vlezna);
  fclose(izlezna);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
jne    11b2 <main+0x52>
lea    0xe73(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <main+0xf4>
lea    0xe7a(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmp    $0x0,%rax
jne    11f2 <main+0x92>
lea    0xe33(%rip),%rdi
lea    0xe52(%rip),%rsi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1254 <main+0xf4>
jmp    11f7 <main+0x97>
lea    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%rdx
mov    $0x51,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     123b <main+0xdb>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x7c(%rbp),%edx
lea    -0x60(%rbp),%rcx
lea    0xe10(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11f7 <main+0x97>
mov    -0x70(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1201 <main+0xa1>
mov    %rax,%r15
lea    0xea6(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1211 <main+0xb1>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x51,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11ed <main+0x8d>
mov    %rsp,%rbx
lea    0xe81(%rip),%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    $0x51,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1229 <main+0xc9>
lea    0xe05(%rip),%rdi
lea    0xdf1(%rip),%rsi
jmp    121f <main+0xbf>
lea    0xdf5(%rip),%rdi
lea    0xe14(%rip),%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"vlezna.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [38 x i8] c"Datotekata %s ne mozhe da se otvori.\0A\00"
@.str.3 = [12 x i8] c"izlezna.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [6 x i8] c"%d\0A%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [81 x i8]
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %34
11: ; preds = %0
%12 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %12, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %34
16: ; preds = %11
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%19 = load i32*, i32** %4
%20 = call i32* @fgets(i8* %18, i32 81, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %6
%25 = load i32*, i32** %5
%26 = load i32, i32* %6
%27 = getelementptr inbounds [81 x i8], [81 x i8]* %2, i64 0, i64 0
%28 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %26, i8* %27)
br label %17
29: ; preds = %17
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
%32 = load i32*, i32** %5
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %1
br label %34
34: ; preds = %29, %14, %9
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [11 x i8] c"vlezna.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [38 x i8] c"Datotekata %s ne mozhe da se otvori.\0A\00"
@.str.3 = [12 x i8] c"izlezna.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [6 x i8] c"%d\0A%s\00"
define i32 @main() {
%1 = alloca [81 x i8]
%2 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %23
7: ; preds = %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i32* @fgets(i8* %2, i32 81, i32* %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %20, label %15
13: ; preds = %7
%14 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %23
15: ; preds = %10, %15
%16 = call i32 @strlen(i8* %2)
%17 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %16, i8* %2)
%18 = call i32* @fgets(i8* %2, i32 81, i32* %3)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %15
20: ; preds = %15, %10
%21 = call i32 @fclose(i32* %3)
%22 = call i32 @fclose(i32* %8)
br label %23
23: ; preds = %20, %13, %5
%24 = phi i32 [ -1, %5 ], [ -1, %13 ], [ 0, %20 ]
ret i32 %24
}