#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 PATH_MAX;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ gethostname(char *, int);
char *load_var(char *);
int strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void print_prompt(char *ps1) {
  char *tmp = ps1;
  while (*tmp != '\0') {
    if (*tmp == '\\') {
      char buf[PATH_MAX];
      char *user;
      buf[0] = '\0';
      switch (*(tmp + 1)) {
      case 'u':
        user = load_var("USER");
        if (user != NULL) {
          write(STDOUT_FILENO, user, strlen(user));
        }
        tmp++;
        break;
      case 'h':
        gethostname(buf, PATH_MAX);
        write(STDOUT_FILENO, buf, strlen(buf));
        tmp++;
        break;
      case 'w':
        getcwd(buf, PATH_MAX);
        write(STDOUT_FILENO, buf, strlen(buf));
        tmp++;
        break;
      default:
        write(STDOUT_FILENO, "\\", 1);
      }
    } else {
      write(STDOUT_FILENO, tmp, 1);
    }
    tmp++;
  }
}


x86 assembly (clang, -O0):
<print_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1328 <print_prompt+0x1d8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1300 <print_prompt+0x1b0>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,%edx
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
mov    %rdx,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rax
mov    %rax,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
neg    %rcx
mov    %rdx,-0x20(%rbp)
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x68,%eax
je     124e <print_prompt+0xfe>
jmp    11d5 <print_prompt+0x85>
mov    -0x2c(%rbp),%eax
sub    $0x75,%eax
je     11f7 <print_prompt+0xa7>
jmp    11e6 <print_prompt+0x96>
mov    -0x2c(%rbp),%eax
sub    $0x77,%eax
je     1294 <print_prompt+0x144>
jmp    12da <print_prompt+0x18a>
lea    0xe02(%rip),%rdi
call   1060 <load_var@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123d <print_prompt+0xed>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12f4 <print_prompt+0x1a4>
mov    -0x38(%rbp),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
call   1070 <gethostname@plt>
mov    -0x38(%rbp),%rdi
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
call   1040 <strlen@plt>
mov    -0x48(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12f4 <print_prompt+0x1a4>
mov    -0x38(%rbp),%rdi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
call   1050 <getcwd@plt>
mov    -0x38(%rbp),%rdi
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12f4 <print_prompt+0x1a4>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1317 <print_prompt+0x1c7>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1164 <print_prompt+0x14>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_prompt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e80(%rip),%r14
jmp    118b <print_prompt+0x3b>
mov    (%r14),%edi
lea    0xe91(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %rbx,%r13
mov    %r15,%rsp
add    $0x1,%r13
mov    %r13,%rbx
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     11b0 <print_prompt+0x60>
test   %al,%al
je     125d <print_prompt+0x10d>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x1,%rbx
jmp    118b <print_prompt+0x3b>
mov    %rsp,%r15
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rcx,%r12
sub    %rax,%r12
mov    %r12,%rsp
neg    %rax
movb   $0x0,(%rcx,%rax,1)
lea    0x1(%rbx),%r13
movsbl 0x1(%rbx),%eax
cmp    $0x68,%eax
je     121d <print_prompt+0xcd>
cmp    $0x77,%eax
je     1230 <print_prompt+0xe0>
cmp    $0x75,%eax
jne    116a <print_prompt+0x1a>
lea    0xe07(%rip),%rdi
call   1060 <load_var@plt>
test   %rax,%rax
je     1181 <print_prompt+0x31>
mov    %rax,%rbx
mov    (%r14),%r12d
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
jmp    1251 <print_prompt+0x101>
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1070 <gethostname@plt>
jmp    1241 <print_prompt+0xf1>
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1050 <getcwd@plt>
mov    (%r14),%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1181 <print_prompt+0x31>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"USER\00"
@STDOUT_FILENO = global i32 0
@.str.1 = [2 x i8] c"\\\00"
define void @print_prompt(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %3
br label %8
8: ; preds = %66, %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %69
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 92
br i1 %17, label %18, label %62
18: ; preds = %13
%19 = load i32, i32* @PATH_MAX
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %4
%22 = alloca i8, i64 %20
store i64 %20, i64* %5
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 0, i8* %23
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %57 [
i32 117, label %28
i32 104, label %41
i32 119, label %49
]
28: ; preds = %18
%29 = call i8* @load_var(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %29, i8** %6
%30 = load i8*, i8** %6
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i32, i32* @STDOUT_FILENO
%34 = load i8*, i8** %6
%35 = load i8*, i8** %6
%36 = call i32 @strlen(i8* %35)
%37 = call i32 @write(i32 %33, i8* %34, i32 %36)
br label %38
38: ; preds = %32, %28
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %3
br label %60
41: ; preds = %18
%42 = load i32, i32* @PATH_MAX
%43 = call i32 @gethostname(i8* %22, i32 %42)
%44 = load i32, i32* @STDOUT_FILENO
%45 = call i32 @strlen(i8* %22)
%46 = call i32 @write(i32 %44, i8* %22, i32 %45)
%47 = load i8*, i8** %3
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %3
br label %60
49: ; preds = %18
%50 = load i32, i32* @PATH_MAX
%51 = call i32 @getcwd(i8* %22, i32 %50)
%52 = load i32, i32* @STDOUT_FILENO
%53 = call i32 @strlen(i8* %22)
%54 = call i32 @write(i32 %52, i8* %22, i32 %53)
%55 = load i8*, i8** %3
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %3
br label %60
57: ; preds = %18
%58 = load i32, i32* @STDOUT_FILENO
%59 = call i32 @write(i32 %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %60
60: ; preds = %57, %49, %41, %38
%61 = load i8*, i8** %4
br label %66
62: ; preds = %13
%63 = load i32, i32* @STDOUT_FILENO
%64 = load i8*, i8** %3
%65 = call i32 @write(i32 %63, i8* %64, i32 1)
br label %66
66: ; preds = %62, %60
%67 = load i8*, i8** %3
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %3
br label %8
69: ; preds = %8
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"USER\00"
@STDOUT_FILENO = global i32 0
@.str.1 = [2 x i8] c"\\\00"
define void @print_prompt(i8* nocapture %0) {
br label %2
2: ; preds = %40, %1
%3 = phi i8* [ %0, %1 ], [ %42, %40 ]
%4 = load i8, i8* %3
switch i8 %4, label %37 [
i8 0, label %43
i8 92, label %5
]
5: ; preds = %2
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
store i8 0, i8* %9
%10 = getelementptr inbounds i8, i8* %3, i64 1
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %32 [
i32 117, label %13
i32 104, label %20
i32 119, label %26
]
13: ; preds = %5
%14 = call i8* @load_var(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %35, label %16
16: ; preds = %13
%17 = load i32, i32* @STDOUT_FILENO
%18 = call i32 @strlen(i8* %14)
%19 = call i32 @write(i32 %17, i8* %14, i32 %18)
br label %35
20: ; preds = %5
%21 = load i32, i32* @PATH_MAX
%22 = call i32 @gethostname(i8* %9, i32 %21)
%23 = load i32, i32* @STDOUT_FILENO
%24 = call i32 @strlen(i8* %9)
%25 = call i32 @write(i32 %23, i8* %9, i32 %24)
br label %35
26: ; preds = %5
%27 = load i32, i32* @PATH_MAX
%28 = call i32 @getcwd(i8* %9, i32 %27)
%29 = load i32, i32* @STDOUT_FILENO
%30 = call i32 @strlen(i8* %9)
%31 = call i32 @write(i32 %29, i8* %9, i32 %30)
br label %35
32: ; preds = %5
%33 = load i32, i32* @STDOUT_FILENO
%34 = call i32 @write(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %35
35: ; preds = %13, %16, %32, %26, %20
%36 = phi i8* [ %3, %32 ], [ %10, %26 ], [ %10, %20 ], [ %10, %16 ], [ %10, %13 ]
br label %40
37: ; preds = %2
%38 = load i32, i32* @STDOUT_FILENO
%39 = call i32 @write(i32 %38, i8* %3, i32 1)
br label %40
40: ; preds = %37, %35
%41 = phi i8* [ %36, %35 ], [ %3, %37 ]
%42 = getelementptr inbounds i8, i8* %41, i64 1
br label %2
43: ; preds = %2
ret void
}