#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*/ basic_sanitize(char *);
char *malloc(size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *);
char *strdup(char *);
size_t strlen(char *);
char *strescape_or_null(char *str) {
  char *escaped;
  size_t len;
  if (!str || !str[0]) {
    return strdup("NULL");
  }
  basic_sanitize(str);
  len = strlen(str);
  escaped = malloc(len + 3);
  snprintf(escaped, len + 3, "'%s'", str);
  return escaped;
}


x86 assembly (clang, -O0):
<strescape_or_null>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1174 <strescape_or_null+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1189 <strescape_or_null+0x39>
lea    0xe85(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11d4 <strescape_or_null+0x84>
mov    -0x10(%rbp),%rdi
call   1030 <basic_sanitize@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x3,%rsi
mov    -0x10(%rbp),%rcx
lea    0xe3e(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strescape_or_null>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     119f <strescape_or_null+0x4f>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     119f <strescape_or_null+0x4f>
mov    %rbx,%rdi
call   1030 <basic_sanitize@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x3(%rax),%r14
mov    %r14,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe7d(%rip),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe5a(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <strdup@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"'%s'\00"
define i8* @strescape_or_null(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8, %1
%14 = call i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %2
br label %29
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = call i32 @basic_sanitize(i8* %16)
%18 = load i8*, i8** %3
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = add i64 %20, 3
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = load i64, i64* %5
%25 = add i64 %24, 3
%26 = load i8*, i8** %3
%27 = call i32 @snprintf(i8* %23, i64 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %4
store i8* %28, i8** %2
br label %29
29: ; preds = %15, %13
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"NULL\00"
@.str.1 = [5 x i8] c"'%s'\00"
define i8* @strescape_or_null(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3, %1
%7 = tail call dereferenceable_or_null(5) i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %3
%9 = tail call i32 @basic_sanitize(i8* %0)
%10 = tail call i64 @strlen(i8* %0)
%11 = add i64 %10, 3
%12 = tail call i8* @malloc(i64 %11)
%13 = tail call i32 @snprintf(i8* %12, i64 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %8, %6
%15 = phi i8* [ %12, %8 ], [ %7, %6 ]
ret i8* %15
}