#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 snprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char *, char const *,
             char const *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *,
                           char const *);
char *xmalloc(int);
char *render_child_node(const char *data) {
  char *buf;
  int len = 0;
  const char *bend = "|";
  const char *horz = "`-";
  if (data == NULL || *data == '\0')
    return NULL;
  len = snprintf(NULL, 0, " %s%s %s", bend, horz, data);
  buf = xmalloc(len + 3);
  sprintf(buf, " %s%s %s", bend, horz, data);
  return buf;
}


x86 assembly (clang, -O0):
<render_child_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeb6(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1174 <render_child_node+0x44>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1181 <render_child_node+0x51>
movq   $0x0,-0x8(%rbp)
jmp    11d5 <render_child_node+0xa5>
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x10(%rbp),%r9
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe6b(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x3,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe3d(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<render_child_node>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     1191 <render_child_node+0x61>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1191 <render_child_node+0x61>
lea    0xeb8(%rip),%r15
lea    0xeac(%rip),%r12
lea    0xea7(%rip),%r13
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    %rbx,%r9
call   1030 <snprintf@plt>
lea    0x3(%rax),%edi
call   1040 <xmalloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
call   1050 <sprintf@plt>
jmp    1194 <render_child_node+0x64>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
@.str.1 = [3 x i8] c"`-\00"
@.str.2 = [9 x i8] c" %s%s %s\00"
define i8* @render_child_node(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = add nsw i32 %7, 3
%9 = tail call i8* @xmalloc(i32 %8)
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %1, %3, %6
%12 = phi i8* [ %9, %6 ], [ null, %3 ], [ null, %1 ]
ret i8* %12
}