#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 LZ4_decompress_fast(char *, char *, int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int FUZ_SecurityTest() {
  char *output;
  char *input;
  int i, r;
  printf("Overflow test (issue 52)...\n");
  input = (char *)malloc(20 << 20);
  output = (char *)malloc(20 << 20);
  input[0] = 0x0F;
  input[1] = 0x00;
  input[2] = 0x00;
  for (i = 3; i < 16840000; i++)
    input[i] = 0xff;
  r = LZ4_decompress_fast(input, output, 20 << 20);
  free(input);
  free(output);
  printf(" Passed (return = %i < 0)\n", r);
  return 0;
}


x86 assembly (clang, -O0):
<FUZ_SecurityTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1400000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1400000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
movb   $0xf,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
movl   $0x3,-0x14(%rbp)
cmpl   $0x100f540,-0x14(%rbp)
jge    11b7 <FUZ_SecurityTest+0x77>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1190 <FUZ_SecurityTest+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x1400000,%edx
call   1050 <LZ4_decompress_fast@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FUZ_SecurityTest>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1400000,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x1400000,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
movw   $0xf,(%rbx)
movb   $0x0,0x2(%rbx)
lea    0x3(%rbx),%rdi
mov    $0x100f53d,%edx
mov    $0xff,%esi
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1400000,%edx
call   1070 <LZ4_decompress_fast@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe31(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Overflow test (issue 52)...\0A\00"
@.str.1 = [27 x i8] c" Passed (return = %i < 0)\0A\00"
define i32 @FUZ_SecurityTest() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @malloc(i32 20971520)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %2
%8 = call i64 @malloc(i32 20971520)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 15, i8* %11
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 0, i8* %13
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 2
store i8 0, i8* %15
store i32 3, i32* %3
br label %16
16: ; preds = %24, %0
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 16840000
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 -1, i8* %23
br label %24
24: ; preds = %19
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %16
27: ; preds = %16
%28 = load i8*, i8** %2
%29 = load i8*, i8** %1
%30 = call i32 @LZ4_decompress_fast(i8* %28, i8* %29, i32 20971520)
store i32 %30, i32* %4
%31 = load i8*, i8** %2
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %1
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %35)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c" Passed (return = %i < 0)\0A\00"
@str = [28 x i8] c"Overflow test (issue 52)...\00"
define i32 @FUZ_SecurityTest() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 @malloc(i32 20971520)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i64 @malloc(i32 20971520)
store i8 15, i8* %3
%5 = getelementptr inbounds i8, i8* %3, i64 1
store i8 0, i8* %5
%6 = getelementptr inbounds i8, i8* %3, i64 2
store i8 0, i8* %6
%7 = getelementptr i8, i8* %3, i64 3
%8 = inttoptr i64 %4 to i8*
%9 = tail call i32 @LZ4_decompress_fast(i8* %3, i8* %8, i32 20971520)
%10 = tail call i32 @free(i8* %3)
%11 = tail call i32 @free(i8* %8)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret i32 0
}