#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 passwd {
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ get_user_name();
int /*<<< orphan*/ *getcwd(char *, int);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ rprintf(char *, ...);
int /*<<< orphan*/ rputc(char);
int /*<<< orphan*/ rputs(char *);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
void print_prompt() {
  char cwd[1024];
  rprintf("\x1b[93m%s", get_user_name());
  if (getcwd(cwd, 1024) != NULL) {
    struct passwd *pw = getpwuid(getuid());
    const char *homedir = pw->pw_dir;
    int homedirlen = strlen(homedir);
    rprintf("\x1b[96m ");
    if (strncmp(homedir, cwd, homedirlen) == 0) {
      rputc('~');
      rputs(&cwd[homedirlen]);
    } else {
      rputs(cwd);
    }
  }
  rprintf("\x1b[0m $ ");
}


x86 assembly (clang, -O0):
<print_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    $0x0,%al
call   10b0 <get_user_name@plt>
mov    %eax,%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <rprintf@plt>
lea    -0x400(%rbp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
cmp    $0x0,%rax
je     126c <print_prompt+0xdc>
mov    $0x0,%al
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x410(%rbp)
mov    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x414(%rbp)
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <rprintf@plt>
mov    -0x410(%rbp),%rdi
lea    -0x400(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    125b <print_prompt+0xcb>
mov    $0x7e,%edi
call   10a0 <rputc@plt>
movslq -0x414(%rbp),%rax
lea    -0x400(%rbp),%rdi
add    %rax,%rdi
call   1090 <rputs@plt>
jmp    1267 <print_prompt+0xd7>
lea    -0x400(%rbp),%rdi
call   1090 <rputs@plt>
jmp    126c <print_prompt+0xdc>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <rprintf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_prompt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
xor    %eax,%eax
call   10b0 <get_user_name@plt>
lea    0xe57(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <rprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
test   %rax,%rax
je     121d <print_prompt+0x8d>
xor    %eax,%eax
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    (%rax),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1040 <rprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1215 <print_prompt+0x85>
mov    $0x7e,%edi
call   10a0 <rputc@plt>
movslq %r14d,%rax
lea    (%rsp,%rax,1),%rbx
mov    %rbx,%rdi
call   1090 <rputs@plt>
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
call   1040 <rprintf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [8 x i8] c"\1B[93m%s\00"
@.str.1 = [7 x i8] c"\1B[96m \00"
@.str.2 = [8 x i8] c"\1B[0m $ \00"
define void @print_prompt() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.passwd*
%3 = alloca i8*
%4 = alloca i32
%5 = call i32 (...) @get_user_name()
%6 = call i32 (i8*, ...) @rprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = call i32* @getcwd(i8* %7, i32 1024)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %34
10: ; preds = %0
%11 = call i32 (...) @getuid()
%12 = call %struct.passwd* @getpwuid(i32 %11)
store %struct.passwd* %12, %struct.passwd** %2
%13 = load %struct.passwd*, %struct.passwd** %2
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i32 0, i32 0
%15 = load i8*, i8** %14
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %4
%18 = call i32 (i8*, ...) @rprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = load i8*, i8** %3
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%21 = load i32, i32* %4
%22 = call i64 @strncmp(i8* %19, i8* %20, i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %10
%25 = call i32 @rputc(i8 signext 126)
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %27
%29 = call i32 @rputs(i8* %28)
br label %33
30: ; preds = %10
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%32 = call i32 @rputs(i8* %31)
br label %33
33: ; preds = %30, %24
br label %34
34: ; preds = %33, %0
%35 = call i32 (i8*, ...) @rprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [8 x i8] c"\1B[93m%s\00"
@.str.1 = [7 x i8] c"\1B[96m \00"
@.str.2 = [8 x i8] c"\1B[0m $ \00"
define void @print_prompt() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @get_user_name()
%4 = tail call i32 (i8*, ...) @rprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32* @getcwd(i8* %2, i32 1024)
%6 = icmp eq i32* %5, null
br i1 %6, label %23, label %7
7: ; preds = %0
%8 = call i32 (...) @getuid()
%9 = call %struct.passwd* @getpwuid(i32 %8)
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = call i32 @strlen(i8* %11)
%13 = call i32 (i8*, ...) @rprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = call i64 @strncmp(i8* %11, i8* %2, i32 %12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %7
%17 = call i32 @rputc(i8 signext 126)
%18 = sext i32 %12 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %18
br label %20
20: ; preds = %7, %16
%21 = phi i8* [ %19, %16 ], [ %2, %7 ]
%22 = call i32 @rputs(i8* %21)
br label %23
23: ; preds = %20, %0
%24 = call i32 (i8*, ...) @rprintf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
ret void
}