#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 */
typedef int /*<<< orphan*/ uid_t;
struct utsname {
  char *nodename;
};
struct passwd {
  char *pw_name;
  char *pw_dir;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *get_current_dir();
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, size_t);
int /*<<< orphan*/ uname(struct utsname *);
char *set_prompt(int ret) {
  char *prompt, *pwd;
  struct utsname machine;
  struct passwd *user;
  uid_t uid;
  size_t prompt_size;
  uid = getuid();
  user = getpwuid(uid);
  pwd = get_current_dir();
  uname(&machine);
  prompt_size =
      60 + strlen(user->pw_name) + strlen(machine.nodename) + strlen(pwd);
  prompt = malloc(sizeof(char) * prompt_size);
  if (ret != 0)
    sprintf(prompt,
            "[\033[34m%d\033[36m!\033[37m][\033[31m%s\033[37m@\033[35m%s\033["
            "37m: \033[34m",
            ret, user->pw_name, machine.nodename);
  else
    sprintf(prompt, "[\033[31m%s\033[37m@\033[35m%s\033[37m: \033[34m",
            user->pw_name, machine.nodename);
  if (!strncmp(pwd, user->pw_dir, strlen(user->pw_dir))) {
    strcat(prompt, "~");
    strcat(prompt, pwd + strlen(user->pw_dir));
  } else
    strcat(prompt, pwd);
  strcat(prompt, "\033[37m $>");
  free(pwd);
  return prompt;
}


