#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 *getcwd(char *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
scalar_t__ strstr(char *, char *);
void printPrompt() {
  char *cwd = 0;
  cwd = getcwd(cwd, 0);
  if (strstr(cwd, getenv("HOME"))) {
    int homeLen = strlen(getenv("HOME"));
    cwd = &cwd[homeLen - 1];
    cwd[0] = '~';
  }
  char hostname[512];
  gethostname(hostname, 512 - 1);
  printf("\x1B[36m"
         "%s@%s",
         getenv("USER"), hostname);
  printf("\x1B[37m"
         ":");
  printf("\x1B[33m"
         "%s$\n",
         cwd);
  printf("\x1B[34m"
         "><((((º> "
         "\x1B[0m");
}


x86 assembly (clang, -O0):
<printPrompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1060 <getcwd@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    0xe6c(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x218(%rbp),%rdi
mov    %rax,%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     11e4 <printPrompt+0x84>
lea    0xe47(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x7e,(%rax)
lea    -0x210(%rbp),%rdi
mov    $0x1ff,%esi
call   1070 <gethostname@plt>
lea    0xe14(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    -0x210(%rbp),%rdx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printPrompt>:
push   %r14
push   %rbx
sub    $0x208,%rsp
xor    %edi,%edi
xor    %esi,%esi
call   1060 <getcwd@plt>
mov    %rax,%rbx
lea    0xe83(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11b4 <printPrompt+0x54>
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x7e,-0x1(%rax,%rbx,1)
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1070 <gethostname@plt>
lea    0xe45(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe2e(%rip),%rdi
mov    %rax,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [11 x i8] c"\1B[36m%s@%s\00"
@.str.2 = [5 x i8] c"USER\00"
@.str.3 = [7 x i8] c"\1B[37m:\00"
@.str.4 = [10 x i8] c"\1B[33m%s$\0A\00"
@.str.5 = [20 x i8] c"\1B[34m><((((\C2\BA> \1B[0m\00"
define void @printPrompt() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [512 x i8]
store i8* null, i8** %1
%4 = load i8*, i8** %1
%5 = call i8* @getcwd(i8* %4, i32 0)
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @strstr(i8* %6, i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %0
%11 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %2
%13 = load i8*, i8** %1
%14 = load i32, i32* %2
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8* %17, i8** %1
%18 = load i8*, i8** %1
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 126, i8* %19
br label %20
20: ; preds = %10, %0
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%22 = call i32 @gethostname(i8* %21, i32 511)
%23 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%27 = load i8*, i8** %1
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [11 x i8] c"\1B[36m%s@%s\00"
@.str.2 = [5 x i8] c"USER\00"
@.str.3 = [7 x i8] c"\1B[37m:\00"
@.str.4 = [10 x i8] c"\1B[33m%s$\0A\00"
@.str.5 = [20 x i8] c"\1B[34m><((((\C2\BA> \1B[0m\00"
define void @printPrompt() {
%1 = alloca [512 x i8]
%2 = tail call i8* @getcwd(i8* null, i32 0)
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @strstr(i8* %2, i8* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %2, i64 %10
store i8 126, i8* %11
br label %12
12: ; preds = %6, %0
%13 = phi i8* [ %11, %6 ], [ %2, %0 ]
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%15 = call i32 @gethostname(i8* %14, i32 511)
%16 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %14)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
ret void
}