#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 */
char const *add_hash(char const *, int);
char *alloca(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
const char *strcache_add_len(const char *str, int len) {
  if (str[len] != '\0') {
    char *key = alloca(len + 1);
    memcpy(key, str, len);
    key[len] = '\0';
    str = key;
  }
  return add_hash(str, len);
}


x86 assembly (clang, -O0):
<strcache_add_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1187 <strcache_add_len+0x57>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <add_hash@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcache_add_len>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
movslq %esi,%rbp
cmpb   $0x0,(%rdi,%rbp,1)
je     1166 <strcache_add_len+0x36>
lea    0x1(%rbp),%edi
call   1030 <alloca@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
movb   $0x0,(%r15,%rbp,1)
mov    %r15,%rbx
mov    %rbx,%rdi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <add_hash@plt>

LLVM IR (-O0):
define i8* @strcache_add_len(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %2
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
%16 = call i8* @alloca(i32 %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = call i32 @memcpy(i8* %17, i8* %18, i32 %19)
%21 = load i8*, i8** %5
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
%25 = load i8*, i8** %5
store i8* %25, i8** %3
br label %26
26: ; preds = %13, %2
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = call i8* @add_hash(i8* %27, i32 %28)
ret i8* %29
}

LLVM IR (-O2):
define i8* @strcache_add_len(i8* %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = add nsw i32 %1, 1
%9 = tail call i8* @alloca(i32 %8)
%10 = tail call i32 @memcpy(i8* %9, i8* %0, i32 %1)
%11 = getelementptr inbounds i8, i8* %9, i64 %3
store i8 0, i8* %11
br label %12
12: ; preds = %7, %2
%13 = phi i8* [ %9, %7 ], [ %0, %2 ]
%14 = tail call i8* @add_hash(i8* %13, i32 %1)
ret i8* %14
}