#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*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
char *simulation() {
  FILE *file = fopen("../simulation.txt", "rt");
  char values[100], *line;
  int i = 1;
  if (!file) {
    printf("Unable to open file\n");
    return 0;
  }
  while (!feof(file)) {
    line = fgets(values, 200, file);
    if (line) {
      printf("Coordenate %d : %s", i, values);
    }
    i++;
    sleep(1);
  }
  close(file);
}


x86 assembly (clang, -O0):
<simulation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x8c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b2 <simulation+0x52>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    123b <simulation+0xdb>
jmp    11b7 <simulation+0x57>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d5 <simulation+0x75>
jmp    1232 <simulation+0xd2>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <fgets@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     1214 <simulation+0xb4>
mov    -0x8c(%rbp),%esi
lea    -0x80(%rbp),%rdx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11b7 <simulation+0x57>
mov    -0x10(%rbp),%rdi
call   1040 <close@plt>
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simulation>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xe7f(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ab <simulation+0x3b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11c4 <simulation+0x54>
mov    %rbx,%rdi
call   1050 <close@plt>
jmp    11b7 <simulation+0x47>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
mov    %rsp,%r14
lea    0xe42(%rip),%r15
jmp    11f9 <simulation+0x89>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11a1 <simulation+0x31>
mov    %r14,%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e0 <simulation+0x70>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e0 <simulation+0x70>

LLVM IR (-O0):
@.str = [18 x i8] c"../simulation.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [21 x i8] c"Unable to open file\0A\00"
@.str.3 = [19 x i8] c"Coordenate %d : %s\00"
define i8* @simulation() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca [100 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
store i32 1, i32* %5
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
br label %34
11: ; preds = %0
br label %12
12: ; preds = %27, %11
%13 = load i32*, i32** %2
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %31
17: ; preds = %12
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = load i32*, i32** %2
%20 = call i8* @fgets(i8* %18, i32 200, i32* %19)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* %5
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %25)
br label %27
27: ; preds = %23, %17
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
%30 = call i32 @sleep(i32 1)
br label %12
31: ; preds = %12
%32 = load i32*, i32** %2
%33 = call i32 @close(i32* %32)
br label %34
34: ; preds = %31, %9
%35 = load i8*, i8** %1
ret i8* %35
}

LLVM IR (-O2):
@.str = [18 x i8] c"../simulation.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.3 = [19 x i8] c"Coordenate %d : %s\00"
@str = [20 x i8] c"Unable to open file\00"
define noalias i8* @simulation() {
%1 = alloca [100 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = icmp eq i32* %2, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @feof(i32* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %21
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %23
10: ; preds = %5, %16
%11 = phi i32 [ %17, %16 ], [ 1, %5 ]
%12 = call i8* @fgets(i8* %3, i32 200, i32* %2)
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %11, i8* %3)
br label %16
16: ; preds = %14, %10
%17 = add nuw nsw i32 %11, 1
%18 = call i32 @sleep(i32 1)
%19 = call i32 @feof(i32* %2)
%20 = icmp eq i32 %19, 0
br i1 %20, label %10, label %21
21: ; preds = %16, %5
%22 = call i32 @close(i32* %2)
br label %23
23: ; preds = %21, %8
ret i8* null
}