#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 */
scalar_t__ memcmp(char const *, char const *, size_t);
char *strdup(char const *);
size_t strlen(char const *);
char *_create_filename(const char *input, const char *from, char to) {
  if (input == NULL)
    return NULL;
  size_t l = strlen(input);
  if (l > 10000)
    return NULL;
  if (l < strlen(from))
    return NULL;
  if (memcmp(&input[l - strlen(from)], from, strlen(from)))
    return NULL;
  char *output = strdup(input);
  if (output == NULL)
    return NULL;
  output[l - 1] = to;
  return output;
}


x86 assembly (clang, -O0):
<_create_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <_create_filename+0x2d>
movq   $0x0,-0x8(%rbp)
jmp    1258 <_create_filename+0x128>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x2710,-0x28(%rbp)
jbe    1185 <_create_filename+0x55>
movq   $0x0,-0x8(%rbp)
jmp    1258 <_create_filename+0x128>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jae    11b3 <_create_filename+0x83>
movq   $0x0,-0x8(%rbp)
jmp    1258 <_create_filename+0x128>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rcx
mov    %rax,%rdx
mov    -0x50(%rbp),%rax
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     1219 <_create_filename+0xe9>
movq   $0x0,-0x8(%rbp)
jmp    1258 <_create_filename+0x128>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    123e <_create_filename+0x10e>
movq   $0x0,-0x8(%rbp)
jmp    1258 <_create_filename+0x128>
mov    -0x19(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_create_filename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1178 <_create_filename+0x48>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1030 <strlen@plt>
cmp    $0x2710,%rax
ja     1178 <_create_filename+0x48>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
sub    %rax,%rdi
jb     1178 <_create_filename+0x48>
add    %rbp,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1185 <_create_filename+0x55>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
call   1050 <strdup@plt>
test   %rax,%rax
je     1178 <_create_filename+0x48>
mov    %r14b,-0x1(%r15,%rax,1)
jmp    117a <_create_filename+0x4a>

LLVM IR (-O0):
define i8* @_create_filename(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
store i8* null, i8** %4
br label %51
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %8
%16 = load i64, i64* %8
%17 = icmp ugt i64 %16, 10000
br i1 %17, label %18, label %19
18: ; preds = %13
store i8* null, i8** %4
br label %51
19: ; preds = %13
%20 = load i64, i64* %8
%21 = load i8*, i8** %6
%22 = call i64 @strlen(i8* %21)
%23 = icmp ult i64 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %19
store i8* null, i8** %4
br label %51
25: ; preds = %19
%26 = load i8*, i8** %5
%27 = load i64, i64* %8
%28 = load i8*, i8** %6
%29 = call i64 @strlen(i8* %28)
%30 = sub i64 %27, %29
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8*, i8** %6
%33 = load i8*, i8** %6
%34 = call i64 @strlen(i8* %33)
%35 = call i64 @memcmp(i8* %31, i8* %32, i64 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %25
store i8* null, i8** %4
br label %51
38: ; preds = %25
%39 = load i8*, i8** %5
%40 = call i8* @strdup(i8* %39)
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %44
43: ; preds = %38
store i8* null, i8** %4
br label %51
44: ; preds = %38
%45 = load i8, i8* %7
%46 = load i8*, i8** %9
%47 = load i64, i64* %8
%48 = sub i64 %47, 1
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 %45, i8* %49
%50 = load i8*, i8** %9
store i8* %50, i8** %4
br label %51
51: ; preds = %44, %43, %37, %24, %18, %12
%52 = load i8*, i8** %4
ret i8* %52
}

LLVM IR (-O2):
define noalias i8* @_create_filename(i8* %0, i8* %1, i8 signext %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %3
%6 = tail call i64 @strlen(i8* %0)
%7 = icmp ugt i64 %6, 10000
br i1 %7, label %22, label %8
8: ; preds = %5
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = icmp ult i64 %6, %9
br i1 %10, label %22, label %11
11: ; preds = %8
%12 = sub i64 %6, %9
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i64 @memcmp(i8* %13, i8* %1, i64 %9)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = tail call i8* @strdup(i8* %0)
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = add nsw i64 %6, -1
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 %2, i8* %21
br label %22
22: ; preds = %5, %8, %11, %16, %19, %3
%23 = phi i8* [ null, %3 ], [ null, %5 ], [ null, %8 ], [ null, %11 ], [ %17, %19 ], [ null, %16 ]
ret i8* %23
}