#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*/ SEEK_CUR;
char *aloca(char);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
char *getCaminhoTabela(char *);
int /*<<< orphan*/ help(int);
void runLengthEncodeDescomp(char *arquivoEntrada) {
  FILE *ptre, *ptrs;
  char c, *vetNum, cont, *caminho;
  int num, i;
  caminho = getCaminhoTabela(arquivoEntrada);
  ptre = fopen(caminho, "rb");
  if (ptre == NULL) {
    help(4);
    exit(-1);
  }
  ptrs = fopen("dados/saidaDescomp.ori", "wb");
  while ((fread(&c, sizeof(char), 1, ptre) == 1)) {
    cont = 0;
    if (c == '#') {
      while ((fread(&c, sizeof(char), 1, ptre) == 1) && (c != '#')) {
        cont++;
      }
      vetNum = aloca(cont);
      fseek(ptre, -(cont + 1), SEEK_CUR);
      fread(vetNum, sizeof(char), cont - 1, ptre);
      num = atoi(vetNum);
      fread(&c, sizeof(char), 1, ptre);
      for (i = 0; i < num; i++) {
        fwrite(&c, sizeof(char), 1, ptrs);
      }
      fseek(ptre, 1, SEEK_CUR);
    } else
      fwrite(&c, sizeof(char), 1, ptrs);
  }
  fclose(ptre);
  fclose(ptrs);
}


