#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*/ descrito(char *, char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int /*<<< orphan*/ inicializaIndices();
int /*<<< orphan*/ ordenaPalavra(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void ler_arquivo() {
  FILE *arquivo = NULL;
  int i = 0, num;
  char palavra_entrada[30];
  char palavra_ordenada[30];
  arquivo = fopen("palavras.txt", "r");
  if (!arquivo) {
    printf("Erro ao abrir arquivo!\n");
    exit(1);
  }
  i = 1;
  while (!feof(arquivo)) {
    if (fscanf(arquivo, "%s %d\n", palavra_entrada, &num) != 2) {
      printf("Palavra invalida!\n");
      exit(0);
    }
    inicializaIndices();
    strcpy(palavra_ordenada, palavra_entrada);
    ordenaPalavra(palavra_ordenada);
    printf("%d - %s => ", i, palavra_entrada);
    descrito(palavra_entrada, palavra_ordenada, (num - 1));
    i++;
  }
}


x86 assembly (clang, -O0):
<ler_arquivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe52(%rip),%rdi
lea    0xe58(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11e1 <ler_arquivo+0x51>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1206 <ler_arquivo+0x76>
jmp    128f <ler_arquivo+0xff>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe12(%rip),%rsi
lea    -0x10(%rbp),%rcx
call   1070 <fscanf@plt>
cmp    $0x2,%eax
je     123c <ler_arquivo+0xac>
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1040 <inicializaIndices@plt>
lea    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
call   1050 <ordenaPalavra@plt>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1090 <descrito@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e8 <ler_arquivo+0x58>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ler_arquivo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe4b(%rip),%rdi
lea    0xe51(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1286 <ler_arquivo+0xe6>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1264 <ler_arquivo+0xc4>
mov    $0x1,%ebp
lea    0x30(%rsp),%rbx
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xe1e(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
lea    0xe05(%rip),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1080 <fscanf@plt>
cmp    $0x2,%eax
jne    1273 <ler_arquivo+0xd3>
xor    %eax,%eax
call   1050 <inicializaIndices@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
call   1060 <ordenaPalavra@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%edx
add    $0xffffffff,%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   10a0 <descrito@plt>
add    $0x1,%ebp
mov    %r15,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1200 <ler_arquivo+0x60>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbf(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xd95(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"palavras.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"Erro ao abrir arquivo!\0A\00"
@.str.3 = [7 x i8] c"%s %d\0A\00"
@.str.4 = [19 x i8] c"Palavra invalida!\0A\00"
@.str.5 = [12 x i8] c"%d - %s => \00"
define void @ler_arquivo() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca [30 x i8]
%5 = alloca [30 x i8]
store i32* null, i32** %1
store i32 0, i32* %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %1
%7 = load i32*, i32** %1
%8 = icmp ne i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
store i32 1, i32* %2
br label %13
13: ; preds = %26, %12
%14 = load i32*, i32** %1
%15 = call i32 @feof(i32* %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %43
18: ; preds = %13
%19 = load i32*, i32** %1
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%21 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %20, i32* %3)
%22 = icmp ne i32 %21, 2
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %18
%27 = call i32 (...) @inicializaIndices()
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%32 = call i32 @ordenaPalavra(i8* %31)
%33 = load i32, i32* %2
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %33, i8* %34)
%36 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%37 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%38 = load i32, i32* %3
%39 = sub nsw i32 %38, 1
%40 = call i32 @descrito(i8* %36, i8* %37, i32 %39)
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
store i32 %42, i32* %2
br label %13
43: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"palavras.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [7 x i8] c"%s %d\0A\00"
@.str.5 = [12 x i8] c"%d - %s => \00"
@str = [23 x i8] c"Erro ao abrir arquivo!\00"
@str.6 = [18 x i8] c"Palavra invalida!\00"
define void @ler_arquivo() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca [30 x i8]
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = call i32 @feof(i32* %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %33
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %22
%16 = phi i32 [ %30, %22 ], [ 1, %9 ]
%17 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %5, i32* %1)
%18 = icmp eq i32 %17, 2
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %15
%23 = call i32 (...) @inicializaIndices()
%24 = call i32 @strcpy(i8* %6, i8* %5)
%25 = call i32 @ordenaPalavra(i8* %6)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %16, i8* %5)
%27 = load i32, i32* %1
%28 = add nsw i32 %27, -1
%29 = call i32 @descrito(i8* %5, i8* %6, i32 %28)
%30 = add nuw nsw i32 %16, 1
%31 = call i32 @feof(i32* %7)
%32 = icmp eq i32 %31, 0
br i1 %32, label %15, label %33
33: ; preds = %22, %9
ret void
}