#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ beep();
char *do_browser(char *);
int /*<<< orphan*/ free(char *);
char *getcwd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ readable_dir(char *);
char *real_dir_from_tilde(char const *);
int stat(char *, struct stat *);
int /*<<< orphan*/ striponedir(char *);
char *do_browse_from(const char *inpath) {
  struct stat st;
  char *bob;
  char *path;
  assert(inpath != NULL);
  path = real_dir_from_tilde(inpath);
  if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
    striponedir(path);
    if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
      free(path);
      path = getcwd(NULL, -1 + 1);
    }
  }
  if (!readable_dir(path)) {
    beep();
    bob = NULL;
  } else
    bob = do_browser(path);
  free(path);
  return bob;
}


x86 assembly (clang, -O0):
<do_browse_from>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x8(%rbp),%rdi
call   10c0 <real_dir_from_tilde@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
je     11f2 <do_browse_from+0x52>
mov    -0x10(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    123f <do_browse_from+0x9f>
mov    -0x20(%rbp),%rdi
call   1070 <striponedir@plt>
mov    -0x20(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
je     1222 <do_browse_from+0x82>
mov    -0x10(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    123a <do_browse_from+0x9a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x20(%rbp)
jmp    123f <do_browse_from+0x9f>
mov    -0x20(%rbp),%rdi
call   1080 <readable_dir@plt>
cmp    $0x0,%eax
jne    1265 <do_browse_from+0xc5>
mov    $0x0,%al
call   1090 <beep@plt>
movq   $0x0,-0x18(%rbp)
jmp    1272 <do_browse_from+0xd2>
mov    -0x20(%rbp),%rdi
call   1060 <do_browser@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_browse_from>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
call   10c0 <real_dir_from_tilde@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
je     11dc <do_browse_from+0x3c>
mov    (%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
jne    1214 <do_browse_from+0x74>
mov    %rbx,%rdi
call   1070 <striponedir@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
je     1200 <do_browse_from+0x60>
mov    (%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
jne    1214 <do_browse_from+0x74>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   1080 <readable_dir@plt>
test   %eax,%eax
je     122d <do_browse_from+0x8d>
mov    %rbx,%rdi
call   1060 <do_browser@plt>
mov    %rax,%r14
jmp    1237 <do_browse_from+0x97>
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <beep@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i8* @do_browse_from(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %2
%11 = call i8* @real_dir_from_tilde(i8* %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @stat(i8* %12, %struct.stat* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %20, label %15
15: ; preds = %1
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISDIR(i32 %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %36, label %20
20: ; preds = %15, %1
%21 = load i8*, i8** %5
%22 = call i32 @striponedir(i8* %21)
%23 = load i8*, i8** %5
%24 = call i32 @stat(i8* %23, %struct.stat* %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %31, label %26
26: ; preds = %20
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @S_ISDIR(i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %26, %20
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
%34 = call i8* @getcwd(i32* null, i32 0)
store i8* %34, i8** %5
br label %35
35: ; preds = %31, %26
br label %36
36: ; preds = %35, %15
%37 = load i8*, i8** %5
%38 = call i32 @readable_dir(i8* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = call i32 (...) @beep()
store i8* null, i8** %4
br label %45
42: ; preds = %36
%43 = load i8*, i8** %5
%44 = call i8* @do_browser(i8* %43)
store i8* %44, i8** %4
br label %45
45: ; preds = %42, %40
%46 = load i8*, i8** %5
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %4
ret i8* %48
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i8* @do_browse_from(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i8* @real_dir_from_tilde(i8* %0)
%8 = call i32 @stat(i8* %7, %struct.stat* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @S_ISDIR(i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %10, %1
%16 = tail call i32 @striponedir(i8* %7)
%17 = call i32 @stat(i8* %7, %struct.stat* %2)
%18 = icmp eq i32 %17, -1
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%21 = load i32, i32* %20
%22 = tail call i32 @S_ISDIR(i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19, %15
%25 = tail call i32 @free(i8* %7)
%26 = tail call i8* @getcwd(i32* null, i32 0)
br label %27
27: ; preds = %19, %24, %10
%28 = phi i8* [ %26, %24 ], [ %7, %19 ], [ %7, %10 ]
%29 = tail call i32 @readable_dir(i8* %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 (...) @beep()
br label %35
33: ; preds = %27
%34 = tail call i8* @do_browser(i8* %28)
br label %35
35: ; preds = %33, %31
%36 = phi i8* [ %34, %33 ], [ null, %31 ]
%37 = tail call i32 @free(i8* %28)
ret i8* %36
}