#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 *Strsafe_find(char *);
int /*<<< orphan*/ Strsafe_insert(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *Strsafe(char *y) {
  char *z;
  z = Strsafe_find(y);
  if (z == 0 && (z = malloc(strlen(y) + 1)) != 0) {
    strcpy(z, y);
    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    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <Strsafe_find@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bd <Strsafe+0x5d>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11bd <Strsafe+0x5d>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1070 <Strsafe_insert@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11cf <Strsafe+0x6f>
mov    $0x0,%al
call   1080 <memory_error@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Strsafe>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <Strsafe_find@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ab <Strsafe+0x4b>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a2 <Strsafe+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <Strsafe_insert@plt>
jmp    11ab <Strsafe+0x4b>
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*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @Strsafe_find(i8* %4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 1
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 @Strsafe_insert(i8* %18)
br label %20
20: ; preds = %14, %8, %1
%21 = load i8*, i8** %3
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %20
br label %24
24: ; preds = %23, %20
%25 = load i8*, i8** %3
ret i8* %25
}

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