#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 */

/* Variables and functions */
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ readlink(char *, char *, int);
int /*<<< orphan*/ readlinkat(int, char *, char *, int);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ write(int, char *, int);
void bufferAccessOutOfBounds(int fd) {
  char a[5];
  read(fd, a, 5);
  read(fd, a, 6);
  write(fd, a, 5);
  write(fd, a, 6);
  recv(fd, a, 5, 0);
  recv(fd, a, 6, 0);
  recvfrom(fd, a, 5, 0, 0x0, 0x0);
  recvfrom(fd, a, 6, 0, 0x0, 0x0);
  send(fd, a, 5, 0);
  send(fd, a, 6, 0);
  sendto(fd, a, 5, 0, 0x0, 0x0);
  sendto(fd, a, 6, 0, 0x0, 0x0);
  0;
  readlink("path", a, 5);
  readlink("path", a, 6);
  readlinkat(1, "path", a, 5);
  readlinkat(1, "path", a, 6);
  gethostname(a, 5);
  gethostname(a, 6);
}


x86 assembly (clang, -O0):
<bufferAccessOutOfBounds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x5,%edx
call   1080 <read@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x6,%edx
call   1080 <read@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x5,%edx
call   1050 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x6,%edx
call   1050 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x5,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   10a0 <recvfrom@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x6,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   10a0 <recvfrom@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x5,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1070 <sendto@plt>
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x6,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1070 <sendto@plt>
lea    -0x9(%rbp),%rsi
lea    0xd62(%rip),%rdi
mov    $0x5,%edx
call   1040 <readlink@plt>
lea    -0x9(%rbp),%rsi
lea    0xd4d(%rip),%rdi
mov    $0x6,%edx
call   1040 <readlink@plt>
lea    -0x9(%rbp),%rdx
mov    $0x1,%edi
lea    0xd33(%rip),%rsi
mov    $0x5,%ecx
call   1090 <readlinkat@plt>
lea    -0x9(%rbp),%rdx
mov    $0x1,%edi
lea    0xd19(%rip),%rsi
mov    $0x6,%ecx
call   1090 <readlinkat@plt>
lea    -0x9(%rbp),%rdi
mov    $0x5,%esi
call   10b0 <gethostname@plt>
lea    -0x9(%rbp),%rdi
mov    $0x6,%esi
call   10b0 <gethostname@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferAccessOutOfBounds>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x3(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x5,%edx
call   1080 <read@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1080 <read@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1050 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1050 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <sendto@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <sendto@plt>
lea    0xd85(%rip),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1040 <readlink@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1040 <readlink@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    $0x5,%ecx
call   1090 <readlinkat@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    $0x6,%ecx
call   1090 <readlinkat@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   10b0 <gethostname@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
call   10b0 <gethostname@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"path\00"
define void @bufferAccessOutOfBounds(i32 %0) {
%2 = alloca i32
%3 = alloca [5 x i8]
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = call i32 @read(i32 %4, i8* %5, i32 5)
%7 = load i32, i32* %2
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 6)
%10 = load i32, i32* %2
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%12 = call i32 @write(i32 %10, i8* %11, i32 5)
%13 = load i32, i32* %2
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%15 = call i32 @write(i32 %13, i8* %14, i32 6)
%16 = load i32, i32* %2
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%18 = call i32 @recv(i32 %16, i8* %17, i32 5, i32 0)
%19 = load i32, i32* %2
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%21 = call i32 @recv(i32 %19, i8* %20, i32 6, i32 0)
%22 = load i32, i32* %2
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%24 = call i32 @recvfrom(i32 %22, i8* %23, i32 5, i32 0, i32 0, i32 0)
%25 = load i32, i32* %2
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%27 = call i32 @recvfrom(i32 %25, i8* %26, i32 6, i32 0, i32 0, i32 0)
%28 = load i32, i32* %2
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%30 = call i32 @send(i32 %28, i8* %29, i32 5, i32 0)
%31 = load i32, i32* %2
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%33 = call i32 @send(i32 %31, i8* %32, i32 6, i32 0)
%34 = load i32, i32* %2
%35 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%36 = call i32 @sendto(i32 %34, i8* %35, i32 5, i32 0, i32 0, i32 0)
%37 = load i32, i32* %2
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%39 = call i32 @sendto(i32 %37, i8* %38, i32 6, i32 0, i32 0, i32 0)
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%41 = call i32 @readlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %40, i32 5)
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%43 = call i32 @readlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %42, i32 6)
%44 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%45 = call i32 @readlinkat(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %44, i32 5)
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%47 = call i32 @readlinkat(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %46, i32 6)
%48 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%49 = call i32 @gethostname(i8* %48, i32 5)
%50 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%51 = call i32 @gethostname(i8* %50, i32 6)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"path\00"
define void @bufferAccessOutOfBounds(i32 %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 5)
%5 = call i32 @read(i32 %0, i8* %3, i32 6)
%6 = call i32 @write(i32 %0, i8* %3, i32 5)
%7 = call i32 @write(i32 %0, i8* %3, i32 6)
%8 = call i32 @recv(i32 %0, i8* %3, i32 5, i32 0)
%9 = call i32 @recv(i32 %0, i8* %3, i32 6, i32 0)
%10 = call i32 @recvfrom(i32 %0, i8* %3, i32 5, i32 0, i32 0, i32 0)
%11 = call i32 @recvfrom(i32 %0, i8* %3, i32 6, i32 0, i32 0, i32 0)
%12 = call i32 @send(i32 %0, i8* %3, i32 5, i32 0)
%13 = call i32 @send(i32 %0, i8* %3, i32 6, i32 0)
%14 = call i32 @sendto(i32 %0, i8* %3, i32 5, i32 0, i32 0, i32 0)
%15 = call i32 @sendto(i32 %0, i8* %3, i32 6, i32 0, i32 0, i32 0)
%16 = call i32 @readlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3, i32 5)
%17 = call i32 @readlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3, i32 6)
%18 = call i32 @readlinkat(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3, i32 5)
%19 = call i32 @readlinkat(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3, i32 6)
%20 = call i32 @gethostname(i8* %3, i32 5)
%21 = call i32 @gethostname(i8* %3, i32 6)
ret void
}