#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);
scalar_t__ getenv(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strncpy(char *, scalar_t__, int);
scalar_t__ strrchr(char *, char);
void print_prompt(void) {
  char username[1024];
  username[1023] = '\0';
  strncpy(username, getenv("USER"), 1023);
  char hostname[1024];
  hostname[1023] = '\0';
  gethostname(hostname, 1023);
  char work_dir[1024];
  work_dir[1023] = '\0';
  getcwd(work_dir, 1023);
  char relative_path[1024];
  relative_path[1023] = '\0';
  strncpy(relative_path, strrchr(work_dir, '/') + 1, 1023);
  printf("%s@", username);
  printf("%s ", hostname);
  printf("~%s > ", relative_path);
}


x86 assembly (clang, -O0):
<print_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movb   $0x0,-0x1(%rbp)
lea    -0x400(%rbp),%rax
mov    %rax,-0x1010(%rbp)
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x1010(%rbp),%rdi
mov    %rax,%rsi
mov    $0x3ff,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x401(%rbp)
lea    -0x800(%rbp),%rdi
mov    $0x3ff,%esi
call   1080 <gethostname@plt>
movb   $0x0,-0x801(%rbp)
lea    -0xc00(%rbp),%rdi
mov    $0x3ff,%esi
call   1070 <getcwd@plt>
movb   $0x0,-0xc01(%rbp)
lea    -0x1000(%rbp),%rax
mov    %rax,-0x1008(%rbp)
lea    -0xc00(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    -0x1008(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
mov    $0x3ff,%edx
call   1040 <strncpy@plt>
lea    -0x400(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
lea    -0x800(%rbp),%rsi
lea    0xddd(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1000(%rbp),%rsi
lea    0xdce(%rip),%rdi
call   1050 <printf@plt>
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_prompt>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
movb   $0x0,0xfff(%rsp)
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
lea    0xc00(%rsp),%r14
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x3ff,%edx
call   1040 <strncpy@plt>
movb   $0x0,0xbff(%rsp)
lea    0x800(%rsp),%r15
mov    %r15,%rdi
mov    $0x3ff,%esi
call   1080 <gethostname@plt>
movb   $0x0,0x7ff(%rsp)
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3ff,%esi
call   1070 <getcwd@plt>
movb   $0x0,0x3ff(%rsp)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3ff,%edx
call   1040 <strncpy@plt>
lea    0xe03(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
lea    0xdf8(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
lea    0xded(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@.str.1 = [4 x i8] c"%s@\00"
@.str.2 = [4 x i8] c"%s \00"
@.str.3 = [7 x i8] c"~%s > \00"
define void @print_prompt() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 1023
store i8 0, i8* %5
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%7 = call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strncpy(i8* %6, i64 %7, i32 1023)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1023
store i8 0, i8* %9
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%11 = call i32 @gethostname(i8* %10, i32 1023)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %12
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = call i32 @getcwd(i8* %13, i32 1023)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1023
store i8 0, i8* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = call i64 @strrchr(i8* %17, i8 signext 47)
%19 = add nsw i64 %18, 1
%20 = call i32 @strncpy(i8* %16, i64 %19, i32 1023)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@.str.1 = [4 x i8] c"%s@\00"
@.str.2 = [4 x i8] c"%s \00"
@.str.3 = [7 x i8] c"~%s > \00"
define void @print_prompt() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 1023
store i8 0, i8* %6
%7 = tail call i64 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strncpy(i8* %5, i64 %7, i32 1023)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1023
store i8 0, i8* %10
%11 = call i32 @gethostname(i8* %9, i32 1023)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %13
%14 = call i32 @getcwd(i8* %12, i32 1023)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1023
store i8 0, i8* %16
%17 = call i64 @strrchr(i8* %12, i8 signext 47)
%18 = add nsw i64 %17, 1
%19 = call i32 @strncpy(i8* %15, i64 %18, i32 1023)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%22 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %15)
ret void
}