#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*/ getcwd(char *, int);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *, char *);
void printPrompt() {
  char *user = getenv("USER");
  char *pwd = malloc(sizeof(char) * 1024);
  getcwd(pwd, 1024);
  char *home = getenv("HOME");
  int i;
  for (i = 0; pwd[i] == home[i] && home[i] != '\0'; i++)
    ;
  char *path;
  if (home[i] == '\0') {
    path = malloc(sizeof(char) * 1024);
    int j = 0;
    path[j] = '~';
    path[++j] = '/';
    while (pwd[i] != '\0')
      path[++j] = pwd[++i];
    path[j] = '\0';
  } else
    path = pwd;
  printf("\x1B[32m%s \x1B[34m%s\x1B[32m $ \033[0m", user, path);
}


x86 assembly (clang, -O0):
<printPrompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rdx
movsbl (%rax,%rdx,1),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x2d(%rbp)
jne    11c5 <printPrompt+0x85>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11d5 <printPrompt+0x95>
jmp    11e8 <printPrompt+0xa8>
jmp    11da <printPrompt+0x9a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118b <printPrompt+0x4b>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1283 <printPrompt+0x143>
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x7e,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1272 <printPrompt+0x132>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1232 <printPrompt+0xf2>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    128b <printPrompt+0x14b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xd70(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printPrompt>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    0xe90(%rip),%rdi
call   1030 <getenv@plt>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdx
movzbl 0x1(%rax,%rbx,1),%ecx
add    $0x1,%rbx
cmp    %cl,0x1(%r15,%rdx,1)
jne    11a7 <printPrompt+0x67>
test   %cl,%cl
jne    1190 <printPrompt+0x50>
test   %cl,%cl
je     11b0 <printPrompt+0x70>
mov    %r15,%rdx
jmp    11fe <printPrompt+0xbe>
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
movw   $0x2f7e,(%rax)
mov    %ebx,%eax
cmpb   $0x0,(%r15,%rax,1)
je     11f5 <printPrompt+0xb5>
mov    %ebx,%eax
add    %rax,%r15
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rax,1),%ecx
mov    %cl,0x1(%rdx,%rax,1)
add    $0x1,%rax
test   %cl,%cl
jne    11e0 <printPrompt+0xa0>
mov    %eax,%eax
jmp    11fa <printPrompt+0xba>
mov    $0x1,%eax
movb   $0x0,(%rdx,%rax,1)
lea    0xe05(%rip),%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [28 x i8] c"\1B[32m%s \1B[34m%s\1B[32m $ \1B[0m\00"
define void @printPrompt() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %1
%8 = call i8* @malloc(i32 1024)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @getcwd(i8* %9, i32 1024)
%11 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %3
store i32 0, i32* %4
br label %12
12: ; preds = %37, %0
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %18, %24
br i1 %25, label %26, label %34
26: ; preds = %12
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br label %34
34: ; preds = %26, %12
%35 = phi i1 [ false, %12 ], [ %33, %26 ]
br i1 %35, label %36, label %40
36: ; preds = %34
br label %37
37: ; preds = %36
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %12
40: ; preds = %34
%41 = load i8*, i8** %3
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %84
48: ; preds = %40
%49 = call i8* @malloc(i32 1024)
store i8* %49, i8** %5
store i32 0, i32* %6
%50 = load i8*, i8** %5
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 126, i8* %53
%54 = load i8*, i8** %5
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %54, i64 %57
store i8 47, i8* %58
br label %59
59: ; preds = %67, %48
%60 = load i8*, i8** %2
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %79
67: ; preds = %59
%68 = load i8*, i8** %2
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = load i8, i8* %72
%74 = load i8*, i8** %5
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 1
store i32 %76, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %74, i64 %77
store i8 %73, i8* %78
br label %59
79: ; preds = %59
%80 = load i8*, i8** %5
%81 = load i32, i32* %6
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 0, i8* %83
br label %86
84: ; preds = %40
%85 = load i8*, i8** %2
store i8* %85, i8** %5
br label %86
86: ; preds = %84, %79
%87 = load i8*, i8** %1
%88 = load i8*, i8** %5
%89 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %87, i8* %88)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [28 x i8] c"\1B[32m%s \1B[34m%s\1B[32m $ \1B[0m\00"
define void @printPrompt() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%3 = tail call i32 @getcwd(i8* %2, i32 1024)
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ %14, %5 ], [ 0, %0 ]
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = load i8, i8* %7
%9 = getelementptr inbounds i8, i8* %4, i64 %6
%10 = load i8, i8* %9
%11 = icmp ne i8 %8, %10
%12 = icmp eq i8 %10, 0
%13 = or i1 %11, %12
%14 = add nuw i64 %6, 1
br i1 %13, label %15, label %5
15: ; preds = %5
br i1 %12, label %16, label %37
16: ; preds = %15
%17 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
store i8 126, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 47, i8* %18
%19 = and i64 %6, 4294967295
%20 = getelementptr inbounds i8, i8* %2, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %16, %23
%24 = phi i64 [ %26, %23 ], [ %19, %16 ]
%25 = phi i64 [ %29, %23 ], [ 1, %16 ]
%26 = add nuw i64 %24, 1
%27 = getelementptr inbounds i8, i8* %2, i64 %26
%28 = load i8, i8* %27
%29 = add nuw nsw i64 %25, 1
%30 = getelementptr inbounds i8, i8* %17, i64 %29
store i8 %28, i8* %30
%31 = icmp eq i8 %28, 0
br i1 %31, label %32, label %23
32: ; preds = %23
%33 = and i64 %29, 4294967295
br label %34
34: ; preds = %32, %16
%35 = phi i64 [ 1, %16 ], [ %33, %32 ]
%36 = getelementptr inbounds i8, i8* %17, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %15, %34
%38 = phi i8* [ %17, %34 ], [ %2, %15 ]
%39 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %38)
ret void
}