#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 */
struct passwd {
  char *pw_dir;
  char *pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ getcwd(char *, int);
scalar_t__ gethostname(char *, int);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
void type_prompt() {
  struct passwd *user;
  char host[256];
  char pwd[1000];
  char path[1000];
  char prompt;
  user = getpwuid(getuid());
  if (user == NULL || gethostname(host, 255) || !getcwd(pwd, 999)) {
    printf("获取用户信息失败！\n");
    return;
  }
  strcpy(path, user->pw_dir);
  if (strncasecmp(path, pwd, strlen(path)) == 0) {
    sprintf(path, "~%s", pwd + strlen(path));
  } else {
    strcpy(path, pwd);
  }
  if (strcmp(user->pw_name, "root") == 0)
    prompt = '#';
  else
    prompt = '$';
  printf("[myshell]%s@%s:%s%c ", user->pw_name, host, path, prompt);
}


x86 assembly (clang, -O0):
<type_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x920,%rsp
mov    $0x0,%al
call   1060 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11fd <type_prompt+0x5d>
lea    -0x110(%rbp),%rdi
mov    $0xff,%esi
call   10b0 <gethostname@plt>
cmp    $0x0,%rax
jne    11fd <type_prompt+0x5d>
lea    -0x500(%rbp),%rdi
mov    $0x3e7,%esi
call   1080 <getcwd@plt>
cmp    $0x0,%eax
jne    1210 <type_prompt+0x70>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1326 <type_prompt+0x186>
lea    -0x8f0(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x8f0(%rbp),%rax
mov    %rax,-0x908(%rbp)
lea    -0x500(%rbp),%rax
mov    %rax,-0x900(%rbp)
lea    -0x8f0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x908(%rbp),%rdi
mov    -0x900(%rbp),%rsi
mov    %eax,%edx
call   10a0 <strncasecmp@plt>
cmp    $0x0,%rax
jne    12b6 <type_prompt+0x116>
lea    -0x8f0(%rbp),%rax
mov    %rax,-0x910(%rbp)
lea    -0x500(%rbp),%rax
mov    %rax,-0x918(%rbp)
lea    -0x8f0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x918(%rbp),%rdx
mov    -0x910(%rbp),%rdi
cltq
add    %rax,%rdx
lea    0xd71(%rip),%rsi
call   10c0 <sprintf@plt>
jmp    12c9 <type_prompt+0x129>
lea    -0x8f0(%rbp),%rdi
lea    -0x500(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd49(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12f3 <type_prompt+0x153>
movb   $0x23,-0x8f1(%rbp)
jmp    12fa <type_prompt+0x15a>
movb   $0x24,-0x8f1(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x110(%rbp),%rdx
lea    -0x8f0(%rbp),%rcx
movsbl -0x8f1(%rbp),%r8d
ff
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
add    $0x920,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<type_prompt>:
push   %r14
push   %rbx
sub    $0x8d8,%rsp
xor    %eax,%eax
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
test   %rax,%rax
je     11e2 <type_prompt+0x32>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0xff,%esi
call   10c0 <gethostname@plt>
test   %rax,%rax
je     11f9 <type_prompt+0x49>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
add    $0x8d8,%rsp
pop    %rbx
pop    %r14
ret
lea    0x4f0(%rsp),%rdi
mov    $0x3e7,%esi
call   1090 <getcwd@plt>
test   %eax,%eax
je     11e2 <type_prompt+0x32>
mov    (%rbx),%rsi
lea    0x100(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x4f0(%rsp),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   10b0 <strncasecmp@plt>
test   %rax,%rax
je     1258 <type_prompt+0xa8>
lea    0x100(%rsp),%rdi
lea    0x4f0(%rsp),%rsi
call   1030 <strcpy@plt>
jmp    1284 <type_prompt+0xd4>
lea    0x100(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdx
add    $0x4f0,%rdx
lea    0xd84(%rip),%rsi
mov    %r14,%rdi
call   10d0 <sprintf@plt>
mov    0x8(%rbx),%rdi
lea    0xd75(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x1,%rax
mov    $0x24,%r8d
sbb    $0x0,%r8d
mov    0x8(%rbx),%rsi
lea    0xd5c(%rip),%rdi
mov    %rsp,%rdx
lea    0x100(%rsp),%rcx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    11ee <type_prompt+0x3e>

LLVM IR (-O0):
%struct.passwd = type { i8*, i8* }
@.str = [29 x i8] c"\E8\8E\B7\E5\8F\96\E7\94\A8\E6\88\B7\E4\BF\A1\E6\81\AF\E5\A4\B1\E8\B4\A5\EF\BC\81\0A\00"
@.str.1 = [4 x i8] c"~%s\00"
@.str.2 = [5 x i8] c"root\00"
@.str.3 = [21 x i8] c"[myshell]%s@%s:%s%c \00"
define void @type_prompt() {
%1 = alloca %struct.passwd*
%2 = alloca [256 x i8]
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = alloca i8
%6 = call i32 (...) @getuid()
%7 = call %struct.passwd* @getpwuid(i32 %6)
store %struct.passwd* %7, %struct.passwd** %1
%8 = load %struct.passwd*, %struct.passwd** %1
%9 = icmp eq %struct.passwd* %8, null
br i1 %9, label %18, label %10
10: ; preds = %0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%12 = call i64 @gethostname(i8* %11, i32 255)
%13 = icmp ne i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%16 = call i32 @getcwd(i8* %15, i32 999)
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14, %10, %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %61
20: ; preds = %14
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = load %struct.passwd*, %struct.passwd** %1
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = call i64 @strncasecmp(i8* %26, i8* %27, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %20
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %44
40: ; preds = %20
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%42 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%43 = call i32 @strcpy(i8* %41, i8* %42)
br label %44
44: ; preds = %40, %32
%45 = load %struct.passwd*, %struct.passwd** %1
%46 = getelementptr inbounds %struct.passwd, %struct.passwd* %45, i32 0, i32 1
%47 = load i8*, i8** %46
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
store i8 35, i8* %5
br label %52
51: ; preds = %44
store i8 36, i8* %5
br label %52
52: ; preds = %51, %50
%53 = load %struct.passwd*, %struct.passwd** %1
%54 = getelementptr inbounds %struct.passwd, %struct.passwd* %53, i32 0, i32 1
%55 = load i8*, i8** %54
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%58 = load i8, i8* %5
%59 = sext i8 %58 to i32
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %55, i8* %56, i8* %57, i32 %59)
br label %61
61: ; preds = %52, %18
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8*, i8* }
@.str.1 = [4 x i8] c"~%s\00"
@.str.2 = [5 x i8] c"root\00"
@.str.3 = [21 x i8] c"[myshell]%s@%s:%s%c \00"
@str = [28 x i8] c"\E8\8E\B7\E5\8F\96\E7\94\A8\E6\88\B7\E4\BF\A1\E6\81\AF\E5\A4\B1\E8\B4\A5\EF\BC\81\00"
define void @type_prompt() {
%1 = alloca [256 x i8]
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (...) @getuid()
%8 = tail call %struct.passwd* @getpwuid(i32 %7)
%9 = icmp eq %struct.passwd* %8, null
br i1 %9, label %16, label %10
10: ; preds = %0
%11 = call i64 @gethostname(i8* %4, i32 255)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @getcwd(i8* %5, i32 999)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13, %10, %0
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %40
18: ; preds = %13
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %6, i8* %20)
%22 = call i32 @strlen(i8* %6)
%23 = call i64 @strncasecmp(i8* %6, i8* %5, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = call i32 @strlen(i8* %6)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %27
%29 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %32
30: ; preds = %18
%31 = call i32 @strcpy(i8* %6, i8* %5)
br label %32
32: ; preds = %30, %25
%33 = getelementptr inbounds %struct.passwd, %struct.passwd* %8, i64 0, i32 1
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
%37 = select i1 %36, i32 35, i32 36
%38 = load i8*, i8** %33
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %38, i8* %4, i8* %6, i32 %37)
br label %40
40: ; preds = %32, %16
ret void
}