#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 *getenv(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ printf(char *, int, char *, char *, char *, char);
void prompt(int retVal) {
  char promptSeparator, hostname[40];
  if (!getuid())
    promptSeparator = '#';
  else
    promptSeparator = '$';
  gethostname(hostname, 40);
  printf("\x1b[31;1m[%d] %s@%s:%s %c\x1b[39;0m ", retVal, getenv("USER"),
         hostname, getenv("PWD"), promptSeparator);
}


x86 assembly (clang, -O0):
<prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%eax
jne    1164 <prompt+0x24>
movb   $0x23,-0x5(%rbp)
jmp    1168 <prompt+0x28>
movb   $0x24,-0x5(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x28,%esi
call   1060 <gethostname@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %rax,%r8
lea    0xe4b(%rip),%rdi
movsbl -0x5(%rbp),%r9d
call   1050 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r15d
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x28,%esi
call   1060 <gethostname@plt>
lea    0xeb3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xea9(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x1,%ebp
mov    $0x24,%r9d
sbb    $0x0,%r9d
lea    0xe6b(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
call   1050 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\1B[31;1m[%d] %s@%s:%s %c\1B[39;0m \00"
@.str.1 = [5 x i8] c"USER\00"
@.str.2 = [4 x i8] c"PWD\00"
define void @prompt(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca [40 x i8]
store i32 %0, i32* %2
%5 = call i32 (...) @getuid()
%6 = icmp ne i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %1
store i8 35, i8* %3
br label %9
8: ; preds = %1
store i8 36, i8* %3
br label %9
9: ; preds = %8, %7
%10 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%11 = call i32 @gethostname(i8* %10, i32 40)
%12 = load i32, i32* %2
%13 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%15 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%16 = load i8, i8* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %13, i8* %14, i8* %15, i8 signext %16)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"\1B[31;1m[%d] %s@%s:%s %c\1B[39;0m \00"
@.str.1 = [5 x i8] c"USER\00"
@.str.2 = [4 x i8] c"PWD\00"
define void @prompt(i32 %0) {
%2 = alloca [40 x i8]
%3 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @getuid()
%5 = icmp eq i32 %4, 0
%6 = select i1 %5, i8 35, i8 36
%7 = call i32 @gethostname(i8* %3, i32 40)
%8 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %8, i8* %3, i8* %9, i8 signext %6)
ret void
}