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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  assert(argc == 2);
  FILE *fpIn = NULL;
  FILE *fpOut = NULL;
  int strLen = strlen(argv[1]);
  char rleFileTag[256];
  strcpy(rleFileTag, argv[1] + strLen - 4);
  if (strcmp(rleFileTag, ".rle") != 0) {
    printf("Invalid File Type. Must be '.rle'\n");
    exit(1);
  }
  char outputFile[256];
  strncpy(outputFile, argv[1], strLen - 4);
  fpIn = fopen(argv[1], "rb");
  fpOut = fopen(outputFile, "wb");
  assert(fpIn != NULL);
  assert(fpOut != NULL);
  unsigned char current = 0;
  unsigned char counter = 0;
  while (fread(&counter, sizeof(counter), 1, fpIn)) {
    fread(&current, sizeof(current), 1, fpIn);
    for (int i = 0; i <= counter; i++)
      fwrite(&current, sizeof(current), 1, fpOut);
  }
  fclose(fpIn);
  fclose(fpOut);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x24(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffc,%rsi
call   1040 <strcpy@plt>
lea    -0x130(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     124c <main+0x9c>
lea    0xdc8(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x24(%rbp),%edx
sub    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb3(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x230(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
movb   $0x0,-0x231(%rbp)
movb   $0x0,-0x232(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x232(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fread@plt>
cmp    $0x0,%rax
je     134e <main+0x19e>
mov    -0x18(%rbp),%rcx
lea    -0x231(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fread@plt>
movl   $0x0,-0x238(%rbp)
mov    -0x238(%rbp),%eax
movzbl -0x232(%rbp),%ecx
cmp    %ecx,%eax
jg     1349 <main+0x199>
mov    -0x20(%rbp),%rcx
lea    -0x231(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10d0 <fwrite@plt>
mov    -0x238(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x238(%rbp)
jmp    1309 <main+0x159>
jmp    12c7 <main+0x117>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   10b0 <assert@plt>
mov    0x8(%rbx),%rdi
call   1080 <strlen@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rax
movslq %ebp,%rcx
lea    (%rax,%rcx,1),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0x110(%rsp),%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
lea    0xdfc(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    131d <main+0x16d>
mov    0x8(%rbx),%rsi
add    $0xfffffffc,%ebp
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    0x8(%rbx),%rdi
lea    0xdcf(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
lea    0xdc3(%rip),%rsi
mov    %r15,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r13
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   10b0 <assert@plt>
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   10b0 <assert@plt>
movb   $0x0,0xf(%rsp)
movb   $0x0,0xe(%rsp)
lea    0xe(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
test   %rax,%rax
je     12f9 <main+0x149>
lea    0xf(%rsp),%r15
lea    0xe(%rsp),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
movzbl 0xe(%rsp),%ebx
movsbl 0xf(%rsp),%ebp
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r13,%rsi
call   1090 <fputc@plt>
add    $0xffffffff,%ebx
jne    12d0 <main+0x120>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
test   %rax,%rax
jne    12a0 <main+0xf0>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    %r13,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce7(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".rle\00"
@.str.1 = [35 x i8] c"Invalid File Type. Must be '.rle'\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca i8
%12 = alloca i8
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
store i32* null, i32** %6
store i32* null, i32** %7
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %8
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = getelementptr inbounds i8, i8* %28, i64 -4
%30 = call i32 @strcpy(i8* %22, i8* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %2
%35 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %2
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i32, i32* %8
%43 = sub nsw i32 %42, 4
%44 = call i32 @strncpy(i8* %38, i8* %41, i32 %43)
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %48, i32** %6
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %50, i32** %7
%51 = load i32*, i32** %6
%52 = icmp ne i32* %51, null
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = load i32*, i32** %7
%56 = icmp ne i32* %55, null
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
store i8 0, i8* %11
store i8 0, i8* %12
br label %59
59: ; preds = %77, %37
%60 = load i32*, i32** %6
%61 = call i64 @fread(i8* %12, i32 1, i32 1, i32* %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %78
63: ; preds = %59
%64 = load i32*, i32** %6
%65 = call i64 @fread(i8* %11, i32 1, i32 1, i32* %64)
store i32 0, i32* %13
br label %66
66: ; preds = %74, %63
%67 = load i32, i32* %13
%68 = load i8, i8* %12
%69 = zext i8 %68 to i32
%70 = icmp sle i32 %67, %69
br i1 %70, label %71, label %77
71: ; preds = %66
%72 = load i32*, i32** %7
%73 = call i32 @fwrite(i8* %11, i32 1, i32 1, i32* %72)
br label %74
74: ; preds = %71
%75 = load i32, i32* %13
%76 = add nsw i32 %75, 1
store i32 %76, i32* %13
br label %66
77: ; preds = %66
br label %59
78: ; preds = %59
%79 = load i32*, i32** %6
%80 = call i32 @fclose(i32* %79)
%81 = load i32*, i32** %7
%82 = call i32 @fclose(i32* %81)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c".rle\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [3 x i8] c"wb\00"
@str = [34 x i8] c"Invalid File Type. Must be '.rle'\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca i8
%6 = alloca i8
%7 = icmp eq i32 %0, 2
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = load i8*, i8** %10
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -4
%18 = call i32 @strcpy(i8* %13, i8* %17)
%19 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %2
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%26 = load i8*, i8** %10
%27 = add nsw i32 %12, -4
%28 = call i32 @strncpy(i8* %25, i8* %26, i32 %27)
%29 = load i8*, i8** %10
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp ne i32* %30, null
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = icmp ne i32* %31, null
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
store i8 0, i8* %5
store i8 0, i8* %6
%38 = call i64 @fread(i8* %6, i32 1, i32 1, i32* %30)
%39 = icmp eq i64 %38, 0
br i1 %39, label %54, label %43
40: ; preds = %49
%41 = call i64 @fread(i8* %6, i32 1, i32 1, i32* %30)
%42 = icmp eq i64 %41, 0
br i1 %42, label %54, label %43
43: ; preds = %24, %40
%44 = call i64 @fread(i8* %5, i32 1, i32 1, i32* %30)
%45 = load i8, i8* %6
%46 = zext i8 %45 to i32
%47 = load i8, i8* %5
%48 = sext i8 %47 to i32
br label %49
49: ; preds = %43, %49
%50 = phi i32 [ 0, %43 ], [ %52, %49 ]
%51 = call i32 @fputc(i32 %48, i32* %31)
%52 = add nuw nsw i32 %50, 1
%53 = icmp eq i32 %50, %46
br i1 %53, label %40, label %49
54: ; preds = %40, %24
%55 = call i32 @fclose(i32* %30)
%56 = call i32 @fclose(i32* %31)
ret i32 0
}