#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 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*/ stderr;
void init(const char *s) {
  int size = atoi(s);
  FILE *fp;
  int i;
  if (access("circular_buffer.txt", F_OK) != -1) {
    fprintf(stderr, "Buffer exists already.\n");
    exit(2);
  }
  if (size < 1) {
    fprintf(stderr, "Invalid size.\n");
    exit(3);
  }
  if (!(fp = fopen("circular_buffer.txt", "w"))) {
    fprintf(stderr, "Could not open file.\n");
    exit(4);
  }
  fprintf(fp, "%8d\n", size);
  fprintf(fp, "%8d\n", 0);
  fprintf(fp, "%8d\n", 0);
  for (i = 0; i < size + 1; i++)
    fprintf(fp, "%8d\n", -1);
  fclose(fp);
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11b8 <init+0x58>
mov    0x2e43(%rip),%rax
movslq (%rax),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
cmpl   $0x1,-0xc(%rbp)
jge    11e4 <init+0x84>
mov    0x2e17(%rip),%rax
movslq (%rax),%rdi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x3,%edi
call   1080 <exit@plt>
lea    0xe15(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1227 <init+0xc7>
mov    0x2dd4(%rip),%rax
movslq (%rax),%rdi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x4,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe0c(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf8(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    12a1 <init+0x141>
mov    -0x18(%rbp),%rdi
lea    0xdcc(%rip),%rsi
mov    $0xffffffff,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    126b <init+0x10b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %r15
push   %r14
push   %rbx
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
jne    1224 <init+0xb4>
test   %ebx,%ebx
jle    124e <init+0xde>
lea    0xe57(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1278 <init+0x108>
mov    %rax,%r14
lea    0xe8b(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0xffffffff,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
jne    1200 <init+0x90>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
mov    0x2db5(%rip),%rax
movslq (%rax),%rcx
lea    0xddf(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2d8b(%rip),%rax
movslq (%rax),%rcx
lea    0xdcd(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0x3,%edi
call   1080 <exit@plt>
mov    0x2d61(%rip),%rax
movslq (%rax),%rcx
lea    0xdb4(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    $0x4,%edi
call   1080 <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 = [24 x i8] c"Buffer exists already.\0A\00"
@.str.2 = [15 x i8] c"Invalid size.\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [22 x i8] c"Could not open file.\0A\00"
@.str.5 = [5 x i8] c"%8d\0A\00"
define void @init(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @atoi(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* @F_OK
%9 = call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i32*
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %1
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i32*
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 3)
unreachable
26: ; preds = %17
%27 = 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.3, i64 0, i64 0))
store i32* %27, i32** %4
%28 = icmp ne i32* %27, null
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to i32*
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @exit(i32 4)
unreachable
35: ; preds = %26
%36 = load i32*, i32** %4
%37 = load i32, i32* %3
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** %4
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 0)
%41 = load i32*, i32** %4
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 0)
store i32 0, i32* %5
br label %43
43: ; preds = %51, %35
%44 = load i32, i32* %5
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
%47 = icmp slt i32 %44, %46
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = load i32*, i32** %4
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 -1)
br label %51
51: ; preds = %48
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %43
54: ; preds = %43
%55 = load i32*, i32** %4
%56 = call i32 @fclose(i32* %55)
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 = [24 x i8] c"Buffer exists already.\0A\00"
@.str.2 = [15 x i8] c"Invalid size.\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [22 x i8] c"Could not open file.\0A\00"
@.str.5 = [5 x i8] c"%8d\0A\00"
define void @init(i8* nocapture %0) {
%2 = tail call i32 @atoi(i8* %0)
%3 = load i32, i32* @F_OK
%4 = tail 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 %12, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 23, i64 1, i32* %9)
%11 = tail call i32 @exit(i32 2)
unreachable
12: ; preds = %1
%13 = icmp slt i32 %2, 1
br i1 %13, label %14, label %20
14: ; preds = %12
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 14, i64 1, i32* %17)
%19 = tail call i32 @exit(i32 3)
unreachable
20: ; preds = %12
%21 = 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.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i32*
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i64 21, i64 1, i32* %26)
%28 = tail call i32 @exit(i32 4)
unreachable
29: ; preds = %20
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %2)
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 0)
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 0)
br label %33
33: ; preds = %29, %33
%34 = phi i32 [ %36, %33 ], [ 0, %29 ]
%35 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 -1)
%36 = add nuw i32 %34, 1
%37 = icmp eq i32 %34, %2
br i1 %37, label %38, label %33
38: ; preds = %33
%39 = tail call i32 @fclose(i32* %21)
ret void
}