x86 assembly (clang, -O0):
<set_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1080 <getuid@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <getpwuid@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <get_current_dir@plt>
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1090 <uname@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
add    $0x3c,%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1259 <set_prompt+0xb9>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%r8
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
jmp    1276 <set_prompt+0xd6>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12f2 <set_prompt+0x152>
mov    -0x10(%rbp),%rdi
lea    0xd7b(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdi
add    %rax,%rsi
call   10b0 <strcat@plt>
jmp    12ff <set_prompt+0x15f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xd2e(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_prompt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r12d
xor    %eax,%eax
call   1080 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <get_current_dir@plt>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
call   1090 <uname@plt>
mov    %rbx,0x8(%rsp)
mov    (%rbx),%r13
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rax,%r14
add    %ebx,%r14d
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    (%rax,%r14,1),%edi
add    $0x3c,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
test   %r12d,%r12d
je     1234 <set_prompt+0x94>
lea    0xde1(%rip),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
mov    %r13,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   10c0 <sprintf@plt>
jmp    124b <set_prompt+0xab>
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    0x8(%rsp),%r14
mov    0x8(%r14),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
mov    %r15,%rsi
test   %eax,%eax
jne    128f <set_prompt+0xef>
lea    0xdbe(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    0x8(%r14),%rdi
call   1060 <strlen@plt>
mov    %r15,%rsi
add    %rax,%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
lea    0xd9a(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8* }
%struct.passwd = type { i8*, i8* }
@.str = [54 x i8] c"[\1B[34m%d\1B[36m!\1B[37m][\1B[31m%s\1B[37m@\1B[35m%s\1B[37m: \1B[34m\00"
@.str.1 = [34 x i8] c"[\1B[31m%s\1B[37m@\1B[35m%s\1B[37m: \1B[34m\00"
@.str.2 = [2 x i8] c"~\00"
@.str.3 = [9 x i8] c"\1B[37m $>\00"
define i8* @set_prompt(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.utsname
%6 = alloca %struct.passwd*
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %2
%9 = call i32 (...) @getuid()
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = call %struct.passwd* @getpwuid(i32 %10)
store %struct.passwd* %11, %struct.passwd** %6
%12 = call i8* (...) @get_current_dir()
store i8* %12, i8** %4
%13 = call i32 @uname(%struct.utsname* %5)
%14 = load %struct.passwd*, %struct.passwd** %6
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i64 @strlen(i8* %16)
%18 = add i64 60, %17
%19 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i64 @strlen(i8* %20)
%22 = add i64 %18, %21
%23 = load i8*, i8** %4
%24 = call i64 @strlen(i8* %23)
%25 = add i64 %22, %24
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
store i8* %29, i8** %3
%30 = load i32, i32* %2
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %1
%33 = load i8*, i8** %3
%34 = load i32, i32* %2
%35 = load %struct.passwd*, %struct.passwd** %6
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 0
%39 = load i8*, i8** %38
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %34, i8* %37, i8* %39)
br label %49
41: ; preds = %1
%42 = load i8*, i8** %3
%43 = load %struct.passwd*, %struct.passwd** %6
%44 = getelementptr inbounds %struct.passwd, %struct.passwd* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %45, i8* %47)
br label %49
49: ; preds = %41, %32
%50 = load i8*, i8** %4
%51 = load %struct.passwd*, %struct.passwd** %6
%52 = getelementptr inbounds %struct.passwd, %struct.passwd* %51, i32 0, i32 1
%53 = load i8*, i8** %52
%54 = load %struct.passwd*, %struct.passwd** %6
%55 = getelementptr inbounds %struct.passwd, %struct.passwd* %54, i32 0, i32 1
%56 = load i8*, i8** %55
%57 = call i64 @strlen(i8* %56)
%58 = call i32 @strncmp(i8* %50, i8* %53, i64 %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %71, label %60
60: ; preds = %49
%61 = load i8*, i8** %3
%62 = call i32 @strcat(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%63 = load i8*, i8** %3
%64 = load i8*, i8** %4
%65 = load %struct.passwd*, %struct.passwd** %6
%66 = getelementptr inbounds %struct.passwd, %struct.passwd* %65, i32 0, i32 1
%67 = load i8*, i8** %66
%68 = call i64 @strlen(i8* %67)
%69 = getelementptr inbounds i8, i8* %64, i64 %68
%70 = call i32 @strcat(i8* %63, i8* %69)
br label %75
71: ; preds = %49
%72 = load i8*, i8** %3
%73 = load i8*, i8** %4
%74 = call i32 @strcat(i8* %72, i8* %73)
br label %75
75: ; preds = %71, %60
%76 = load i8*, i8** %3
%77 = call i32 @strcat(i8* %76, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%78 = load i8*, i8** %4
%79 = call i32 @free(i8* %78)
%80 = load i8*, i8** %3
ret i8* %80
}

LLVM IR (-O2):
%struct.utsname = type { i8* }
%struct.passwd = type { i8*, i8* }
@.str = [54 x i8] c"[\1B[34m%d\1B[36m!\1B[37m][\1B[31m%s\1B[37m@\1B[35m%s\1B[37m: \1B[34m\00"
@.str.1 = [34 x i8] c"[\1B[31m%s\1B[37m@\1B[35m%s\1B[37m: \1B[34m\00"
@.str.2 = [2 x i8] c"~\00"
@.str.3 = [9 x i8] c"\1B[37m $>\00"
define i8* @set_prompt(i32 %0) {
%2 = alloca %struct.utsname
%3 = bitcast %struct.utsname* %2 to i8*
%4 = tail call i32 (...) @getuid()
%5 = tail call %struct.passwd* @getpwuid(i32 %4)
%6 = tail call i8* (...) @get_current_dir()
%7 = call i32 @uname(%struct.utsname* %2)
%8 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%11 = add i64 %10, 60
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %2, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%15 = add i64 %11, %14
%16 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%17 = add i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = tail call i8* @malloc(i32 %18)
%20 = icmp eq i32 %0, 0
br i1 %20, label %23, label %21
21: ; preds = %1
%22 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %9, i8* %13)
br label %25
23: ; preds = %1
%24 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %13)
br label %25
25: ; preds = %23, %21
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 1
%27 = load i8*, i8** %26
%28 = tail call i64 @strlen(i8* dereferenceable(1) %27)
%29 = tail call i32 @strncmp(i8* %6, i8* %27, i64 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %26
%34 = tail call i64 @strlen(i8* dereferenceable(1) %33)
%35 = getelementptr inbounds i8, i8* %6, i64 %34
br label %36
36: ; preds = %25, %31
%37 = phi i8* [ %35, %31 ], [ %6, %25 ]
%38 = tail call i32 @strcat(i8* %19, i8* %37)
%39 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%40 = tail call i32 @free(i8* %6)
ret i8* %19
}