#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*/ s;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int main02() {
  char s[1024] = {0};
  FILE *p = fopen("D:\\temp\\main.c", "r");
  while (!feof(p)) {
    memset(s, 0, sizeof(s));
    fgets(s, sizeof(s), p);
    printf("%s", s);
  }
  fclose(p);
  return 0;
}


x86 assembly (clang, -O0):
<main02>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    -0x400(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    0xe7b(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b9 <main02+0x59>
jmp    11fc <main02+0x9c>
lea    -0x400(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x400(%rbp),%rdi
mov    -0x408(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
lea    -0x400(%rbp),%rsi
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
jmp    1198 <main02+0x38>
mov    -0x408(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main02>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe7e(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11e6 <main02+0x86>
mov    %rsp,%r14
lea    0xe6a(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11b0 <main02+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"D:\\temp\\main.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main02() {
%1 = alloca [1024 x i8]
%2 = alloca i32*
%3 = bitcast [1024 x i8]* %1 to i8*
%4 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 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** %2
br label %5
5: ; preds = %10, %0
%6 = load i32*, i32** %2
%7 = call i32 @feof(i32* %6)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 1024)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i32 @fgets(i8* %13, i32 1024, i32* %14)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %5
18: ; preds = %5
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"D:\\temp\\main.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main02() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @feof(i32* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0, %6
%7 = call i32 @memset(i8* %2, i32 0, i32 1024)
%8 = call i32 @fgets(i8* %2, i32 1024, i32* %3)
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%10 = call i32 @feof(i32* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %6, label %12
12: ; preds = %6, %0
%13 = call i32 @fclose(i32* %3)
ret i32 0
}