#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int main() {
  char linhaOriginal[200], linhaSaida[200];
  FILE *entrada, *saida;
  int i, j;
  int aspas;
  int nomeCidade;
  entrada = fopen("../brutos/lixo_coletado.csv", "r");
  saida = fopen("../tratados/lixo_coletado.csv", "w");
  while (fgets(linhaOriginal, 200, entrada) != NULL) {
    aspas = 0;
    j = 0;
    nomeCidade = 1;
    printf("%s\n", linhaOriginal);
    linhaSaida[j] = '"';
    j++;
    for (i = 0; i < strlen(linhaOriginal); i++) {
      if (linhaOriginal[i] == '\n') {
        linhaSaida[j] = '\0';
        break;
      }
      if (linhaOriginal[i] == ',' && nomeCidade == 1) {
        nomeCidade = 0;
        linhaSaida[j] = '"';
        j++;
      }
      if (linhaOriginal[i] == '"') {
        if (aspas == 1) {
          aspas = 0;
        } else {
          aspas = 1;
        }
        continue;
      }
      if (aspas && linhaOriginal[i] == ',') {
        linhaSaida[j] = '.';
        j++;
        continue;
      }
      if (linhaOriginal[i] != ' ' || nomeCidade) {
        linhaSaida[j] = linhaOriginal[i];
        j++;
        continue;
      }
    }
    fprintf(saida, "%s,2000\n", linhaSaida);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x1a8(%rbp)
lea    0xe9b(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x1b0(%rbp)
lea    -0xd0(%rbp),%rdi
mov    -0x1a8(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     13ca <main+0x27a>
movl   $0x0,-0x1bc(%rbp)
movl   $0x0,-0x1b8(%rbp)
movl   $0x1,-0x1c0(%rbp)
lea    -0xd0(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
movslq -0x1b8(%rbp),%rax
movb   $0x22,-0x1a0(%rbp,%rax,1)
22
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
movl   $0x0,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%eax
mov    %eax,-0x1c4(%rbp)
lea    -0xd0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c4(%rbp),%eax
cmp    %ecx,%eax
jge    13ab <main+0x25b>
movslq -0x1b4(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1265 <main+0x115>
movslq -0x1b8(%rbp),%rax
movb   $0x0,-0x1a0(%rbp,%rax,1)
jmp    13ab <main+0x25b>
movslq -0x1b4(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0x2c,%eax
jne    12b2 <main+0x162>
cmpl   $0x1,-0x1c0(%rbp)
jne    12b2 <main+0x162>
movl   $0x0,-0x1c0(%rbp)
movslq -0x1b8(%rbp),%rax
movb   $0x22,-0x1a0(%rbp,%rax,1)
22
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
movslq -0x1b4(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0x22,%eax
jne    12f5 <main+0x1a5>
cmpl   $0x1,-0x1bc(%rbp)
jne    12e6 <main+0x196>
movl   $0x0,-0x1bc(%rbp)
jmp    12f0 <main+0x1a0>
movl   $0x1,-0x1bc(%rbp)
jmp    1397 <main+0x247>
cmpl   $0x0,-0x1bc(%rbp)
je     133d <main+0x1ed>
movslq -0x1b4(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0x2c,%eax
jne    133d <main+0x1ed>
movslq -0x1b8(%rbp),%rax
movb   $0x2e,-0x1a0(%rbp,%rax,1)
2e
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    1397 <main+0x247>
movslq -0x1b4(%rbp),%rax
movsbl -0xd0(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    1362 <main+0x212>
cmpl   $0x0,-0x1c0(%rbp)
je     1392 <main+0x242>
movslq -0x1b4(%rbp),%rax
mov    -0xd0(%rbp,%rax,1),%cl
movslq -0x1b8(%rbp),%rax
mov    %cl,-0x1a0(%rbp,%rax,1)
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    1397 <main+0x247>
jmp    1397 <main+0x247>
mov    -0x1b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    1211 <main+0xc1>
mov    -0x1b0(%rbp),%rdi
lea    -0x1a0(%rbp),%rdx
lea    0xc82(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1196 <main+0x46>
xor    %eax,%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
lea    0xe98(%rip),%rdi
lea    0xead(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0xea0(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,0x8(%rsp)
lea    0xe0(%rsp),%rdi
mov    $0xc8,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12cd <main+0x17d>
lea    0xe0(%rsp),%rbx
jmp    11f7 <main+0xa7>
nopw   0x0(%rax,%rax,1)
movslq %r13d,%rax
movb   $0x0,0x10(%rsp,%rax,1)
mov    0x8(%rsp),%rdi
lea    0xe6e(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     12cd <main+0x17d>
lea    0xe40(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
movb   $0x22,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11c8 <main+0x78>
xor    %r15d,%r15d
mov    $0x1,%ebp
xor    %r14d,%r14d
mov    $0x1,%r13d
jmp    1253 <main+0x103>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
cmp    $0x1,%r14d
setne  %al
mov    %eax,%r14d
add    $0x1,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r15
jge    11c8 <main+0x78>
movzbl 0xe0(%rsp,%r15,1),%eax
cmp    $0xa,%al
je     11c0 <main+0x70>
cmp    $0x2c,%al
jne    1280 <main+0x130>
cmp    $0x1,%ebp
jne    1280 <main+0x130>
movslq %r13d,%r13
movb   $0x22,0x10(%rsp,%r13,1)
add    $0x1,%r13d
xor    %ebp,%ebp
jmp    1284 <main+0x134>
xchg   %ax,%ax
cmp    $0x22,%al
je     1230 <main+0xe0>
test   %r14d,%r14d
je     12b0 <main+0x160>
cmp    $0x2c,%al
jne    12b0 <main+0x160>
movslq %r13d,%rax
movb   $0x2e,0x10(%rsp,%rax,1)
add    $0x1,%r13d
mov    $0x1,%r14d
jmp    123c <main+0xec>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x20,%al
jne    12bc <main+0x16c>
test   %ebp,%ebp
jne    12bc <main+0x16c>
xor    %ebp,%ebp
jmp    123c <main+0xec>
movslq %r13d,%r13
mov    %al,0x10(%rsp,%r13,1)
add    $0x1,%r13d
jmp    123c <main+0xec>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"../brutos/lixo_coletado.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"../tratados/lixo_coletado.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [9 x i8] c"%s,2000\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [200 x i8]
%3 = alloca [200 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %5
br label %12
12: ; preds = %110, %0
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i32* @fgets(i8* %13, i32 200, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %114
17: ; preds = %12
store i32 0, i32* %8
store i32 0, i32* %7
store i32 1, i32* %9
%18 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %21
store i8 34, i8* %22
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
store i32 0, i32* %6
br label %25
25: ; preds = %107, %17
%26 = load i32, i32* %6
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = icmp slt i32 %26, %28
br i1 %29, label %30, label %110
30: ; preds = %25
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %41
37: ; preds = %30
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %39
store i8 0, i8* %40
br label %110
41: ; preds = %30
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 44
br i1 %47, label %48, label %57
48: ; preds = %41
%49 = load i32, i32* %9
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %57
51: ; preds = %48
store i32 0, i32* %9
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %53
store i8 34, i8* %54
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %57
57: ; preds = %51, %48, %41
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 34
br i1 %63, label %64, label %70
64: ; preds = %57
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, 1
br i1 %66, label %67, label %68
67: ; preds = %64
store i32 0, i32* %8
br label %69
68: ; preds = %64
store i32 1, i32* %8
br label %69
69: ; preds = %68, %67
br label %107
70: ; preds = %57
%71 = load i32, i32* %8
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %86
73: ; preds = %70
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = icmp eq i32 %78, 44
br i1 %79, label %80, label %86
80: ; preds = %73
%81 = load i32, i32* %7
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %82
store i8 46, i8* %83
%84 = load i32, i32* %7
%85 = add nsw i32 %84, 1
store i32 %85, i32* %7
br label %107
86: ; preds = %73, %70
%87 = load i32, i32* %6
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %88
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp ne i32 %91, 32
br i1 %92, label %96, label %93
93: ; preds = %86
%94 = load i32, i32* %9
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %106
96: ; preds = %93, %86
%97 = load i32, i32* %6
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %98
%100 = load i8, i8* %99
%101 = load i32, i32* %7
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 %102
store i8 %100, i8* %103
%104 = load i32, i32* %7
%105 = add nsw i32 %104, 1
store i32 %105, i32* %7
br label %107
106: ; preds = %93
br label %107
107: ; preds = %106, %96, %80, %69
%108 = load i32, i32* %6
%109 = add nsw i32 %108, 1
store i32 %109, i32* %6
br label %25
110: ; preds = %37, %25
%111 = load i32*, i32** %5
%112 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%113 = call i32 @fprintf(i32* %111, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %112)
br label %12
114: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"../brutos/lixo_coletado.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"../tratados/lixo_coletado.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [9 x i8] c"%s,2000\0A\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = alloca [200 x i8]
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = call i32* @fgets(i8* %3, i32 200, i32* %5)
%8 = icmp eq i32* %7, null
br i1 %8, label %66, label %9
9: ; preds = %0, %62
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %3)
store i8 34, i8* %4
%11 = call i32 @strlen(i8* %3)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %62
13: ; preds = %9, %54
%14 = phi i64 [ %58, %54 ], [ 0, %9 ]
%15 = phi i32 [ %55, %54 ], [ 1, %9 ]
%16 = phi i32 [ %57, %54 ], [ 0, %9 ]
%17 = phi i32 [ %56, %54 ], [ 1, %9 ]
%18 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 %14
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = sext i32 %17 to i64
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %22
store i8 0, i8* %23
br label %62
24: ; preds = %13
%25 = icmp eq i8 %19, 44
%26 = icmp eq i32 %15, 1
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = sext i32 %17 to i64
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %29
store i8 34, i8* %30
%31 = add nsw i32 %17, 1
br label %37
32: ; preds = %24
%33 = icmp eq i8 %19, 34
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = icmp ne i32 %16, 1
%36 = zext i1 %35 to i32
br label %54
37: ; preds = %28, %32
%38 = phi i32 [ 0, %28 ], [ %15, %32 ]
%39 = phi i32 [ %31, %28 ], [ %17, %32 ]
%40 = icmp ne i32 %16, 0
%41 = select i1 %40, i1 %25, i1 false
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = sext i32 %39 to i64
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %43
store i8 46, i8* %44
%45 = add nsw i32 %39, 1
br label %54
46: ; preds = %37
%47 = icmp ne i8 %19, 32
%48 = icmp ne i32 %38, 0
%49 = select i1 %47, i1 true, i1 %48
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = sext i32 %39 to i64
%52 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %51
store i8 %19, i8* %52
%53 = add nsw i32 %39, 1
br label %54
54: ; preds = %34, %46, %50, %42
%55 = phi i32 [ %38, %42 ], [ %38, %50 ], [ 0, %46 ], [ %15, %34 ]
%56 = phi i32 [ %45, %42 ], [ %53, %50 ], [ %39, %46 ], [ %17, %34 ]
%57 = phi i32 [ 1, %42 ], [ %16, %50 ], [ %16, %46 ], [ %36, %34 ]
%58 = add nuw nsw i64 %14, 1
%59 = call i32 @strlen(i8* %3)
%60 = sext i32 %59 to i64
%61 = icmp slt i64 %58, %60
br i1 %61, label %13, label %62
62: ; preds = %54, %9, %21
%63 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%64 = call i32* @fgets(i8* %3, i32 200, i32* %5)
%65 = icmp eq i32* %64, null
br i1 %65, label %66, label %9
66: ; preds = %62, %0
ret i32 0
}