#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ puts(char *);
int main() {
  char file[300];
  FILE *fptr;
  fptr = fopen("/home/mohit/Desktop/c-programs/myfile.txt", "r");
  while (1) {
    if (fgets(file, 300, fptr) != NULL) {
      puts(file);
    }
    if (feof(fptr)) {
      break;
    }
  }
  fclose(fptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    $0x12c,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11aa <main+0x5a>
lea    -0x130(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x138(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11c5 <main+0x75>
jmp    11ca <main+0x7a>
jmp    117c <main+0x2c>
mov    -0x138(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x138,%rsp
lea    0xe9f(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
jmp    118d <main+0x3d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11ac <main+0x5c>
mov    %r14,%rdi
mov    $0x12c,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1180 <main+0x30>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1180 <main+0x30>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [42 x i8] c"/home/mohit/Desktop/c-programs/myfile.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [300 x i8]
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
br label %5
5: ; preds = %0, %18
%6 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%7 = load i32*, i32** %3
%8 = call i32* @fgets(i8* %6, i32 300, i32* %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%12 = call i32 @puts(i8* %11)
br label %13
13: ; preds = %10, %5
%14 = load i32*, i32** %3
%15 = call i64 @feof(i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %19
18: ; preds = %13
br label %5
19: ; preds = %17
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
ret i32 0
}

LLVM IR (-O2):
@.str = [42 x i8] c"/home/mohit/Desktop/c-programs/myfile.txt\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main() {
%1 = alloca [300 x i8]
%2 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %9, %0
%5 = call i32* @fgets(i8* %2, i32 300, i32* %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = call i32 @puts(i8* %2)
br label %9
9: ; preds = %7, %4
%10 = call i64 @feof(i32* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %4, label %12
12: ; preds = %9
%13 = call i32 @fclose(i32* %3)
ret i32 0
}