#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*/ cmd_file(char const *, char const *, void *);
int strlen(char *);
unsigned char cmd_directory(const char *com, const char *val, void *place) {
  char *s, *t;
  if (!cmd_file(com, val, place))
    return 0;
  s = *(char **)place;
  t = s + strlen(s);
  while (t > s && *--t == '/')
    *t = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<cmd_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <cmd_file@plt>
cmp    $0x0,%eax
jne    1157 <cmd_directory+0x37>
movb   $0x0,-0x1(%rbp)
jmp    11d2 <cmd_directory+0xb2>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    -0x28(%rbp),%rcx
mov    %al,-0x39(%rbp)
jbe    11b2 <cmd_directory+0x92>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11c2 <cmd_directory+0xa2>
jmp    11ce <cmd_directory+0xae>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
jmp    1183 <cmd_directory+0x63>
movb   $0x1,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_directory>:
push   %rbx
mov    %rdx,%rbx
call   1040 <cmd_file@plt>
test   %eax,%eax
je     1165 <cmd_directory+0x45>
mov    (%rbx),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0x1,%al
test   %ecx,%ecx
jle    1163 <cmd_directory+0x43>
mov    %ecx,%ecx
add    %rbx,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x2f,-0x1(%rcx)
jne    1163 <cmd_directory+0x43>
movb   $0x0,-0x1(%rcx)
add    $0xffffffffffffffff,%rcx
cmp    %rbx,%rcx
ja     1150 <cmd_directory+0x30>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define zeroext i8 @cmd_directory(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = load i8*, i8** %7
%13 = call i32 @cmd_file(i8* %10, i8* %11, i8* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %3
store i8 0, i8* %4
br label %40
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = bitcast i8* %17 to i8**
%19 = load i8*, i8** %18
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = load i8*, i8** %8
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8* %24, i8** %9
br label %25
25: ; preds = %37, %16
%26 = load i8*, i8** %9
%27 = load i8*, i8** %8
%28 = icmp ugt i8* %26, %27
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %9
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 47
br label %35
35: ; preds = %29, %25
%36 = phi i1 [ false, %25 ], [ %34, %29 ]
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = load i8*, i8** %9
store i8 0, i8* %38
br label %25
39: ; preds = %35
store i8 1, i8* %4
br label %40
40: ; preds = %39, %15
%41 = load i8, i8* %4
ret i8 %41
}

LLVM IR (-O2):
define zeroext i8 @cmd_directory(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @cmd_file(i8* %0, i8* %1, i8* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = bitcast i8* %2 to i8**
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = zext i32 %9 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
br label %14
14: ; preds = %11, %19
%15 = phi i8* [ %16, %19 ], [ %13, %11 ]
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 47
br i1 %18, label %19, label %21
19: ; preds = %14
store i8 0, i8* %16
%20 = icmp ugt i8* %16, %8
br i1 %20, label %14, label %21
21: ; preds = %19, %14, %6, %3
%22 = phi i8 [ 0, %3 ], [ 1, %6 ], [ 1, %14 ], [ 1, %19 ]
ret i8 %22
}