#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 EXIT_FAILURE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int main() {
  FILE *fp = fopen("in.txt", "r");
  if (fp == NULL) {
    perror("Can't open file");
    return EXIT_FAILURE;
  }
  int ch;
  ch = fgetc(fp);
  printf("%c\n", (char)ch);
  ch = fgetc(fp);
  printf("%c\n", (char)ch);
  fseek(fp, 0, 0);
  ch = fgetc(fp);
  printf("%c\n", (char)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    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ae <main+0x4e>
lea    0xe71(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1225 <main+0xc5>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
lea    0xe55(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
lea    0xe37(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
lea    0xe0c(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11dc <main+0x7c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
movsbl %al,%esi
lea    0xe88(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
movsbl %al,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
movsbl %al,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe26(%rip),%rdi
call   1080 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%ebp
jmp    11d5 <main+0x75>

LLVM IR (-O0):
@.str = [7 x i8] c"in.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"Can't open file\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%c\0A\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 ([7 x i8], [7 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 eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
store i32 %9, i32* %1
br label %30
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = trunc i32 %13 to i8
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %14)
%16 = load i32*, i32** %2
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = trunc i32 %18 to i8
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %19)
%21 = load i32*, i32** %2
%22 = call i32 @fseek(i32* %21, i32 0, i32 0)
%23 = load i32*, i32** %2
%24 = call i32 @fgetc(i32* %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = trunc i32 %25 to i8
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %26)
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %1
br label %30
30: ; preds = %10, %7
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [7 x i8] c"in.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"Can't open file\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 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 %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
br label %18
6: ; preds = %0
%7 = tail call i32 @fgetc(i32* %1)
%8 = trunc i32 %7 to i8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %8)
%10 = tail call i32 @fgetc(i32* %1)
%11 = trunc i32 %10 to i8
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %11)
%13 = tail call i32 @fseek(i32* %1, i32 0, i32 0)
%14 = tail call i32 @fgetc(i32* %1)
%15 = trunc i32 %14 to i8
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %15)
%17 = tail call i32 @fclose(i32* %1)
br label %18
18: ; preds = %6, %3
%19 = phi i32 [ %5, %3 ], [ 0, %6 ]
ret i32 %19
}