#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__ Strlen(char const *);
char *Strsafe_find(char const *);
int /*<<< orphan*/ Strsafe_insert(char const *);
int /*<<< orphan*/ lemon_strcpy(char *, char const *);
scalar_t__ malloc(int);
const char *Strsafe(const char *y) {
  const char *z;
  char *cpy;
  if (y == 0)
    return 0;
  z = Strsafe_find(y);
  if (z == 0 && (cpy = (char *)malloc(((int)Strlen(y)) + 1)) != 0) {
    lemon_strcpy(cpy, y);
    z = cpy;
    Strsafe_insert(z);
  }
  if ((z) == 0) {
    extern void memory_error();
    memory_error();
  };
  return z;
}


x86 assembly (clang, -O0):
<Strsafe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <Strsafe+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <Strsafe+0x95>
mov    -0x10(%rbp),%rdi
call   1030 <Strsafe_find@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11db <Strsafe+0x7b>
mov    -0x10(%rbp),%rdi
call   1070 <Strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11db <Strsafe+0x7b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <lemon_strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <Strsafe_insert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11ed <Strsafe+0x8d>
mov    $0x0,%al
call   1080 <memory_error@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Strsafe>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a6 <Strsafe+0x46>
mov    %rdi,%r14
call   1030 <Strsafe_find@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b3 <Strsafe+0x53>
mov    %r14,%rdi
call   1070 <Strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11aa <Strsafe+0x4a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <lemon_strcpy@plt>
mov    %rbx,%rdi
call   1060 <Strsafe_insert@plt>
jmp    11b3 <Strsafe+0x53>
xor    %ebx,%ebx
jmp    11b3 <Strsafe+0x53>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <memory_error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @Strsafe(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %35
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @Strsafe_find(i8* %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %29
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i64 @Strlen(i8* %15)
%17 = trunc i64 %16 to i32
%18 = add nsw i32 %17, 1
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %29
22: ; preds = %14
%23 = load i8*, i8** %5
%24 = load i8*, i8** %3
%25 = call i32 @lemon_strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %5
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = call i32 @Strsafe_insert(i8* %27)
br label %29
29: ; preds = %22, %14, %9
%30 = load i8*, i8** %4
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %29
br label %33
33: ; preds = %32, %29
%34 = load i8*, i8** %4
store i8* %34, i8** %2
br label %35
35: ; preds = %33, %8
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
define i8* @Strsafe(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = tail call i8* @Strsafe_find(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = tail call i64 @Strlen(i8* %0)
%8 = trunc i64 %7 to i32
%9 = add nsw i32 %8, 1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %16, label %13
13: ; preds = %6
%14 = tail call i32 @lemon_strcpy(i8* %11, i8* %0)
%15 = tail call i32 @Strsafe_insert(i8* %11)
br label %17
16: ; preds = %6
tail call void (...) @memory_error()
br label %17
17: ; preds = %13, %3, %16, %1
%18 = phi i8* [ null, %1 ], [ null, %16 ], [ %11, %13 ], [ %4, %3 ]
ret i8* %18
}