#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*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main() {
  FILE *fp;
  int ch;
  fp = fopen("file.txt", "r");
  if (fp != NULL) {
    while (!feof(fp)) {
      ch = fgetc(fp);
      printf("%c", ch);
    }
    rewind(fp);
    while (!feof(fp)) {
      ch = fgetc(fp);
      printf("%c", ch);
    }
    fclose(fp);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1224 <main+0xc4>
jmp    1196 <main+0x36>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b4 <main+0x54>
jmp    11d4 <main+0x74>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
jmp    1196 <main+0x36>
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fb <main+0x9b>
jmp    121b <main+0xbb>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
jmp    11dd <main+0x7d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@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    0xe97(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1206 <main+0xa6>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11be <main+0x5e>
lea    0xe75(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11a0 <main+0x40>
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11fe <main+0x9e>
lea    0xe32(%rip),%r14
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11e0 <main+0x80>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %34
7: ; preds = %0
br label %8
8: ; preds = %13, %7
%9 = load i32*, i32** %2
%10 = call i32 @feof(i32* %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32*, i32** %2
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %8
18: ; preds = %8
%19 = load i32*, i32** %2
%20 = call i32 @rewind(i32* %19)
br label %21
21: ; preds = %26, %18
%22 = load i32*, i32** %2
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i32*, i32** %2
%28 = call i32 @fgetc(i32* %27)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %21
31: ; preds = %21
%32 = load i32*, i32** %2
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %31, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %22, label %3
3: ; preds = %0
%4 = tail call i32 @feof(i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %3, %6
%7 = tail call i32 @fgetc(i32* %1)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 @feof(i32* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %6, label %11
11: ; preds = %6, %3
%12 = tail call i32 @rewind(i32* %1)
%13 = tail call i32 @feof(i32* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11, %15
%16 = tail call i32 @fgetc(i32* %1)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = tail call i32 @feof(i32* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %15, %11
%21 = tail call i32 @fclose(i32* %1)
br label %22
22: ; preds = %20, %0
ret i32 0
}