#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*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
size_t getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
size_t strlen(char *);
int main(void) {
  char *nomeDoArquivoDeEntrada = "palavras-port.txt";
  FILE *arquivoEntrada = fopen(nomeDoArquivoDeEntrada, "r");
  if (!arquivoEntrada) {
    printf("Não consegui ler o arquivo de entrada\n");
    exit(EXIT_FAILURE);
  }
  size_t bufferSize = 32;
  size_t lineSize;
  char *line = (char *)malloc(bufferSize * sizeof(char));
  assert(line != NULL);
  size_t i = 0;
  while ((lineSize = getline(&line, &bufferSize, arquivoEntrada)) != -1) {
    printf("Li uma linha de %d chars, %s\n", (int)lineSize, line);
    for (i = 0; i < strlen(line); i++) {
      printf("%c", line[i]);
    }
    printf("\n");
  }
  free(line);
  fclose(arquivoEntrada);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e5 <main+0x55>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movq   $0x20,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
shl    $0x0,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <getline@plt>
mov    %rax,-0x28(%rbp)
cmp    $0xffffffffffffffff,%rax
je     12b6 <main+0x126>
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x30(%rbp),%rdx
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
jae    12a3 <main+0x113>
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1257 <main+0xc7>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1218 <main+0x88>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe3b(%rip),%rdi
lea    0xe46(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12e7 <main+0x137>
mov    %rax,%r13
movq   $0x20,0x10(%rsp)
mov    $0x20,%edi
call   10a0 <malloc@plt>
mov    %rax,0x8(%rsp)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1090 <assert@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
call   10c0 <getline@plt>
cmp    $0xffffffffffffffff,%rax
je     12c4 <main+0x114>
lea    0xdee(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    125e <main+0xae>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   10c0 <getline@plt>
cmp    $0xffffffffffffffff,%rax
je     12c4 <main+0x114>
mov    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%rax
movsbl (%rax),%edi
test   %edi,%edi
je     1240 <main+0x90>
call   1040 <putchar@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
cmp    $0x2,%rax
jb     1240 <main+0x90>
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%rbx,%rbp,1),%edi
call   1040 <putchar@plt>
add    $0x1,%rbp
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
cmp    %rax,%rbp
jb     12a0 <main+0xf0>
jmp    1240 <main+0x90>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd44(%rip),%rdi
call   1050 <puts@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"palavras-port.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"N\C3\A3o consegui ler o arquivo de entrada\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [30 x i8] c"Li uma linha de %d chars, %s\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
store i64 32, i64* %4
%17 = load i64, i64* %4
%18 = mul i64 %17, 1
%19 = call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
store i64 0, i64* %7
br label %25
25: ; preds = %49, %16
%26 = load i32*, i32** %3
%27 = call i64 @getline(i8** %6, i64* %4, i32* %26)
store i64 %27, i64* %5
%28 = icmp ne i64 %27, -1
br i1 %28, label %29, label %51
29: ; preds = %25
%30 = load i64, i64* %5
%31 = trunc i64 %30 to i32
%32 = load i8*, i8** %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %31, i8* %32)
store i64 0, i64* %7
br label %34
34: ; preds = %46, %29
%35 = load i64, i64* %7
%36 = load i8*, i8** %6
%37 = call i64 @strlen(i8* %36)
%38 = icmp ult i64 %35, %37
br i1 %38, label %39, label %49
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = load i64, i64* %7
%42 = getelementptr inbounds i8, i8* %40, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %39
%47 = load i64, i64* %7
%48 = add i64 %47, 1
store i64 %48, i64* %7
br label %34
49: ; preds = %34
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %25
51: ; preds = %25
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
%54 = load i32*, i32** %3
%55 = call i32 @fclose(i32* %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"palavras-port.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [30 x i8] c"Li uma linha de %d chars, %s\0A\00"
@str = [39 x i8] c"N\C3\A3o consegui ler o arquivo de entrada\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = bitcast i64* %1 to i8*
store i64 32, i64* %1
%11 = bitcast i8** %2 to i8*
%12 = tail call i64 @malloc(i64 32)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %2
%14 = icmp ne i64 %12, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = call i64 @getline(i8** %2, i64* %1, i32* %3)
%18 = icmp eq i64 %17, -1
br i1 %18, label %48, label %19
19: ; preds = %9, %44
%20 = phi i64 [ %46, %44 ], [ %17, %9 ]
%21 = trunc i64 %20 to i32
%22 = load i8*, i8** %2
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* %22)
%24 = load i8*, i8** %2
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %44, label %27
27: ; preds = %19
%28 = sext i8 %25 to i32
%29 = call i32 @putchar(i32 %28)
%30 = load i8*, i8** %2
%31 = call i64 @strlen(i8* dereferenceable(1) %30)
%32 = icmp ugt i64 %31, 1
br i1 %32, label %33, label %44
33: ; preds = %27, %33
%34 = phi i8* [ %41, %33 ], [ %30, %27 ]
%35 = phi i64 [ %40, %33 ], [ 1, %27 ]
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 @putchar(i32 %38)
%40 = add nuw i64 %35, 1
%41 = load i8*, i8** %2
%42 = call i64 @strlen(i8* dereferenceable(1) %41)
%43 = icmp ult i64 %40, %42
br i1 %43, label %33, label %44
44: ; preds = %33, %27, %19
%45 = call i32 @putchar(i32 10)
%46 = call i64 @getline(i8** %2, i64* %1, i32* %3)
%47 = icmp eq i64 %46, -1
br i1 %47, label %48, label %19
48: ; preds = %44, %9
%49 = load i8*, i8** %2
%50 = call i32 @free(i8* %49)
%51 = call i32 @fclose(i32* %3)
ret i32 0
}