#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 */
struct confctl_var {
  int dummy;
};

/* Variables and functions */
char *confctl_var_name(struct confctl_var *);
int /*<<< orphan*/ err(int, char *);
char *malloc(int);
int strlen(char const *);
int /*<<< orphan*/ strvis(char *, char const *, int);
char *cv_safe_name(struct confctl_var *cv) {
  const char *name;
  char *dst;
  name = confctl_var_name(cv);
  dst = malloc(strlen(name) * 4 + 1);
  if (dst == NULL)
    err(1, "malloc");
  strvis(dst, name, 0x10 | 0x02);
  return (dst);
}


x86 assembly (clang, -O0):
<cv_safe_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <confctl_var_name@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
shl    $0x2,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119f <cv_safe_name+0x4f>
mov    $0x1,%edi
lea    0xe66(%rip),%rsi
call   1060 <err@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x12,%edx
call   1030 <strvis@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cv_safe_name>:
push   %r14
push   %rbx
push   %rax
call   1050 <confctl_var_name@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(,%rax,4),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1189 <cv_safe_name+0x39>
lea    0xe81(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x12,%edx
call   1030 <strvis@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.confctl_var = type { i32 }
@.str = [7 x i8] c"malloc\00"
define i8* @cv_safe_name(%struct.confctl_var* %0) {
%2 = alloca %struct.confctl_var*
%3 = alloca i8*
%4 = alloca i8*
store %struct.confctl_var* %0, %struct.confctl_var** %2
%5 = load %struct.confctl_var*, %struct.confctl_var** %2
%6 = call i8* @confctl_var_name(%struct.confctl_var* %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = mul nsw i32 %8, 4
%10 = add nsw i32 %9, 1
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = call i32 @strvis(i8* %17, i8* %18, i32 18)
%20 = load i8*, i8** %4
ret i8* %20
}

LLVM IR (-O2):
%struct.confctl_var = type { i32 }
@.str = [7 x i8] c"malloc\00"
define i8* @cv_safe_name(%struct.confctl_var* %0) {
%2 = tail call i8* @confctl_var_name(%struct.confctl_var* %0)
%3 = tail call i32 @strlen(i8* %2)
%4 = shl nsw i32 %3, 2
%5 = or i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = tail call i32 @strvis(i8* %6, i8* %2, i32 18)
ret i8* %6
}