x86 assembly (clang, -O0):
<runLengthEncodeDescomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getCaminhoTabela@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ec <runLengthEncodeDescomp+0x4c>
mov    $0x4,%edi
call   1090 <help@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    0xe10(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1351 <runLengthEncodeDescomp+0x1b1>
movb   $0x0,-0x29(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x23,%eax
jne    1338 <runLengthEncodeDescomp+0x198>
jmp    1236 <runLengthEncodeDescomp+0x96>
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x41(%rbp)
jne    1267 <runLengthEncodeDescomp+0xc7>
movsbl -0x19(%rbp),%eax
cmp    $0x23,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1277 <runLengthEncodeDescomp+0xd7>
jmp    1284 <runLengthEncodeDescomp+0xe4>
mov    -0x29(%rbp),%al
add    $0x1,%al
mov    %al,-0x29(%rbp)
jmp    1236 <runLengthEncodeDescomp+0x96>
movsbl -0x29(%rbp),%edi
call   1030 <aloca@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x29(%rbp),%eax
add    $0x1,%eax
xor    %esi,%esi
sub    %eax,%esi
mov    0x2d41(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    -0x28(%rbp),%rdi
movsbl -0x29(%rbp),%edx
sub    $0x1,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    131c <runLengthEncodeDescomp+0x17c>
mov    -0x18(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10c0 <fwrite@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    12ee <runLengthEncodeDescomp+0x14e>
mov    -0x10(%rbp),%rdi
mov    0x2cc1(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1070 <fseek@plt>
jmp    134c <runLengthEncodeDescomp+0x1ac>
mov    -0x18(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10c0 <fwrite@plt>
jmp    1203 <runLengthEncodeDescomp+0x63>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runLengthEncodeDescomp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1050 <getCaminhoTabela@plt>
lea    0xe49(%rip),%rsi
mov    %rax,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1313 <runLengthEncodeDescomp+0x173>
mov    %rax,%r12
lea    0xe31(%rip),%rdi
lea    0xe41(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    12f5 <runLengthEncodeDescomp+0x155>
lea    0x7(%rsp),%r15
mov    0x2ddb(%rip),%r13
jmp    1236 <runLengthEncodeDescomp+0x96>
nop
mov    %r14,%rsi
call   1070 <fputc@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    12f5 <runLengthEncodeDescomp+0x155>
movsbl 0x7(%rsp),%edi
cmp    $0x23,%edi
jne    1210 <runLengthEncodeDescomp+0x70>
mov    $0xff,%bl
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
add    $0x1,%bl
cmp    $0x1,%eax
jne    1274 <runLengthEncodeDescomp+0xd4>
cmpb   $0x23,0x7(%rsp)
jne    1250 <runLengthEncodeDescomp+0xb0>
movsbl %bl,%ebx
mov    %ebx,%edi
call   1030 <aloca@plt>
mov    %rax,%rbp
mov    %ebx,%esi
not    %esi
mov    0x0(%r13),%edx
mov    %r12,%rdi
call   1080 <fseek@plt>
add    $0xffffffff,%ebx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %ebp,%ebp
jle    12df <runLengthEncodeDescomp+0x13f>
movsbl 0x7(%rsp),%ebx
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
add    $0xffffffff,%ebp
jne    12d0 <runLengthEncodeDescomp+0x130>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    $0x1,%esi
call   1080 <fseek@plt>
jmp    1218 <runLengthEncodeDescomp+0x78>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fclose@plt>
mov    $0x4,%edi
call   10a0 <help@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [23 x i8] c"dados/saidaDescomp.ori\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_CUR = global i32 0
define void @runLengthEncodeDescomp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %2
%11 = load i8*, i8** %2
%12 = call i8* @getCaminhoTabela(i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %3
%15 = load i32*, i32** %3
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = call i32 @help(i32 4)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %1
%21 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %4
br label %22
22: ; preds = %81, %20
%23 = load i32*, i32** %3
%24 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %82
26: ; preds = %22
store i8 0, i8* %7
%27 = load i8, i8* %5
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 35
br i1 %29, label %30, label %78
30: ; preds = %26
br label %31
31: ; preds = %41, %30
%32 = load i32*, i32** %3
%33 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %32)
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i8, i8* %5
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 35
br label %39
39: ; preds = %35, %31
%40 = phi i1 [ false, %31 ], [ %38, %35 ]
br i1 %40, label %41, label %44
41: ; preds = %39
%42 = load i8, i8* %7
%43 = add i8 %42, 1
store i8 %43, i8* %7
br label %31
44: ; preds = %39
%45 = load i8, i8* %7
%46 = call i8* @aloca(i8 signext %45)
store i8* %46, i8** %6
%47 = load i32*, i32** %3
%48 = load i8, i8* %7
%49 = sext i8 %48 to i32
%50 = add nsw i32 %49, 1
%51 = sub nsw i32 0, %50
%52 = load i32, i32* @SEEK_CUR
%53 = call i32 @fseek(i32* %47, i32 %51, i32 %52)
%54 = load i8*, i8** %6
%55 = load i8, i8* %7
%56 = sext i8 %55 to i32
%57 = sub nsw i32 %56, 1
%58 = load i32*, i32** %3
%59 = call i32 @fread(i8* %54, i32 1, i32 %57, i32* %58)
%60 = load i8*, i8** %6
%61 = call i32 @atoi(i8* %60)
store i32 %61, i32* %9
%62 = load i32*, i32** %3
%63 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %62)
store i32 0, i32* %10
br label %64
64: ; preds = %71, %44
%65 = load i32, i32* %10
%66 = load i32, i32* %9
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %74
68: ; preds = %64
%69 = load i32*, i32** %4
%70 = call i32 @fwrite(i8* %5, i32 1, i32 1, i32* %69)
br label %71
71: ; preds = %68
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 1
store i32 %73, i32* %10
br label %64
74: ; preds = %64
%75 = load i32*, i32** %3
%76 = load i32, i32* @SEEK_CUR
%77 = call i32 @fseek(i32* %75, i32 1, i32 %76)
br label %81
78: ; preds = %26
%79 = load i32*, i32** %4
%80 = call i32 @fwrite(i8* %5, i32 1, i32 1, i32* %79)
br label %81
81: ; preds = %78, %74
br label %22
82: ; preds = %22
%83 = load i32*, i32** %3
%84 = call i32 @fclose(i32* %83)
%85 = load i32*, i32** %4
%86 = call i32 @fclose(i32* %85)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [23 x i8] c"dados/saidaDescomp.ori\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_CUR = global i32 0
define void @runLengthEncodeDescomp(i8* %0) {
%2 = alloca i8
%3 = tail call i8* @getCaminhoTabela(i8* %0)
%4 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @help(i32 4)
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %1
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %52
13: ; preds = %9, %49
%14 = load i8, i8* %2
%15 = icmp eq i8 %14, 35
br i1 %15, label %16, label %46
16: ; preds = %13, %16
%17 = phi i8 [ %23, %16 ], [ 0, %13 ]
%18 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %4)
%19 = icmp eq i32 %18, 1
%20 = load i8, i8* %2
%21 = icmp ne i8 %20, 35
%22 = select i1 %19, i1 %21, i1 false
%23 = add i8 %17, 1
br i1 %22, label %16, label %24
24: ; preds = %16
%25 = tail call i8* @aloca(i8 signext %17)
%26 = sext i8 %17 to i32
%27 = xor i32 %26, -1
%28 = load i32, i32* @SEEK_CUR
%29 = tail call i32 @fseek(i32* %4, i32 %27, i32 %28)
%30 = add nsw i32 %26, -1
%31 = tail call i32 @fread(i8* %25, i32 1, i32 %30, i32* %4)
%32 = tail call i32 @atoi(i8* %25)
%33 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %4)
%34 = icmp sgt i32 %32, 0
br i1 %34, label %35, label %43
35: ; preds = %24
%36 = load i8, i8* %2
%37 = sext i8 %36 to i32
br label %38
38: ; preds = %35, %38
%39 = phi i32 [ 0, %35 ], [ %41, %38 ]
%40 = tail call i32 @fputc(i32 %37, i32* %10)
%41 = add nuw nsw i32 %39, 1
%42 = icmp eq i32 %41, %32
br i1 %42, label %43, label %38
43: ; preds = %38, %24
%44 = load i32, i32* @SEEK_CUR
%45 = tail call i32 @fseek(i32* %4, i32 1, i32 %44)
br label %49
46: ; preds = %13
%47 = sext i8 %14 to i32
%48 = tail call i32 @fputc(i32 %47, i32* %10)
br label %49
49: ; preds = %46, %43
%50 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %4)
%51 = icmp eq i32 %50, 1
br i1 %51, label %13, label %52
52: ; preds = %49, %9
%53 = tail call i32 @fclose(i32* %4)
%54 = tail call i32 @fclose(i32* %10)
ret void
}