#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 */

/* Variables and functions */
int analise_fifo(int, int *);
int *ler_referencia();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int numero_de_quadros;
  int *referencias;
  int indice = 0;
  int fifo;
  printf("digite a quantidade de quadros na memoria\n");
  scanf("%d", &numero_de_quadros);
  referencias = ler_referencia();
  while (referencias[indice] > 0) {
    printf("Indice: %d\t Valor: %d\n", indice, referencias[indice]);
    indice = indice + 1;
  }
  fifo = analise_fifo(numero_de_quadros, referencias);
  printf("FIFO %d\n", fifo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    $0x0,%al
call   1060 <ler_referencia@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    11c2 <main+0x82>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1186 <main+0x46>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <analise_fifo@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe94(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
xor    %eax,%eax
call   1070 <ler_referencia@plt>
mov    %rax,%r15
mov    (%rax),%edx
test   %edx,%edx
jle    11a9 <main+0x59>
lea    0xe76(%rip),%r14
xor    %ebx,%ebx
nop
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%r15,%rbx,4),%edx
add    $0x1,%rbx
test   %edx,%edx
jg     1190 <main+0x40>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
call   1060 <analise_fifo@plt>
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [43 x i8] c"digite a quantidade de quadros na memoria\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Indice: %d\09 Valor: %d\0A\00"
@.str.3 = [9 x i8] c"FIFO %d\0A\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%12 = call i32* (...) @ler_referencia()
store i32* %12, i32** %7
br label %13
13: ; preds = %20, %2
%14 = load i32*, i32** %7
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %13
%21 = load i32, i32* %8
%22 = load i32*, i32** %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %26)
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %13
30: ; preds = %13
%31 = load i32, i32* %6
%32 = load i32*, i32** %7
%33 = call i32 @analise_fifo(i32 %31, i32* %32)
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"Indice: %d\09 Valor: %d\0A\00"
@.str.3 = [9 x i8] c"FIFO %d\0A\00"
@str = [42 x i8] c"digite a quantidade de quadros na memoria\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = call i32* (...) @ler_referencia()
%8 = load i32, i32* %7
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %2, %10
%11 = phi i64 [ %15, %10 ], [ 0, %2 ]
%12 = phi i32 [ %17, %10 ], [ %8, %2 ]
%13 = trunc i64 %11 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %12)
%15 = add nuw i64 %11, 1
%16 = getelementptr inbounds i32, i32* %7, i64 %15
%17 = load i32, i32* %16
%18 = icmp sgt i32 %17, 0
br i1 %18, label %10, label %19
19: ; preds = %10, %2
%20 = load i32, i32* %3
%21 = call i32 @analise_fifo(i32 %20, i32* %7)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %21)
ret i32 0
}