#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*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ puts(char *);
int main() {
  char *pline;
  FILE *fptr;
  fptr = fopen("Lyrics.txt", "w");
  fprintf(fptr, "Hey This is inital file..");
  fclose(fptr);
  fptr = fopen("Lyrics.txt", "r");
  pline = (char *)malloc(200 * sizeof(char));
  while (1) {
    fgets(pline, 200, fptr);
    puts(pline);
    if (feof(fptr)) {
      break;
    }
  }
  fclose(fptr);
  free(pline);
  fptr = fopen("Lyrics.txt", "a");
  fprintf(fptr, "\nhere we have a simple line");
  fprintf(fptr, "\nhere we have another simple line");
  fclose(fptr);
  fptr = fopen("Lyrics.txt", "r");
  pline = (char *)malloc(200 * sizeof(char));
  while (1) {
    fgets(pline, 200, fptr);
    puts(pline);
    if (feof(fptr)) {
      break;
    }
  }
  fclose(fptr);
  free(pline);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xe3a(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0xc8,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xc8,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1217 <main+0x97>
jmp    121c <main+0x9c>
jmp    11e4 <main+0x64>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xdcb(%rip),%rdi
lea    0xded(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd8b(%rip),%rdi
lea    0xdab(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0xc8,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xc8,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     12c6 <main+0x146>
jmp    12cb <main+0x14b>
jmp    1293 <main+0x113>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe75(%rip),%r14
lea    0xe79(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0xe69(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe62(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    $0xc8,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
nopl   (%rax)
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11e0 <main+0x60>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xde4(%rip),%r14
lea    0xe06(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0xdf6(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
lea    0xdf9(%rip),%rdi
mov    $0x21,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xdb8(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    $0xc8,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     1290 <main+0x110>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"Lyrics.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"Hey This is inital file..\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [28 x i8] c"\0Ahere we have a simple line\00"
@.str.6 = [34 x i8] c"\0Ahere we have another simple line\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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
%5 = load i32*, i32** %3
%6 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32*, i32** %3
%8 = call i32 @fclose(i32* %7)
%9 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %3
%10 = call i64 @malloc(i32 200)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %2
br label %12
12: ; preds = %0, %22
%13 = load i8*, i8** %2
%14 = load i32*, i32** %3
%15 = call i32 @fgets(i8* %13, i32 200, i32* %14)
%16 = load i8*, i8** %2
%17 = call i32 @puts(i8* %16)
%18 = load i32*, i32** %3
%19 = call i64 @feof(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %12
br label %23
22: ; preds = %12
br label %12
23: ; preds = %21
%24 = load i32*, i32** %3
%25 = call i32 @fclose(i32* %24)
%26 = load i8*, i8** %2
%27 = call i32 @free(i8* %26)
%28 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %28, i32** %3
%29 = load i32*, i32** %3
%30 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32*, i32** %3
%32 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32*, i32** %3
%34 = call i32 @fclose(i32* %33)
%35 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %3
%36 = call i64 @malloc(i32 200)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %2
br label %38
38: ; preds = %23, %48
%39 = load i8*, i8** %2
%40 = load i32*, i32** %3
%41 = call i32 @fgets(i8* %39, i32 200, i32* %40)
%42 = load i8*, i8** %2
%43 = call i32 @puts(i8* %42)
%44 = load i32*, i32** %3
%45 = call i64 @feof(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %38
br label %49
48: ; preds = %38
br label %38
49: ; preds = %47
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
%52 = load i8*, i8** %2
%53 = call i32 @free(i8* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"Lyrics.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [26 x i8] c"Hey This is inital file..\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [28 x i8] c"\0Ahere we have a simple line\00"
@.str.6 = [34 x i8] c"\0Ahere we have another simple line\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 25, i64 1, i32* %1)
%3 = tail call i32 @fclose(i32* %1)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i64 @malloc(i32 200)
%6 = inttoptr i64 %5 to i8*
br label %7
7: ; preds = %7, %0
%8 = tail call i32 @fgets(i8* %6, i32 200, i32* %4)
%9 = tail call i32 @puts(i8* dereferenceable(1) %6)
%10 = tail call i64 @feof(i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %7, label %12
12: ; preds = %7
%13 = tail call i32 @fclose(i32* %4)
%14 = tail call i32 @free(i8* %6)
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i64 27, i64 1, i32* %15)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i64 33, i64 1, i32* %15)
%18 = tail call i32 @fclose(i32* %15)
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = tail call i64 @malloc(i32 200)
%21 = inttoptr i64 %20 to i8*
br label %22
22: ; preds = %22, %12
%23 = tail call i32 @fgets(i8* %21, i32 200, i32* %19)
%24 = tail call i32 @puts(i8* dereferenceable(1) %21)
%25 = tail call i64 @feof(i32* %19)
%26 = icmp eq i64 %25, 0
br i1 %26, label %22, label %27
27: ; preds = %22
%28 = tail call i32 @fclose(i32* %19)
%29 = tail call i32 @free(i8* %21)
ret i32 0
}