#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*/ memcmp(unsigned char const *, char *, unsigned int);
int /*<<< orphan*/ memcpy(unsigned char *, ...);
unsigned char *realloc(unsigned char *, unsigned int);
unsigned int strlen(char *);
const unsigned char *afl_postprocess(const unsigned char *in_buf,
                                     unsigned int *len) {
  static unsigned char *saved_buf;
  unsigned char *new_buf;
  if (*len < strlen("GIF89a"))
    return NULL;
  if (!memcmp(in_buf, "GIF89a", strlen("GIF89a")))
    return in_buf;
  new_buf = realloc(saved_buf, *len);
  if (!new_buf)
    return in_buf;
  saved_buf = new_buf;
  memcpy(new_buf, in_buf, *len);
  memcpy(new_buf, "GIF89a", strlen("GIF89a"));
  return new_buf;
}


x86 assembly (clang, -O0):
<afl_postprocess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    0xea0(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jae    117f <afl_postprocess+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    1239 <afl_postprocess+0xf9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe72(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xe60(%rip),%rsi
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11bb <afl_postprocess+0x7b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1239 <afl_postprocess+0xf9>
mov    0x2e86(%rip),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e9 <afl_postprocess+0xa9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1239 <afl_postprocess+0xf9>
mov    -0x20(%rbp),%rax
mov    %rax,0x2e54(%rip)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xde8(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xdd6(%rip),%rsi
xor    %eax,%eax
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<afl_postprocess>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rsi),%ebp
lea    0xeaa(%rip),%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jae    1163 <afl_postprocess+0x23>
xor    %ebx,%ebx
jmp    11d2 <afl_postprocess+0x92>
lea    0xe96(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <memcmp@plt>
test   %eax,%eax
je     11d2 <afl_postprocess+0x92>
mov    0x2ebe(%rip),%rdi
mov    (%r14),%esi
call   1060 <realloc@plt>
test   %rax,%rax
je     11d2 <afl_postprocess+0x92>
mov    %rax,%r15
mov    %rax,0x2ea7(%rip)
mov    (%r14),%edx
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <memcpy@plt>
lea    0xe48(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <memcpy@plt>
mov    %r15,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@afl_postprocess.saved_buf = internal global i8* null
@.str = [7 x i8] c"GIF89a\00"
define i8* @afl_postprocess(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i32*, i32** %5
%8 = load i32, i32* %7
%9 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp ult i32 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %2
store i8* null, i8** %3
br label %39
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @memcmp(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = load i8*, i8** %4
store i8* %18, i8** %3
br label %39
19: ; preds = %12
%20 = load i8*, i8** @afl_postprocess.saved_buf
%21 = load i32*, i32** %5
%22 = load i32, i32* %21
%23 = call i8* @realloc(i8* %20, i32 %22)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %19
%27 = load i8*, i8** %4
store i8* %27, i8** %3
br label %39
28: ; preds = %19
%29 = load i8*, i8** %6
store i8* %29, i8** @afl_postprocess.saved_buf
%30 = load i8*, i8** %6
%31 = load i8*, i8** %4
%32 = load i32*, i32** %5
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @memcpy(i8* %30, i8* %31, i32 %33)
%35 = load i8*, i8** %6
%36 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%37 = call i32 (i8*, ...) @memcpy(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i8*, i8** %6
store i8* %38, i8** %3
br label %39
39: ; preds = %28, %26, %17, %11
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
@afl_postprocess.saved_buf = internal unnamed_addr global i8* null
@.str = [7 x i8] c"GIF89a\00"
define i8* @afl_postprocess(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = icmp ult i32 %3, %4
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @memcmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %6
%11 = load i8*, i8** @afl_postprocess.saved_buf
%12 = load i32, i32* %1
%13 = tail call i8* @realloc(i8* %11, i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %10
store i8* %13, i8** @afl_postprocess.saved_buf
%16 = load i32, i32* %1
%17 = tail call i32 (i8*, ...) @memcpy(i8* %13, i8* %0, i32 %16)
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @memcpy(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %10, %6, %2, %15
%21 = phi i8* [ %13, %15 ], [ null, %2 ], [ %0, %6 ], [ %0, %10 ]
ret i8* %21
}