#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncat_s(char *, int, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ strncpy_s(char *, int, char *, int);
void bufferAccessOutOfBounds(void) {
  char a[5];
  fgets(a, 5, stdin);
  fgets(a, 6, stdin);
  sprintf(a, "ab%s", "cd");
  sprintf(a, "ab%s", "cde");
  snprintf(a, 5, "abcde%i", 1);
  snprintf(a, 6, "abcde%i", 1);
  strcpy(a, "abcd");
  strcpy(a, "abcde");
  strncpy(a, "abcde", 5);
  strncpy(a, "abcde", 6);
  strncpy(a, "a", 6);
  strncpy(a, "abcdefgh", 4);
  strncpy_s(a, 5, "abcd", 5);
  strncpy_s(a, 5, "abcde", 6);
  strncpy_s(a, 5, "a", 6);
  strncpy_s(a, 5, "abcdefgh", 4);
  strncat_s(a, 5, "1", 2);
  strncat_s(a, 10, "1", 2);
  strncat_s(a, 5, "1", 5);
  fread(a, 1, 5, stdin);
  fread(a, 1, 6, stdin);
  fwrite(a, 1, 5, stdout);
  fread(a, 1, 6, stdout);
}


x86 assembly (clang, -O0):
<bufferAccessOutOfBounds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x5(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1070 <fgets@plt>
lea    -0x5(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1070 <fgets@plt>
lea    -0x5(%rbp),%rdi
lea    0xe2f(%rip),%rsi
lea    0xe37(%rip),%rdx
call   1090 <sprintf@plt>
lea    -0x5(%rbp),%rdi
lea    0xe18(%rip),%rsi
lea    0xe25(%rip),%rdx
call   1090 <sprintf@plt>
lea    -0x5(%rbp),%rdi
mov    $0x5,%esi
lea    0xe01(%rip),%rdx
mov    $0x1,%ecx
call   1060 <snprintf@plt>
lea    -0x5(%rbp),%rdi
mov    $0x6,%esi
lea    0xde7(%rip),%rdx
mov    $0x1,%ecx
call   1060 <snprintf@plt>
lea    -0x5(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x5(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x5(%rbp),%rdi
lea    0xdbf(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
lea    -0x5(%rbp),%rdi
lea    0xdaa(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    -0x5(%rbp),%rdi
lea    0xd9b(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    -0x5(%rbp),%rdi
lea    0xd88(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    -0x5(%rbp),%rdi
mov    $0x5,%ecx
lea    0xd61(%rip),%rdx
mov    %ecx,%esi
call   10b0 <strncpy_s@plt>
lea    -0x5(%rbp),%rdi
mov    $0x5,%esi
lea    0xd4f(%rip),%rdx
mov    $0x6,%ecx
call   10b0 <strncpy_s@plt>
lea    -0x5(%rbp),%rdi
mov    $0x5,%esi
lea    0xd3b(%rip),%rdx
mov    $0x6,%ecx
call   10b0 <strncpy_s@plt>
lea    -0x5(%rbp),%rdi
mov    $0x5,%esi
lea    0xd23(%rip),%rdx
mov    $0x4,%ecx
call   10b0 <strncpy_s@plt>
lea    -0x5(%rbp),%rdi
mov    $0x5,%esi
lea    0xd12(%rip),%rdx
mov    $0x2,%ecx
call   1080 <strncat_s@plt>
lea    -0x5(%rbp),%rdi
mov    $0xa,%esi
lea    0xcf8(%rip),%rdx
mov    $0x2,%ecx
call   1080 <strncat_s@plt>
lea    -0x5(%rbp),%rdi
mov    $0x5,%ecx
lea    0xcde(%rip),%rdx
mov    %ecx,%esi
call   1080 <strncat_s@plt>
lea    -0x5(%rbp),%rdi
mov    0x2c91(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x5,%edx
call   1050 <fread@plt>
lea    -0x5(%rbp),%rdi
mov    0x2c75(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x6,%edx
call   1050 <fread@plt>
lea    -0x5(%rbp),%rdi
mov    0x2c49(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x5,%edx
call   10a0 <fwrite@plt>
lea    -0x5(%rbp),%rdi
mov    0x2c2d(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x6,%edx
call   1050 <fread@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferAccessOutOfBounds>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e46(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x3(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1070 <fgets@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1070 <fgets@plt>
lea    0xe32(%rip),%r14
lea    0xe3a(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0xe2d(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <sprintf@plt>
lea    0xe0c(%rip),%r14
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1060 <snprintf@plt>
lea    0xde3(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xdd6(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    0xdaa(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    0xd95(%rip),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r15,%rdx
mov    $0x5,%ecx
call   10b0 <strncpy_s@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r14,%rdx
mov    $0x6,%ecx
call   10b0 <strncpy_s@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r12,%rdx
mov    $0x6,%ecx
call   10b0 <strncpy_s@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r13,%rdx
mov    $0x4,%ecx
call   10b0 <strncpy_s@plt>
lea    0xd33(%rip),%r14
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r14,%rdx
mov    $0x2,%ecx
call   1080 <strncat_s@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
mov    $0x2,%ecx
call   1080 <strncat_s@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r14,%rdx
mov    $0x5,%ecx
call   1080 <strncat_s@plt>
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   1050 <fread@plt>
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x6,%edx
call   1050 <fread@plt>
mov    0x2c78(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x5,%edx
call   10a0 <fwrite@plt>
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x6,%edx
call   1050 <fread@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [5 x i8] c"ab%s\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [4 x i8] c"cde\00"
@.str.3 = [8 x i8] c"abcde%i\00"
@.str.4 = [5 x i8] c"abcd\00"
@.str.5 = [6 x i8] c"abcde\00"
@.str.6 = [2 x i8] c"a\00"
@.str.7 = [9 x i8] c"abcdefgh\00"
@.str.8 = [2 x i8] c"1\00"
@stdout = global i32 0
define void @bufferAccessOutOfBounds() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 5, i32 %3)
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 6, i32 %6)
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%9 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%11 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%13 = call i32 @snprintf(i8* %12, i32 5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1)
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%15 = call i32 @snprintf(i8* %14, i32 6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1)
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%21 = call i32 @strncpy(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%23 = call i32 @strncpy(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 6)
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%25 = call i32 @strncpy(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 6)
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%27 = call i32 @strncpy(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 4)
%28 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%29 = call i32 @strncpy_s(i8* %28, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 5)
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%31 = call i32 @strncpy_s(i8* %30, i32 5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 6)
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%33 = call i32 @strncpy_s(i8* %32, i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 6)
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%35 = call i32 @strncpy_s(i8* %34, i32 5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 4)
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%37 = call i32 @strncat_s(i8* %36, i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 2)
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%39 = call i32 @strncat_s(i8* %38, i32 10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 2)
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%41 = call i32 @strncat_s(i8* %40, i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 5)
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%43 = load i32, i32* @stdin
%44 = call i32 @fread(i8* %42, i32 1, i32 5, i32 %43)
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%46 = load i32, i32* @stdin
%47 = call i32 @fread(i8* %45, i32 1, i32 6, i32 %46)
%48 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%49 = load i32, i32* @stdout
%50 = call i32 @fwrite(i8* %48, i32 1, i32 5, i32 %49)
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%52 = load i32, i32* @stdout
%53 = call i32 @fread(i8* %51, i32 1, i32 6, i32 %52)
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [5 x i8] c"ab%s\00"
@.str.1 = [3 x i8] c"cd\00"
@.str.2 = [4 x i8] c"cde\00"
@.str.3 = [8 x i8] c"abcde%i\00"
@.str.4 = [5 x i8] c"abcd\00"
@.str.5 = [6 x i8] c"abcde\00"
@.str.6 = [2 x i8] c"a\00"
@.str.7 = [9 x i8] c"abcdefgh\00"
@.str.8 = [2 x i8] c"1\00"
@stdout = global i32 0
define void @bufferAccessOutOfBounds() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 5, i32 %3)
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 6, i32 %5)
%7 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @snprintf(i8* %2, i32 5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1)
%10 = call i32 @snprintf(i8* %2, i32 6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 1)
%11 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%14 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 6)
%15 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 6)
%16 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 4)
%17 = call i32 @strncpy_s(i8* %2, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 5)
%18 = call i32 @strncpy_s(i8* %2, i32 5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 6)
%19 = call i32 @strncpy_s(i8* %2, i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 6)
%20 = call i32 @strncpy_s(i8* %2, i32 5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 4)
%21 = call i32 @strncat_s(i8* %2, i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 2)
%22 = call i32 @strncat_s(i8* %2, i32 10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 2)
%23 = call i32 @strncat_s(i8* %2, i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 5)
%24 = load i32, i32* @stdin
%25 = call i32 @fread(i8* %2, i32 1, i32 5, i32 %24)
%26 = load i32, i32* @stdin
%27 = call i32 @fread(i8* %2, i32 1, i32 6, i32 %26)
%28 = load i32, i32* @stdout
%29 = call i32 @fwrite(i8* %2, i32 1, i32 5, i32 %28)
%30 = load i32, i32* @stdout
%31 = call i32 @fread(i8* %2, i32 1, i32 6, i32 %30)
ret void
}