char *Strsafe(y)
char *y;
{
  char *z;
  if (y == 0)
    return 0;
  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    $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
mov    $0x0,%al
call   1030 <Strsafe_find@plt>
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11db <Strsafe+0x7b>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11db <Strsafe+0x7b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1070 <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     117c <Strsafe+0x1c>
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <Strsafe_find@plt>
test   %eax,%eax
je     1181 <Strsafe+0x21>
movslq %eax,%r14
jmp    11bb <Strsafe+0x5b>
xor    %r14d,%r14d
jmp    11bb <Strsafe+0x5b>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b1 <Strsafe+0x51>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <Strsafe_insert@plt>
jmp    11bb <Strsafe+0x5b>
xor    %r14d,%r14d
xor    %eax,%eax
call   1080 <memory_error@plt>
mov    %r14,%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*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %33
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 (i8*, ...) bitcast (i32 (...)* @Strsafe_find to i32 (i8*, ...)*)(i8* %9)
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %27
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = call i64 @strlen(i8* %16)
%18 = add i64 %17, 1
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = load i8*, i8** %3
%24 = call i8* @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %4
%26 = call i32 (i8*, ...) bitcast (i32 (...)* @Strsafe_insert to i32 (i8*, ...)*)(i8* %25)
br label %27
27: ; preds = %21, %15, %8
%28 = load i8*, i8** %4
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %27
br label %31
31: ; preds = %30, %27
%32 = load i8*, i8** %4
store i8* %32, i8** %2
br label %33
33: ; preds = %31, %7
%34 = load i8*, i8** %2
ret i8* %34
}

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