#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*/ free(char *);
int /*<<< orphan*/ getcwd(char *, int);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strchr(char *, char);
char *strsep(char **, char *);
int print_prompt() {
  char *cwd;
  cwd = malloc(sizeof(char) * 256);
  getcwd(cwd, 256);
  char *cwdcopy = cwd;
  char *truncated_prompt;
  while (strchr(cwdcopy, '/')) {
    truncated_prompt = strsep(&cwdcopy, "/");
  }
  printf("%s$: ", cwdcopy);
  free(cwd);
  return 0;
}


x86 assembly (clang, -O0):
<print_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11bd <print_prompt+0x5d>
lea    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1080 <strsep@plt>
mov    %rax,-0x18(%rbp)
jmp    118c <print_prompt+0x2c>
mov    -0x10(%rbp),%rsi
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_prompt>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x100,%esi
call   1060 <getcwd@plt>
mov    %r14,0x8(%rsp)
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %r14,%rsi
test   %rax,%rax
je     11d4 <print_prompt+0x74>
lea    0xe5c(%rip),%r15
lea    0x8(%rsp),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strsep@plt>
mov    0x8(%rsp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11b0 <print_prompt+0x50>
mov    0x8(%rsp),%rsi
lea    0xe27(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [6 x i8] c"%s$: \00"
define i32 @print_prompt() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @malloc(i32 256)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i32 @getcwd(i8* %5, i32 256)
%7 = load i8*, i8** %1
store i8* %7, i8** %2
br label %8
8: ; preds = %12, %0
%9 = load i8*, i8** %2
%10 = call i64 @strchr(i8* %9, i8 signext 47)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %3
br label %8
14: ; preds = %8
%15 = load i8*, i8** %2
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %1
%18 = call i32 @free(i8* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [6 x i8] c"%s$: \00"
define i32 @print_prompt() {
%1 = alloca i8*
%2 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%3 = tail call i32 @getcwd(i8* %2, i32 256)
%4 = bitcast i8** %1 to i8*
store i8* %2, i8** %1
%5 = call i64 @strchr(i8* %2, i8 signext 47)
%6 = icmp eq i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %0, %7
%8 = call i8* @strsep(i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %1
%10 = call i64 @strchr(i8* %9, i8 signext 47)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = load i8*, i8** %1
br label %14
14: ; preds = %12, %0
%15 = phi i8* [ %13, %12 ], [ %2, %0 ]
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @free(i8* %2)
ret i32 0
}