#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*/ chdir(char *);
int ft_strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void backup_cd(char *cdpath) {
  cdpath -= 5;
  if (cdpath)
    cdpath += 5;
  else
    cdpath = "(null)";
  write(2,
        "ft_minishell"
        ": Problem with HOME path: ",
        sizeof("ft_minishell"
               ": Problem with HOME path: "));
  write(2, cdpath, ft_strlen(cdpath));
  write(2, ".\nRoot is your new directory.\n", 30);
  chdir("/");
}


x86 assembly (clang, -O0):
<backup_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xfffffffffffffffb,%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1164 <backup_cd+0x34>
mov    -0x8(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
jmp    116f <backup_cd+0x3f>
lea    0xe95(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    $0x2,%edi
lea    0xe8c(%rip),%rsi
mov    $0x27,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1030 <write@plt>
mov    $0x2,%edi
lea    0xe7c(%rip),%rsi
mov    $0x1e,%edx
call   1030 <write@plt>
lea    0xe8a(%rip),%rdi
call   1050 <chdir@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<backup_cd>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rsi
mov    $0x2,%edi
mov    $0x27,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1040 <ft_strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xebf(%rip),%rsi
mov    $0x2,%edi
mov    $0x1e,%edx
call   1030 <write@plt>
lea    0xec8(%rip),%rdi
pop    %rbx
jmp    1050 <chdir@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"(null)\00"
@.str.1 = [39 x i8] c"ft_minishell: Problem with HOME path: \00"
@.str.2 = [31 x i8] c".\0ARoot is your new directory.\0A\00"
@.str.3 = [2 x i8] c"/\00"
define void @backup_cd(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = getelementptr inbounds i8, i8* %3, i64 -5
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 5
store i8* %9, i8** %2
br label %11
10: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
br label %11
11: ; preds = %10, %7
%12 = call i32 @write(i32 2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 39)
%13 = load i8*, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 @ft_strlen(i8* %14)
%16 = call i32 @write(i32 2, i8* %13, i32 %15)
%17 = call i32 @write(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 30)
%18 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [39 x i8] c"ft_minishell: Problem with HOME path: \00"
@.str.2 = [31 x i8] c".\0ARoot is your new directory.\0A\00"
@.str.3 = [2 x i8] c"/\00"
define void @backup_cd(i8* %0) {
%2 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 39)
%3 = tail call i32 @ft_strlen(i8* %0)
%4 = tail call i32 @write(i32 2, i8* %0, i32 %3)
%5 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 30)
%6 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}