#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*/ sprintf(char *, char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void build_name(char *str, char *name) {
  if (str == 0 || *str == 27)
    strcpy(name, "(buffer)");
  else {
    char *temp;
    sprintf(name,
            "(dostring) >> \"%."
            "20"
            "s\"",
            str);
    temp = strchr(name, '\n');
    if (temp) {
      *temp = '"';
      *(temp + 1) = 0;
    }
  }
}


x86 assembly (clang, -O0):
<build_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115b <build_name+0x2b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x1b,%eax
jne    1170 <build_name+0x40>
mov    -0x10(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11b5 <build_name+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b0 <build_name+0x80>
mov    -0x18(%rbp),%rax
movb   $0x22,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11b5 <build_name+0x85>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_name>:
push   %rbx
mov    %rsi,%rbx
test   %rdi,%rdi
je     1141 <build_name+0x11>
mov    %rdi,%rdx
cmpb   $0x1b,(%rdi)
jne    1151 <build_name+0x21>
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <strcpy@plt>
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1177 <build_name+0x47>
movw   $0x22,(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"(buffer)\00"
@.str.1 = [22 x i8] c"(dostring) >> \22%.20s\22\00"
define void @build_name(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 27
br i1 %6, label %7, label %9
7: ; preds = %4, %2
%8 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %15
9: ; preds = %4
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 10)
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %9
store i8 34, i8* %11
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 0, i8* %14
br label %15
15: ; preds = %9, %13, %7
ret void
}