#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*/ mem_alloc_tiny_func(size_t, int);
scalar_t__ memcpy(int /*<<< orphan*/, char *, size_t);
int strlen(char *);
char *str_alloc_copy_func(char *src) {
  size_t size;
  if (!src)
    return "";
  if (!*src)
    return "";
  size = strlen(src) + 1;
  return (char *)memcpy(mem_alloc_tiny_func(size, 1), src, size);
}


x86 assembly (clang, -O0):
<str_alloc_copy_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <str_alloc_copy_func+0x27>
lea    0xeb2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a7 <str_alloc_copy_func+0x77>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1174 <str_alloc_copy_func+0x44>
lea    0xe95(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a7 <str_alloc_copy_func+0x77>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1040 <mem_alloc_tiny_func@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_alloc_copy_func>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rax
test   %rdi,%rdi
je     1170 <str_alloc_copy_func+0x40>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1170 <str_alloc_copy_func+0x40>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <mem_alloc_tiny_func@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <memcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @str_alloc_copy_func(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %24
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %24
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = call i32 @mem_alloc_tiny_func(i64 %18, i32 1)
%20 = load i8*, i8** %3
%21 = load i64, i64* %4
%22 = call i64 @memcpy(i32 %19, i8* %20, i64 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %2
br label %24
24: ; preds = %13, %12, %7
%25 = load i8*, i8** %2
ret i8* %25
}

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