#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 atoi(char const *);
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*/ stderr;
void put(const char *s) {
  int value = atoi(s);
  FILE *fp;
  int size, low, high;
  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 (fseek(fp, (high + 3) * 9L, SEEK_SET) < 0) {
    fprintf(stderr, "Invalid pointer.\n");
    exit(5);
  }
  high++;
  if (high >= size)
    high = 0;
  if (high == low) {
    fprintf(stderr, "Buffer full, can't store more data.\n");
    exit(6);
  }
  fprintf(fp, "%8d\n", value);
  if (fseek(fp, 2 * 9L, SEEK_SET) < 0) {
    fprintf(stderr, "Invalid pointer.\n");
    exit(5);
  }
  fprintf(fp, "%8d\n", high);
  fclose(fp);
}


x86 assembly (clang, -O0):
<put>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
jne    11d8 <put+0x58>
mov    0x2e23(%rip),%rax
movslq (%rax),%rdi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xe21(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121b <put+0x9b>
mov    0x2de0(%rip),%rax
movslq (%rax),%rdi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe23(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe0f(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdfb(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    $0x3,%eax
cltq
imul   $0x9,%rax,%rax
mov    %eax,%esi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
cmp    $0x0,%rax
jge    12a3 <put+0x123>
mov    0x2d58(%rip),%rax
movslq (%rax),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     12bf <put+0x13f>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    12ed <put+0x16d>
mov    0x2d0e(%rip),%rax
movslq (%rax),%rdi
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x6,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ccb(%rip),%rax
mov    (%rax),%edx
mov    $0x12,%esi
call   1060 <fseek@plt>
cmp    $0x0,%rax
jge    1345 <put+0x1c5>
mov    0x2cb6(%rip),%rax
movslq (%rax),%rdi
lea    0xd19(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    0xe50(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     12cc <put+0x13c>
lea    0xe3b(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12f6 <put+0x166>
mov    %rax,%rbx
lea    0xe65(%rip),%rbp
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <fscanf@plt>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <fscanf@plt>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <fscanf@plt>
mov    0x4(%rsp),%eax
lea    (%rax,%rax,8),%esi
add    $0x1b,%esi
mov    0x2db3(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
call   1060 <fseek@plt>
test   %rax,%rax
js     12a2 <put+0x112>
mov    0x4(%rsp),%eax
add    $0x1,%eax
xor    %ecx,%ecx
cmp    0xc(%rsp),%eax
cmovl  %eax,%ecx
mov    %ecx,0x4(%rsp)
cmp    0x8(%rsp),%ecx
je     1320 <put+0x190>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x12,%esi
call   1060 <fseek@plt>
test   %rax,%rax
js     12a2 <put+0x112>
mov    0x4(%rsp),%edx
lea    0xdfd(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d37(%rip),%rax
movslq (%rax),%rcx
lea    0xd9a(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0x5,%edi
call   10a0 <exit@plt>
mov    0x2d0d(%rip),%rax
movslq (%rax),%rcx
lea    0xd37(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x2ce3(%rip),%rax
movslq (%rax),%rcx
lea    0xd2c(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    $0x4,%edi
call   10a0 <exit@plt>
mov    0x2cb9(%rip),%rax
movslq (%rax),%rcx
lea    0xd2e(%rip),%rdi
mov    $0x24,%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"
@SEEK_SET = global i32 0
@.str.5 = [18 x i8] c"Invalid pointer.\0A\00"
@.str.6 = [37 x i8] c"Buffer full, can't store more data.\0A\00"
@.str.7 = [5 x i8] c"%8d\0A\00"
define void @put(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @atoi(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* @F_OK
%11 = call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 2)
unreachable
19: ; preds = %1
%20 = 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* %20, i32** %4
%21 = icmp ne i32* %20, null
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = sext i32 %23 to i64
%25 = inttoptr i64 %24 to i32*
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @exit(i32 4)
unreachable
28: ; preds = %19
%29 = load i32*, i32** %4
%30 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%31 = load i32*, i32** %4
%32 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%33 = load i32*, i32** %4
%34 = call i32 @fscanf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %7)
%35 = load i32*, i32** %4
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 3
%38 = sext i32 %37 to i64
%39 = mul nsw i64 %38, 9
%40 = trunc i64 %39 to i32
%41 = load i32, i32* @SEEK_SET
%42 = call i64 @fseek(i32* %35, i32 %40, i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %28
%45 = load i32, i32* @stderr
%46 = sext i32 %45 to i64
%47 = inttoptr i64 %46 to i32*
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 @exit(i32 5)
unreachable
50: ; preds = %28
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = load i32, i32* %5
%55 = icmp sge i32 %53, %54
br i1 %55, label %56, label %57
56: ; preds = %50
store i32 0, i32* %7
br label %57
57: ; preds = %56, %50
%58 = load i32, i32* %7
%59 = load i32, i32* %6
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %67
61: ; preds = %57
%62 = load i32, i32* @stderr
%63 = sext i32 %62 to i64
%64 = inttoptr i64 %63 to i32*
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %64, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%66 = call i32 @exit(i32 6)
unreachable
67: ; preds = %57
%68 = load i32*, i32** %4
%69 = load i32, i32* %3
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %69)
%71 = load i32*, i32** %4
%72 = load i32, i32* @SEEK_SET
%73 = call i64 @fseek(i32* %71, i32 18, i32 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %67
%76 = load i32, i32* @stderr
%77 = sext i32 %76 to i64
%78 = inttoptr i64 %77 to i32*
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%80 = call i32 @exit(i32 5)
unreachable
81: ; preds = %67
%82 = load i32*, i32** %4
%83 = load i32, i32* %7
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %82, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %83)
%85 = load i32*, i32** %4
%86 = call i32 @fclose(i32* %85)
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"
@SEEK_SET = global i32 0
@.str.5 = [18 x i8] c"Invalid pointer.\0A\00"
@.str.6 = [37 x i8] c"Buffer full, can't store more data.\0A\00"
@.str.7 = [5 x i8] c"%8d\0A\00"
define void @put(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32 @atoi(i8* %0)
%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 = %1
%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 = %1
%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* %2)
%29 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%30 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%31 = load i32, i32* %4
%32 = mul i32 %31, 9
%33 = add i32 %32, 27
%34 = load i32, i32* @SEEK_SET
%35 = call i64 @fseek(i32* %19, i32 %33, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %27
%38 = load i32, i32* @stderr
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i32*
%41 = call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i64 17, i64 1, i32* %40)
%42 = call i32 @exit(i32 5)
unreachable
43: ; preds = %27
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
%46 = load i32, i32* %2
%47 = icmp slt i32 %45, %46
%48 = select i1 %47, i32 %45, i32 0
store i32 %48, i32* %4
%49 = load i32, i32* %3
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %57
51: ; preds = %43
%52 = load i32, i32* @stderr
%53 = sext i32 %52 to i64
%54 = inttoptr i64 %53 to i32*
%55 = call i64 @fwrite(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i64 36, i64 1, i32* %54)
%56 = call i32 @exit(i32 6)
unreachable
57: ; preds = %43
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %5)
%59 = load i32, i32* @SEEK_SET
%60 = call i64 @fseek(i32* %19, i32 18, i32 %59)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %57
%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.5, i64 0, i64 0), i64 17, i64 1, i32* %65)
%67 = call i32 @exit(i32 5)
unreachable
68: ; preds = %57
%69 = load i32, i32* %4
%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 = call i32 @fclose(i32* %19)
ret void
}