#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*/ enc;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int dekodovat(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char enc[65536];
  char dec[65536] = {
      '\0',
  };
  if (argc != 3) {
    printf("Program se spousti program.exe in.txt out.txt\n");
    return -1;
  }
  FILE *input = fopen(argv[1], "r");
  FILE *output = fopen(argv[2], "w");
  if (input == NULL) {
    fclose(input);
    fclose(output);
    printf("Vstupni soubor neexistuje!\n");
    return -2;
  }
  if (input == NULL) {
    fclose(input);
    fclose(output);
    printf("Vystupni soubor nelze zalozit!\n");
    return -3;
  }
  for (int i = 0; i < sizeof(enc); i++) {
    char c = fgetc(input);
    if (c == EOF)
      break;
    enc[i] = c;
  }
  printf("Dekoduji zpravu... ");
  if (dekodovat(enc, dec) == -1) {
    fclose(input);
    fclose(output);
    printf("Neplatny format!\n");
    return -4;
  }
  printf("OK\n");
  fprintf(output, "%s", dec);
  printf("Zprava je ulozena v %s\n", argv[2]);
  fclose(input);
  fclose(output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20010(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1050 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
je     11c0 <main+0x50>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a4 <main+0x234>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe60(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20018(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20020(%rbp)
cmpq   $0x0,-0x20018(%rbp)
jne    1236 <main+0xc6>
mov    -0x20018(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20020(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    13a4 <main+0x234>
cmpq   $0x0,-0x20018(%rbp)
jne    1276 <main+0x106>
mov    -0x20018(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20020(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    13a4 <main+0x234>
movl   $0x0,-0x20024(%rbp)
movslq -0x20024(%rbp),%rax
cmp    $0x10000,%rax
jae    12eb <main+0x17b>
mov    -0x20018(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x20025(%rbp)
movsbl -0x20025(%rbp),%eax
mov    0x2d35(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12c3 <main+0x153>
jmp    12eb <main+0x17b>
mov    -0x20025(%rbp),%cl
movslq -0x20024(%rbp),%rax
mov    %cl,-0x10010(%rbp,%rax,1)
mov    -0x20024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20024(%rbp)
jmp    1280 <main+0x110>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10010(%rbp),%rdi
lea    -0x20010(%rbp),%rsi
call   1080 <dekodovat@plt>
cmp    $0xffffffff,%eax
jne    1347 <main+0x1d7>
mov    -0x20018(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20020(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    13a4 <main+0x234>
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20020(%rbp),%rdi
lea    -0x20010(%rbp),%rdx
lea    0xd2f(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20018(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20020(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20000,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x10000,%edx
xor    %esi,%esi
call   1070 <memset@plt>
cmp    $0x3,%ebx
jne    1272 <main+0xf2>
mov    0x8(%r15),%rdi
lea    0xe49(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r15),%rdi
lea    0xe38(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1285 <main+0x105>
xor    %ebp,%ebp
mov    0x2e04(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1080 <fgetc@plt>
cmp    (%r12),%al
je     1212 <main+0x92>
mov    %al,0x10000(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    $0x10000,%rbp
jne    11f0 <main+0x70>
lea    0xdeb(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10000(%rsp),%rdi
mov    %rsp,%rsi
call   1090 <dekodovat@plt>
cmp    $0xffffffff,%eax
je     12a7 <main+0x127>
lea    0xdf2(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1060 <fputs@plt>
mov    0x10(%r15),%rsi
lea    0xdbf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    12c8 <main+0x148>
lea    0xde6(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    12c8 <main+0x148>
xor    %edi,%edi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xda9(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebp
jmp    12c8 <main+0x148>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xd75(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffc,%ebp
mov    %ebp,%eax
add    $0x20000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Program se spousti program.exe in.txt out.txt\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [28 x i8] c"Vstupni soubor neexistuje!\0A\00"
@.str.4 = [32 x i8] c"Vystupni soubor nelze zalozit!\0A\00"
@EOF = global i8 0
@.str.5 = [20 x i8] c"Dekoduji zpravu... \00"
@.str.6 = [18 x i8] c"Neplatny format!\0A\00"
@.str.7 = [4 x i8] c"OK\0A\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [24 x i8] c"Zprava je ulozena v %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [65536 x i8]
%7 = alloca [65536 x i8]
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [65536 x i8]* %7 to i8*
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %90
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %9
%26 = load i32*, i32** %8
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %34
28: ; preds = %17
%29 = load i32*, i32** %8
%30 = call i32 @fclose(i32* %29)
%31 = load i32*, i32** %9
%32 = call i32 @fclose(i32* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 -2, i32* %3
br label %90
34: ; preds = %17
%35 = load i32*, i32** %8
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
%40 = load i32*, i32** %9
%41 = call i32 @fclose(i32* %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
store i32 -3, i32* %3
br label %90
43: ; preds = %34
store i32 0, i32* %10
br label %44
44: ; preds = %62, %43
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = icmp ult i64 %46, 65536
br i1 %47, label %48, label %65
48: ; preds = %44
%49 = load i32*, i32** %8
%50 = call signext i8 @fgetc(i32* %49)
store i8 %50, i8* %11
%51 = load i8, i8* %11
%52 = sext i8 %51 to i32
%53 = load i8, i8* @EOF
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %52, %54
br i1 %55, label %56, label %57
56: ; preds = %48
br label %65
57: ; preds = %48
%58 = load i8, i8* %11
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 %60
store i8 %58, i8* %61
br label %62
62: ; preds = %57
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %44
65: ; preds = %56, %44
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%67 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%68 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%69 = call i32 @dekodovat(i8* %67, i8* %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %77
71: ; preds = %65
%72 = load i32*, i32** %8
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %9
%75 = call i32 @fclose(i32* %74)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
store i32 -4, i32* %3
br label %90
77: ; preds = %65
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%79 = load i32*, i32** %9
%80 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%81 = call i32 @fprintf(i32* %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %80)
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 2
%84 = load i8*, i8** %83
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %84)
%86 = load i32*, i32** %8
%87 = call i32 @fclose(i32* %86)
%88 = load i32*, i32** %9
%89 = call i32 @fclose(i32* %88)
store i32 0, i32* %3
br label %90
90: ; preds = %77, %71, %37, %28, %15
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
@.str.5 = [20 x i8] c"Dekoduji zpravu... \00"
@.str.9 = [24 x i8] c"Zprava je ulozena v %s\0A\00"
@str = [3 x i8] c"OK\00"
@str.10 = [17 x i8] c"Neplatny format!\00"
@str.11 = [27 x i8] c"Vstupni soubor neexistuje!\00"
@str.12 = [46 x i8] c"Program se spousti program.exe in.txt out.txt\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65536 x i8]
%4 = alloca [65536 x i8]
%5 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.12, i64 0, i64 0))
br label %46
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %13, null
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = tail call i32 @fclose(i32* null)
%20 = tail call i32 @fclose(i32* %16)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.11, i64 0, i64 0))
br label %46
22: ; preds = %10, %27
%23 = phi i64 [ %29, %27 ], [ 0, %10 ]
%24 = tail call signext i8 @fgetc(i32* %13)
%25 = load i8, i8* @EOF
%26 = icmp eq i8 %24, %25
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %23
store i8 %24, i8* %28
%29 = add nuw nsw i64 %23, 1
%30 = icmp eq i64 %29, 65536
br i1 %30, label %31, label %22
31: ; preds = %22, %27
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @dekodovat(i8* %5, i8* %6)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = call i32 @fclose(i32* %13)
%37 = call i32 @fclose(i32* %16)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0))
br label %46
39: ; preds = %31
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%41 = call i32 @fputs(i8* %6, i32* %16)
%42 = load i8*, i8** %14
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %42)
%44 = call i32 @fclose(i32* %13)
%45 = call i32 @fclose(i32* %16)
br label %46
46: ; preds = %18, %35, %39, %8
%47 = phi i32 [ -1, %8 ], [ -2, %18 ], [ -4, %35 ], [ 0, %39 ]
ret i32 %47
}