#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*/ copyright();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ rle_decode(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ rle_encode(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  if (argc < 3 || argc > 4) {
    fprintf(stderr, "\n Run Length Encoding (RLE) implementation.\n"
                    "\n Usage : gtrle inputfile outputfile [/d]");
    copyright();
    return 0;
  }
  in = fopen(argv[1], "rb");
  if (!in) {
    fprintf(stderr, "\n Error opening input file!");
    copyright();
    return 0;
  }
  out = fopen(argv[2], "wb");
  if (!out) {
    fprintf(stderr, "\n Error opening output file!");
    copyright();
    return 0;
  }
  if (argc == 4) {
    if (!strcmp(argv[3], "/d") || !strcmp(argv[3], "/D")) {
      fprintf(stderr, "\n Run-Length decoding...");
      rle_decode(in, out);
    } else {
      fprintf(stderr, "\n Error! Unknown: \"%s\"\n", argv[3]);
      return 0;
    }
  } else {
    fprintf(stderr, "\n Run-Length encoding...");
    rle_encode(in, out);
  }
  fprintf(stderr, "complete.\n");
  if (in)
    fclose(in);
  if (out)
    fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     119a <main+0x2a>
cmpl   $0x4,-0x8(%rbp)
jle    11c4 <main+0x54>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1040 <copyright@plt>
movl   $0x0,-0x4(%rbp)
jmp    1365 <main+0x1f5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe83(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1211 <main+0xa1>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1040 <copyright@plt>
movl   $0x0,-0x4(%rbp)
jmp    1365 <main+0x1f5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe55(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    125e <main+0xee>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1040 <copyright@plt>
movl   $0x0,-0x4(%rbp)
jmp    1365 <main+0x1f5>
cmpl   $0x4,-0x8(%rbp)
jne    12fb <main+0x18b>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe1e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     12a2 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe04(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12cb <main+0x15b>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <rle_decode@plt>
jmp    12f6 <main+0x186>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1365 <main+0x1f5>
jmp    131f <main+0x1af>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <rle_encode@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     134a <main+0x1da>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     135e <main+0x1ee>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x5(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     1197 <main+0x27>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
jmp    1241 <main+0xd1>
mov    %rsi,%r12
mov    0x8(%rsi),%rdi
lea    0xeb1(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     121f <main+0xaf>
mov    %rax,%r15
mov    0x10(%r12),%rdi
lea    0xeb7(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1231 <main+0xc1>
mov    %rax,%r14
cmp    $0x4,%ebx
jne    125d <main+0xed>
mov    0x18(%r12),%rbx
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1281 <main+0x111>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1281 <main+0x111>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    124f <main+0xdf>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
jmp    1241 <main+0xd1>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1040 <copyright@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <rle_encode@plt>
jmp    12a3 <main+0x133>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <rle_decode@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    124f <main+0xdf>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [86 x i8] c"\0A Run Length Encoding (RLE) implementation.\0A\0A Usage : gtrle inputfile outputfile [/d]\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [28 x i8] c"\0A Error opening input file!\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [29 x i8] c"\0A Error opening output file!\00"
@.str.5 = [3 x i8] c"/d\00"
@.str.6 = [3 x i8] c"/D\00"
@.str.7 = [25 x i8] c"\0A Run-Length decoding...\00"
@.str.8 = [24 x i8] c"\0A Error! Unknown: \22%s\22\0A\00"
@.str.9 = [25 x i8] c"\0A Run-Length encoding...\00"
@.str.10 = [11 x i8] c"complete.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 4
br i1 %12, label %13, label %17
13: ; preds = %10, %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @copyright()
store i32 0, i32* %3
br label %88
17: ; preds = %10
%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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 (...) @copyright()
store i32 0, i32* %3
br label %88
28: ; preds = %17
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp ne i32* %33, null
br i1 %34, label %39, label %35
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 (...) @copyright()
store i32 0, i32* %3
br label %88
39: ; preds = %28
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 4
br i1 %41, label %42, label %67
42: ; preds = %39
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = call i32 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %42
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i32 @strcmp(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%53 = icmp ne i32 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %48, %42
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%57 = load i32*, i32** %6
%58 = load i32*, i32** %7
%59 = call i32 @rle_decode(i32* %57, i32* %58)
br label %66
60: ; preds = %48
%61 = load i32, i32* @stderr
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 3
%64 = load i8*, i8** %63
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %64)
store i32 0, i32* %3
br label %88
66: ; preds = %54
br label %73
67: ; preds = %39
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
%70 = load i32*, i32** %6
%71 = load i32*, i32** %7
%72 = call i32 @rle_encode(i32* %70, i32* %71)
br label %73
73: ; preds = %67, %66
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%76 = load i32*, i32** %6
%77 = icmp ne i32* %76, null
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = load i32*, i32** %6
%80 = call i32 @fclose(i32* %79)
br label %81
81: ; preds = %78, %73
%82 = load i32*, i32** %7
%83 = icmp ne i32* %82, null
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i32*, i32** %7
%86 = call i32 @fclose(i32* %85)
br label %87
87: ; preds = %84, %81
store i32 0, i32* %3
br label %88
88: ; preds = %87, %60, %35, %24, %13
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [86 x i8] c"\0A Run Length Encoding (RLE) implementation.\0A\0A Usage : gtrle inputfile outputfile [/d]\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [28 x i8] c"\0A Error opening input file!\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [29 x i8] c"\0A Error opening output file!\00"
@.str.5 = [3 x i8] c"/d\00"
@.str.6 = [3 x i8] c"/D\00"
@.str.7 = [25 x i8] c"\0A Run-Length decoding...\00"
@.str.8 = [24 x i8] c"\0A Error! Unknown: \22%s\22\0A\00"
@.str.9 = [25 x i8] c"\0A Run-Length encoding...\00"
@.str.10 = [11 x i8] c"complete.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -5
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @copyright()
br label %53
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 (...) @copyright()
br label %53
18: ; preds = %9
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%26 = tail call i32 (...) @copyright()
br label %53
27: ; preds = %18
%28 = icmp eq i32 %0, 4
br i1 %28, label %29, label %44
29: ; preds = %27
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = tail call i32 @strcmp(i8* dereferenceable(1) %31, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = tail call i32 @strcmp(i8* dereferenceable(1) %31, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %34, %29
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%40 = tail call i32 @rle_decode(i32* %12, i32* %21)
br label %48
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %31)
br label %53
44: ; preds = %27
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
%47 = tail call i32 @rle_encode(i32* %12, i32* %21)
br label %48
48: ; preds = %44, %37
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%51 = tail call i32 @fclose(i32* %12)
%52 = tail call i32 @fclose(i32* %21)
br label %53
53: ; preds = %48, %41, %23, %14, %5
ret i32 0
}