#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 */
char *get_narrow_prefix();
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
char *strcpy(char *, char *);
int strlen(char *);
char *make_prompt(void) {
  char *narrow_prefix = get_narrow_prefix();
  char *result;
  if (narrow_prefix) {
    int length;
    length = strlen(narrow_prefix) + 8;
    result = (char *)malloc(sizeof(char) * (length));
    strcpy(result, "tdl[");
    strcat(result, narrow_prefix);
    strcat(result, "]> ");
  } else {
    result = strcpy((char *)malloc(1 + strlen("tdl> ")), ("tdl> "));
  }
  return result;
}


x86 assembly (clang, -O0):
<make_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <get_narrow_prefix@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c2 <make_prompt+0x72>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x8,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1070 <strcat@plt>
jmp    11eb <make_prompt+0x9b>
lea    0xe40(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
lea    0xe27(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_prompt>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <get_narrow_prefix@plt>
test   %rax,%rax
je     118c <make_prompt+0x4c>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
lea    0x8(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movl   $0x5b6c6474,(%rax)
movb   $0x0,0x4(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
jmp    11af <make_prompt+0x6f>
lea    0xe76(%rip),%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movl   $0x3e6c6474,(%rax)
movw   $0x20,0x4(%rax)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"tdl[\00"
@.str.1 = [4 x i8] c"]> \00"
@.str.2 = [6 x i8] c"tdl> \00"
define i8* @make_prompt() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = call i8* (...) @get_narrow_prefix()
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %24
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 8
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = call i8* @strcpy(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = load i8*, i8** %1
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %2
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %30
24: ; preds = %0
%25 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = add nsw i32 1, %25
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
%29 = call i8* @strcpy(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8* %29, i8** %2
br label %30
30: ; preds = %24, %7
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"tdl[\00"
@.str.1 = [4 x i8] c"]> \00"
@.str.2 = [6 x i8] c"tdl> \00"
define i8* @make_prompt() {
%1 = tail call i8* (...) @get_narrow_prefix()
%2 = icmp eq i8* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, 8
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %7, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5, i1 false)
%8 = tail call i32 @strcat(i8* %7, i8* %1)
%9 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %15
10: ; preds = %0
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%12 = add nsw i32 %11, 1
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) %14, i8* align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 6, i1 false)
br label %15
15: ; preds = %10, %3
%16 = phi i8* [ %7, %3 ], [ %14, %10 ]
ret i8* %16
}