#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 */
char *comand_complete(char *, char *);
char *file_complete(char *, int, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strrchr(char *, char);
char *try_complete(char *str, char *prompt) {
  char *p = str;
  if (str == NULL)
    return NULL;
  while (' ' == *p)
    p++;
  if ('\0' == *p)
    return NULL;
  p = strrchr(p, ' ');
  if (p == NULL) {
    p = str;
    if (*p != '/' && *p != '.')
      return comand_complete(str, prompt);
  }
  if (!strncmp("cd ", p, 3))
    return file_complete(str, 4 | 0, prompt);
  else
    return file_complete(str, 0, prompt);
  return NULL;
}


x86 assembly (clang, -O0):
<try_complete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1170 <try_complete+0x30>
movq   $0x0,-0x8(%rbp)
jmp    1264 <try_complete+0x124>
jmp    1175 <try_complete+0x35>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x20,%eax
cmp    %ecx,%eax
jne    119a <try_complete+0x5a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1175 <try_complete+0x35>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11b8 <try_complete+0x78>
movq   $0x0,-0x8(%rbp)
jmp    1264 <try_complete+0x124>
mov    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1218 <try_complete+0xd8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1213 <try_complete+0xd3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1213 <try_complete+0xd3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <comand_complete@plt>
mov    %rax,-0x8(%rbp)
jmp    1264 <try_complete+0x124>
jmp    1218 <try_complete+0xd8>
mov    -0x20(%rbp),%rsi
lea    0xddd(%rip),%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1251 <try_complete+0x111>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x4,%esi
call   1060 <file_complete@plt>
mov    %rax,-0x8(%rbp)
jmp    1264 <try_complete+0x124>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1060 <file_complete@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<try_complete>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1161 <try_complete+0x21>
mov    %rsi,%r14
mov    %rdi,%rbx
nop
movzbl (%rdi),%eax
cmp    $0x20,%al
jne    115d <try_complete+0x1d>
add    $0x1,%rdi
jmp    1150 <try_complete+0x10>
test   %al,%al
jne    116b <try_complete+0x2b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x20,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
jne    1187 <try_complete+0x47>
mov    (%rbx),%cl
and    $0xfe,%cl
mov    %rbx,%rax
cmp    $0x2e,%cl
jne    11ba <try_complete+0x7a>
lea    0xe72(%rip),%rdi
mov    %rax,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
mov    %rbx,%rdi
test   %eax,%eax
je     11a6 <try_complete+0x66>
xor    %esi,%esi
jmp    11ab <try_complete+0x6b>
mov    $0x4,%esi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <file_complete@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <comand_complete@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"cd \00"
define i8* @try_complete(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
store i8* %7, i8** %6
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* null, i8** %3
br label %59
11: ; preds = %2
br label %12
12: ; preds = %17, %11
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 32, %15
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %6
br label %12
20: ; preds = %12
%21 = load i8*, i8** %6
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 0, %23
br i1 %24, label %25, label %26
25: ; preds = %20
store i8* null, i8** %3
br label %59
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = call i8* @strrchr(i8* %27, i8 signext 32)
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %47
31: ; preds = %26
%32 = load i8*, i8** %4
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 47
br i1 %36, label %37, label %46
37: ; preds = %31
%38 = load i8*, i8** %6
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 46
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i8*, i8** %4
%44 = load i8*, i8** %5
%45 = call i8* @comand_complete(i8* %43, i8* %44)
store i8* %45, i8** %3
br label %59
46: ; preds = %37, %31
br label %47
47: ; preds = %46, %26
%48 = load i8*, i8** %6
%49 = call i32 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %48, i32 3)
%50 = icmp ne i32 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i8*, i8** %4
%53 = load i8*, i8** %5
%54 = call i8* @file_complete(i8* %52, i32 4, i8* %53)
store i8* %54, i8** %3
br label %59
55: ; preds = %47
%56 = load i8*, i8** %4
%57 = load i8*, i8** %5
%58 = call i8* @file_complete(i8* %56, i32 0, i8* %57)
store i8* %58, i8** %3
br label %59
59: ; preds = %55, %51, %42, %25, %10
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
@.str = [4 x i8] c"cd \00"
define i8* @try_complete(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %26, label %4
4: ; preds = %2, %7
%5 = phi i8* [ %8, %7 ], [ %0, %2 ]
%6 = load i8, i8* %5
switch i8 %6, label %9 [
i8 32, label %7
i8 0, label %26
]
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
9: ; preds = %4
%10 = tail call i8* @strrchr(i8* %5, i8 signext 32)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i8, i8* %0
%14 = and i8 %13, -2
%15 = icmp eq i8 %14, 46
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = tail call i8* @comand_complete(i8* %0, i8* %1)
br label %26
18: ; preds = %12, %9
%19 = phi i8* [ %10, %9 ], [ %0, %12 ]
%20 = tail call i32 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19, i32 3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i8* @file_complete(i8* %0, i32 4, i8* %1)
br label %26
24: ; preds = %18
%25 = tail call i8* @file_complete(i8* %0, i32 0, i8* %1)
br label %26
26: ; preds = %4, %2, %24, %22, %16
%27 = phi i8* [ %17, %16 ], [ %25, %24 ], [ %23, %22 ], [ null, %2 ], [ null, %4 ]
ret i8* %27
}