char *Strsafe(y)
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) {
    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
mov    $0x0,%al
call   1030 <Strsafe_find@plt>
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <Strsafe+0x63>
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     11c3 <Strsafe+0x63>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1070 <Strsafe_insert@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11d5 <Strsafe+0x75>
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
xor    %eax,%eax
call   1030 <Strsafe_find@plt>
test   %eax,%eax
je     1177 <Strsafe+0x17>
movslq %eax,%rbx
jmp    11b0 <Strsafe+0x50>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a7 <Strsafe+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <Strsafe_insert@plt>
jmp    11b0 <Strsafe+0x50>
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 i32 (i8*, ...) bitcast (i32 (...)* @Strsafe_find to i32 (i8*, ...)*)(i8* %4)
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %22
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i64 @strlen(i8* %11)
%13 = add i64 %12, 1
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %22
16: ; preds = %10
%17 = load i8*, i8** %3
%18 = load i8*, i8** %2
%19 = call i8* @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %3
%21 = call i32 (i8*, ...) bitcast (i32 (...)* @Strsafe_insert to i32 (i8*, ...)*)(i8* %20)
br label %22
22: ; preds = %16, %10, %1
%23 = load i8*, i8** %3
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (...) @memory_error()
br label %27
27: ; preds = %25, %22
%28 = load i8*, i8** %3
ret i8* %28
}

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