#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*/ free(char *);
char *get_current_dir_name();
char *getlogin();
int /*<<< orphan*/ printf(char *, char *, char *, char *, ...);
void dsh_prompt_set_title(char *title_msg) {
  char esc_start[] = {0x1b, ']', '0', ';', 0};
  char esc_end[] = {0x07, 0};
  char *cdir = get_current_dir_name();
  if (title_msg)
    printf("%s%s%s", esc_start, title_msg, esc_end);
  else
    printf("%sdsh - %s - %s%s", esc_start, getlogin(), cdir, esc_end);
  free(cdir);
}


x86 assembly (clang, -O0):
<dsh_prompt_set_title>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xeae(%rip),%eax
mov    %eax,-0xd(%rbp)
mov    0xea9(%rip),%al
mov    %al,-0x9(%rbp)
mov    0xea0(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    $0x0,%al
call   1050 <get_current_dir_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119e <dsh_prompt_set_title+0x5e>
lea    -0xd(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    -0xf(%rbp),%rcx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ca <dsh_prompt_set_title+0x8a>
lea    -0xd(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <getlogin@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
mov    -0x18(%rbp),%rcx
lea    -0xf(%rbp),%r8
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dsh_prompt_set_title>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movb   $0x0,0x14(%rsp)
movl   $0x3b305d1b,0x10(%rsp)
3b
movw   $0x7,0xe(%rsp)
xor    %eax,%eax
call   1050 <get_current_dir_name@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     118a <dsh_prompt_set_title+0x4a>
lea    0xe91(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xe(%rsp),%rcx
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11af <dsh_prompt_set_title+0x6f>
xor    %eax,%eax
call   1060 <getlogin@plt>
lea    0xe74(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xe(%rsp),%r8
mov    %rax,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.dsh_prompt_set_title.esc_start = [5 x i8] c"\1B]0;\00"
@__const.dsh_prompt_set_title.esc_end = [2 x i8] c"\07\00"
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [18 x i8] c"%sdsh - %s - %s%s\00"
define void @dsh_prompt_set_title(i8* %0) {
%2 = alloca i8*
%3 = alloca [5 x i8]
%4 = alloca [2 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = bitcast [5 x i8]* %3 to i8*
%7 = bitcast [2 x i8]* %4 to i8*
%8 = call i8* (...) @get_current_dir_name()
store i8* %8, i8** %5
%9 = load i8*, i8** %2
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%15 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13, i8* %14)
br label %22
16: ; preds = %1
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%18 = call i8* (...) @getlogin()
%19 = load i8*, i8** %5
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%21 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %18, i8* %19, i8* %20)
br label %22
22: ; preds = %16, %11
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
ret void
}

LLVM IR (-O2):
@__const.dsh_prompt_set_title.esc_start = [5 x i8] c"\1B]0;\00"
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [18 x i8] c"%sdsh - %s - %s%s\00"
define void @dsh_prompt_set_title(i8* %0) {
%2 = alloca [5 x i8]
%3 = alloca i16
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = bitcast i16* %3 to i8*
store i16 7, i16* %3
%6 = tail call i8* (...) @get_current_dir_name()
%7 = icmp eq i8* %0, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %0, i8* %5)
br label %13
10: ; preds = %1
%11 = tail call i8* (...) @getlogin()
%12 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %11, i8* %6, i16* %3)
br label %13
13: ; preds = %10, %8
%14 = call i32 @free(i8* %6)
ret void
}