#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 window {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cbreak();
int chdir(char *);
int /*<<< orphan*/ curs_set(int /*<<< orphan*/);
struct window *defaultWindow();
int /*<<< orphan*/ erase();
int /*<<< orphan*/ getch();
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printw(char *);
struct window *changeDirectory(char *newDirectory) {
  if ((chdir(newDirectory)) == -1) {
    erase();
    printw("Unable to switch");
    noecho();
    curs_set(0);
    cbreak();
    getch();
    erase();
    return NULL;
  }
  return defaultWindow();
}


x86 assembly (clang, -O0):
<changeDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11e1 <changeDirectory+0x61>
mov    $0x0,%al
call   1050 <erase@plt>
lea    0xe54(%rip),%rdi
call   1060 <printw@plt>
mov    $0x0,%al
call   1090 <noecho@plt>
xor    %edi,%edi
call   10a0 <curs_set@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    $0x0,%al
call   1080 <getch@plt>
mov    $0x0,%al
call   1050 <erase@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ec <changeDirectory+0x6c>
mov    $0x0,%al
call   1070 <defaultWindow@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeDirectory>:
push   %rax
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     1193 <changeDirectory+0x13>
xor    %eax,%eax
pop    %rcx
jmp    1070 <defaultWindow@plt>
xor    %eax,%eax
call   1050 <erase@plt>
lea    0xe5f(%rip),%rdi
call   1060 <printw@plt>
xor    %eax,%eax
call   1090 <noecho@plt>
xor    %edi,%edi
call   10a0 <curs_set@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
xor    %eax,%eax
call   1080 <getch@plt>
xor    %eax,%eax
call   1050 <erase@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.window = type { i32 }
@.str = [17 x i8] c"Unable to switch\00"
define %struct.window* @changeDirectory(i8* %0) {
%2 = alloca %struct.window*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @chdir(i8* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = call i32 (...) @erase()
%9 = call i32 @printw(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @noecho()
%11 = call i32 @curs_set(i32 0)
%12 = call i32 (...) @cbreak()
%13 = call i32 (...) @getch()
%14 = call i32 (...) @erase()
store %struct.window* null, %struct.window** %2
br label %17
15: ; preds = %1
%16 = call %struct.window* (...) @defaultWindow()
store %struct.window* %16, %struct.window** %2
br label %17
17: ; preds = %15, %7
%18 = load %struct.window*, %struct.window** %2
ret %struct.window* %18
}

LLVM IR (-O2):
%struct.window = type { i32 }
@.str = [17 x i8] c"Unable to switch\00"
define %struct.window* @changeDirectory(i8* %0) {
%2 = tail call i32 @chdir(i8* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = tail call i32 (...) @erase()
%6 = tail call i32 @printw(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (...) @noecho()
%8 = tail call i32 @curs_set(i32 0)
%9 = tail call i32 (...) @cbreak()
%10 = tail call i32 (...) @getch()
%11 = tail call i32 (...) @erase()
br label %14
12: ; preds = %1
%13 = tail call %struct.window* (...) @defaultWindow()
br label %14
14: ; preds = %12, %4
%15 = phi %struct.window* [ null, %4 ], [ %13, %12 ]
ret %struct.window* %15
}