#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  fp = fopen("myF.txt", "rt");
  char arr[8];
  while (fgets(arr, 8, fp) != NULL) {
    printf("%s\n", arr);
  }
  fclose(fp);
  printf("\n\n[press Enter to close]");
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11a9 <main+0x59>
lea    -0x18(%rbp),%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1176 <main+0x26>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x8,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11bd <main+0x5d>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"myF.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [25 x i8] c"\0A\0A[press Enter to close]\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [8 x i8]
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
br label %5
5: ; preds = %10, %0
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%7 = load i32*, i32** %2
%8 = call i32* @fgets(i8* %6, i32 8, i32* %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %5
13: ; preds = %5
%14 = load i32*, i32** %2
%15 = call i32 @fclose(i32* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"myF.txt\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.3 = [25 x i8] c"\0A\0A[press Enter to close]\00"
define i32 @main() {
%1 = alloca [8 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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 [8 x i8], [8 x i8]* %1, i64 0, i64 0
%4 = call i32* @fgets(i8* %3, i32 8, i32* %2)
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %0, %6
%7 = call i32 @puts(i8* %3)
%8 = call i32* @fgets(i8* %3, i32 8, i32* %2)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %6
10: ; preds = %6, %0
%11 = call i32 @fclose(i32* %2)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (...) @getchar()
ret i32 0
}