#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*/ cgets(char *);
int /*<<< orphan*/ cprintf(char *, ...);
int /*<<< orphan*/ getpath_app();
int setpath_app(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ textattr(int);
int set_path(char *s) {
  char cfname[15];
  char *fname;
  int status;
  if (s == NULL) {
    cprintf("\n\rEnter (new) path (.. for up-level): ");
    cfname[0] = 12;
    cgets(cfname);
    fname = cfname + 2;
  } else {
    strcpy(cfname, s);
    fname = cfname;
  }
  status = setpath_app(fname);
  if (status) {
    textattr(0x0C);
    cprintf("\n\rDir '%s' does NOT exist. STATUS: %d", fname, status);
    textattr(0x07);
  }
  cprintf("\n\rPath: %s", getpath_app());
  return status;
}


x86 assembly (clang, -O0):
<set_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a3 <set_path+0x43>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1060 <cprintf@plt>
movb   $0xc,-0x17(%rbp)
lea    -0x17(%rbp),%rdi
call   1080 <cgets@plt>
lea    -0x17(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    11b8 <set_path+0x58>
lea    -0x17(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x17(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <setpath_app@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11f7 <set_path+0x97>
mov    $0xc,%edi
call   1050 <textattr@plt>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1060 <cprintf@plt>
mov    $0x7,%edi
call   1050 <textattr@plt>
mov    $0x0,%al
call   1070 <getpath_app@plt>
mov    %eax,%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <cprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_path>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     117d <set_path+0x1d>
mov    %rdi,%rsi
lea    0x9(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    119f <set_path+0x3f>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1060 <cprintf@plt>
movb   $0xc,0x9(%rsp)
lea    0x9(%rsp),%rdi
call   1080 <cgets@plt>
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <setpath_app@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11d4 <set_path+0x74>
mov    $0xc,%edi
call   1050 <textattr@plt>
lea    0xe69(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <cprintf@plt>
mov    $0x7,%edi
call   1050 <textattr@plt>
xor    %eax,%eax
call   1070 <getpath_app@plt>
lea    0xe6b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <cprintf@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"\0A\0DEnter (new) path (.. for up-level): \00"
@.str.1 = [38 x i8] c"\0A\0DDir '%s' does NOT exist. STATUS: %d\00"
@.str.2 = [11 x i8] c"\0A\0DPath: %s\00"
define i32 @set_path(i8* %0) {
%2 = alloca i8*
%3 = alloca [15 x i8]
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = call i32 (i8*, ...) @cprintf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
store i8 12, i8* %10
%11 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%12 = call i32 @cgets(i8* %11)
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %13, i64 2
store i8* %14, i8** %4
br label %20
15: ; preds = %1
%16 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%17 = load i8*, i8** %2
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
store i8* %19, i8** %4
br label %20
20: ; preds = %15, %8
%21 = load i8*, i8** %4
%22 = call i32 @setpath_app(i8* %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = call i32 @textattr(i32 12)
%27 = load i8*, i8** %4
%28 = load i32, i32* %5
%29 = call i32 (i8*, ...) @cprintf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 %28)
%30 = call i32 @textattr(i32 7)
br label %31
31: ; preds = %25, %20
%32 = call i32 (...) @getpath_app()
%33 = call i32 (i8*, ...) @cprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@.str = [39 x i8] c"\0A\0DEnter (new) path (.. for up-level): \00"
@.str.1 = [38 x i8] c"\0A\0DDir '%s' does NOT exist. STATUS: %d\00"
@.str.2 = [11 x i8] c"\0A\0DPath: %s\00"
define i32 @set_path(i8* %0) {
%2 = alloca [15 x i8]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @cprintf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i8 12, i8* %3
%7 = call i32 @cgets(i8* %3)
%8 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 2
br label %11
9: ; preds = %1
%10 = call i32 @strcpy(i8* %3, i8* %0)
br label %11
11: ; preds = %9, %5
%12 = phi i8* [ %8, %5 ], [ %3, %9 ]
%13 = call i32 @setpath_app(i8* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = call i32 @textattr(i32 12)
%17 = call i32 (i8*, ...) @cprintf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %13)
%18 = call i32 @textattr(i32 7)
br label %19
19: ; preds = %15, %11
%20 = call i32 (...) @getpath_app()
%21 = call i32 (i8*, ...) @cprintf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %20)
ret i32 %13
}