#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*/ F_OK;
int /*<<< orphan*/ SEEK_SET;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
void get() {
  FILE *fp;
  int size, low, high;
  int value;
  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);
  }
  fscanf(fp, "%d\n", &size);
  fscanf(fp, "%d\n", &low);
  fscanf(fp, "%d\n", &high);
  if (high == low) {
    fprintf(stderr, "Buffer empty, can't extract more data.\n");
    exit(6);
  }
  if (fseek(fp, (low + 3) * 9L, SEEK_SET) < 0) {
    fprintf(stderr, "Invalid pointer.\n");
    exit(5);
  }
  fscanf(fp, "%d\n", &value);
  low++;
  if (low >= size)
    low = 0;
  if (fseek(fp, 1 * 9L, SEEK_SET) < 0) {
    fprintf(stderr, "Invalid pointer.\n");
    exit(5);
  }
  fprintf(fp, "%8d\n", low);
  printf("%d\n", value);
  fclose(fp);
}


x86 assembly (clang, -O0):
<get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    11c8 <get+0x48>
mov    0x2e33(%rip),%rax
movslq (%rax),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xe31(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    120b <get+0x8b>
mov    0x2df0(%rip),%rax
movslq (%rax),%rdi
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe1f(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe0b(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    1275 <get+0xf5>
mov    0x2d86(%rip),%rax
movslq (%rax),%rdi
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x6,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
add    $0x3,%eax
cltq
imul   $0x9,%rax,%rax
mov    %eax,%esi
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
jge    12c1 <get+0x141>
mov    0x2d3a(%rip),%rax
movslq (%rax),%rdi
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xd7d(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     12f1 <get+0x171>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2cdc(%rip),%rax
mov    (%rax),%edx
mov    $0x9,%esi
call   1070 <fseek@plt>
cmp    $0x0,%rax
jge    1334 <get+0x1b4>
mov    0x2cc7(%rip),%rax
movslq (%rax),%rdi
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%esi
lea    0xcf6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe59(%rip),%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
je     12d2 <get+0x142>
lea    0xe44(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12fc <get+0x16c>
mov    %rax,%rbx
lea    0xe6e(%rip),%r14
lea    0x14(%rsp),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fscanf@plt>
mov    0x8(%rsp),%eax
cmp    %eax,0x10(%rsp)
je     1326 <get+0x196>
lea    (%rax,%rax,8),%esi
add    $0x1b,%esi
mov    0x2db2(%rip),%r14
mov    (%r14),%edx
mov    %rbx,%rdi
call   1070 <fseek@plt>
test   %rax,%rax
js     12a8 <get+0x118>
lea    0xe0c(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <fscanf@plt>
mov    0x8(%rsp),%eax
add    $0x1,%eax
xor    %ecx,%ecx
cmp    0x14(%rsp),%eax
cmovl  %eax,%ecx
mov    %ecx,0x8(%rsp)
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1070 <fseek@plt>
test   %rax,%rax
js     12a8 <get+0x118>
mov    0x8(%rsp),%edx
lea    0xe09(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0xc(%rsp),%esi
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d31(%rip),%rax
movslq (%rax),%rcx
lea    0xdbc(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    0x2d07(%rip),%rax
movslq (%rax),%rcx
lea    0xd31(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x2cdd(%rip),%rax
movslq (%rax),%rcx
lea    0xd26(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    0x2cb3(%rip),%rax
movslq (%rax),%rcx
lea    0xd16(%rip),%rdi
mov    $0x27,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0x6,%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 = [3 x i8] c"r+\00"
@.str.3 = [22 x i8] c"Could not open file.\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [40 x i8] c"Buffer empty, can't extract more data.\0A\00"
@SEEK_SET = global i32 0
@.str.6 = [18 x i8] c"Invalid pointer.\0A\00"
@.str.7 = [5 x i8] c"%8d\0A\00"
define void @get() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = load i32, i32* @F_OK
%7 = call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %0
%16 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %16, i32** %1
%17 = icmp ne i32* %16, null
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i32*
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 4)
unreachable
24: ; preds = %15
%25 = load i32*, i32** %1
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%27 = load i32*, i32** %1
%28 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%29 = load i32*, i32** %1
%30 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%31 = load i32, i32* %4
%32 = load i32, i32* %3
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %24
%35 = load i32, i32* @stderr
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i32*
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @exit(i32 6)
unreachable
40: ; preds = %24
%41 = load i32*, i32** %1
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 3
%44 = sext i32 %43 to i64
%45 = mul nsw i64 %44, 9
%46 = trunc i64 %45 to i32
%47 = load i32, i32* @SEEK_SET
%48 = call i64 @fseek(i32* %41, i32 %46, i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %40
%51 = load i32, i32* @stderr
%52 = sext i32 %51 to i64
%53 = inttoptr i64 %52 to i32*
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%55 = call i32 @exit(i32 5)
unreachable
56: ; preds = %40
%57 = load i32*, i32** %1
%58 = call i32 @fscanf(i32* %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 1
store i32 %60, i32* %3
%61 = load i32, i32* %3
%62 = load i32, i32* %2
%63 = icmp sge i32 %61, %62
br i1 %63, label %64, label %65
64: ; preds = %56
store i32 0, i32* %3
br label %65
65: ; preds = %64, %56
%66 = load i32*, i32** %1
%67 = load i32, i32* @SEEK_SET
%68 = call i64 @fseek(i32* %66, i32 9, i32 %67)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %76
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = sext i32 %71 to i64
%73 = inttoptr i64 %72 to i32*
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @exit(i32 5)
unreachable
76: ; preds = %65
%77 = load i32*, i32** %1
%78 = load i32, i32* %3
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %78)
%80 = load i32, i32* %5
%81 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %80)
%82 = load i32*, i32** %1
%83 = call i32 @fclose(i32* %82)
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 = [3 x i8] c"r+\00"
@.str.3 = [22 x i8] c"Could not open file.\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [40 x i8] c"Buffer empty, can't extract more data.\0A\00"
@SEEK_SET = global i32 0
@.str.6 = [18 x i8] c"Invalid pointer.\0A\00"
@.str.7 = [5 x i8] c"%8d\0A\00"
define void @get() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = load i32, i32* @F_OK
%10 = tail call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %18
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 27, i64 1, i32* %15)
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %0
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i64 21, i64 1, i32* %24)
%26 = tail call i32 @exit(i32 4)
unreachable
27: ; preds = %18
%28 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%29 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%30 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%31 = load i32, i32* %3
%32 = load i32, i32* %2
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i32*
%38 = call i64 @fwrite(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i64 39, i64 1, i32* %37)
%39 = call i32 @exit(i32 6)
unreachable
40: ; preds = %27
%41 = mul i32 %32, 9
%42 = add i32 %41, 27
%43 = load i32, i32* @SEEK_SET
%44 = call i64 @fseek(i32* %19, i32 %42, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %40
%47 = load i32, i32* @stderr
%48 = sext i32 %47 to i64
%49 = inttoptr i64 %48 to i32*
%50 = call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i64 17, i64 1, i32* %49)
%51 = call i32 @exit(i32 5)
unreachable
52: ; preds = %40
%53 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
%56 = load i32, i32* %1
%57 = icmp slt i32 %55, %56
%58 = select i1 %57, i32 %55, i32 0
store i32 %58, i32* %2
%59 = load i32, i32* @SEEK_SET
%60 = call i64 @fseek(i32* %19, i32 9, i32 %59)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %52
%63 = load i32, i32* @stderr
%64 = sext i32 %63 to i64
%65 = inttoptr i64 %64 to i32*
%66 = call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i64 17, i64 1, i32* %65)
%67 = call i32 @exit(i32 5)
unreachable
68: ; preds = %52
%69 = load i32, i32* %2
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %69)
%71 = load i32, i32* %4
%72 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %71)
%73 = call i32 @fclose(i32* %19)
ret void
}