#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 */
char EOF;
int /*<<< orphan*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
void dump() {
  FILE *fp;
  char c;
  if (access("circular_buffer.txt", F_OK) == -1) {
    fprintf(stderr, "Buffer is not initialized.\n");
    exit(2);
  }
  if (!(fp = fopen("circular_buffer.txt", "r"))) {
    fprintf(stderr, "Could not open file.\n");
    exit(4);
  }
  printf("\nFile '%s' contains:\n\n", "circular_buffer.txt");
  while ((c = fgetc(fp)) != EOF)
    putchar(c);
  fclose(fp);
  putchar('\n');
}


x86 assembly (clang, -O0):
<dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    11c5 <dump+0x45>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xe34(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1205 <dump+0x85>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
lea    0xe3c(%rip),%rdi
lea    0xded(%rip),%rsi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
mov    0x2dba(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1247 <dump+0xc7>
movsbl -0x9(%rbp),%edi
call   1030 <putchar@plt>
jmp    1218 <dump+0x98>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump>:
push   %r14
push   %rbx
push   %rax
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    0xe6c(%rip),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
je     120e <dump+0x8e>
lea    0xe5b(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     122d <dump+0xad>
mov    %rax,%rbx
lea    0xe88(%rip),%rdi
lea    0xe39(%rip),%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e0d(%rip),%r14
cmp    (%r14),%al
je     11f5 <dump+0x75>
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
jne    11e0 <dump+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"circular_buffer.txt\00"
@F_OK = global i32 0
@stderr = global i32 0
@.str.1 = [28 x i8] c"Buffer is not initialized.\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [22 x i8] c"Could not open file.\0A\00"
@.str.4 = [23 x i8] c"\0AFile '%s' contains:\0A\0A\00"
@EOF = global i8 0
define void @dump() {
%1 = alloca i32*
%2 = alloca i8
%3 = load i32, i32* @F_OK
%4 = call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 2)
unreachable
10: ; preds = %0
%11 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %1
%12 = icmp ne i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @exit(i32 4)
unreachable
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %26, %17
%20 = load i32*, i32** %1
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %2
%22 = sext i8 %21 to i32
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i8, i8* %2
%28 = call i32 @putchar(i8 signext %27)
br label %19
29: ; preds = %19
%30 = load i32*, i32** %1
%31 = call i32 @fclose(i32* %30)
%32 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"circular_buffer.txt\00"
@F_OK = global i32 0
@stderr = global i32 0
@.str.1 = [28 x i8] c"Buffer is not initialized.\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [22 x i8] c"Could not open file.\0A\00"
@.str.4 = [23 x i8] c"\0AFile '%s' contains:\0A\0A\00"
@EOF = global i8 0
define void @dump() {
%1 = load i32, i32* @F_OK
%2 = tail call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 2)
unreachable
8: ; preds = %0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @exit(i32 4)
unreachable
15: ; preds = %8
%16 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%17 = tail call signext i8 @fgetc(i32* %9)
%18 = load i8, i8* @EOF
%19 = icmp eq i8 %17, %18
br i1 %19, label %26, label %20
20: ; preds = %15, %20
%21 = phi i8 [ %23, %20 ], [ %17, %15 ]
%22 = tail call i32 @putchar(i8 signext %21)
%23 = tail call signext i8 @fgetc(i32* %9)
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %26, label %20
26: ; preds = %20, %15
%27 = tail call i32 @fclose(i32* %9)
%28 = tail call i32 @putchar(i8 signext 10)
ret void
}