#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 dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int tilda_strcmp(char *, int /*<<< orphan*/);
int high_ver_name(char *name, char *path) {
  int next, tilda = (-1);
  struct dirent *dp;
  DIR *dirp;
  int closedir();
  if (path[0] == '.' || path[0] == ' ')
    dirp = opendir(".");
  else
    dirp = opendir(path);
  if (dirp != NULL) {
    for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
      next = tilda_strcmp(name, dp->d_name);
      if (next > tilda)
        tilda = next;
    }
    closedir(dirp);
  }
  return tilda;
}


x86 assembly (clang, -O0):
<high_ver_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1177 <high_ver_name+0x37>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    118c <high_ver_name+0x4c>
lea    0xe82(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
jmp    1199 <high_ver_name+0x59>
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1202 <high_ver_name+0xc2>
mov    -0x28(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f7 <high_ver_name+0xb7>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1050 <tilda_strcmp@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11e0 <high_ver_name+0xa0>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11e5 <high_ver_name+0xa5>
mov    -0x28(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
jmp    11b1 <high_ver_name+0x71>
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1040 <closedir@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<high_ver_name>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rsi),%al
cmp    $0x2e,%al
je     1151 <high_ver_name+0x11>
cmp    $0x20,%al
jne    115a <high_ver_name+0x1a>
lea    0xea8(%rip),%rdi
jmp    115d <high_ver_name+0x1d>
mov    %rsi,%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a8 <high_ver_name+0x68>
mov    %rbx,%rdi
call   1060 <readdir@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     119c <high_ver_name+0x5c>
nopl   0x0(%rax)
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <tilda_strcmp@plt>
cmp    %ebp,%eax
cmovg  %eax,%ebp
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    1180 <high_ver_name+0x40>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <closedir@plt>
jmp    11ad <high_ver_name+0x6d>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
define i32 @high_ver_name(i8* %0, i8* nocapture %1) {
%3 = load i8, i8* %1
switch i8 %3, label %6 [
i8 46, label %4
i8 32, label %4
]
4: ; preds = %2, %2
%5 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %8
6: ; preds = %2
%7 = tail call i32* @opendir(i8* %1)
br label %8
8: ; preds = %6, %4
%9 = phi i32* [ %5, %4 ], [ %7, %6 ]
%10 = icmp eq i32* %9, null
br i1 %10, label %27, label %11
11: ; preds = %8
%12 = tail call %struct.dirent* @readdir(i32* %9)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %24, label %14
14: ; preds = %11, %14
%15 = phi %struct.dirent* [ %22, %14 ], [ %12, %11 ]
%16 = phi i32 [ %21, %14 ], [ -1, %11 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i32 @tilda_strcmp(i8* %0, i32 %18)
%20 = icmp sgt i32 %19, %16
%21 = select i1 %20, i32 %19, i32 %16
%22 = tail call %struct.dirent* @readdir(i32* %9)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %24, label %14
24: ; preds = %14, %11
%25 = phi i32 [ -1, %11 ], [ %21, %14 ]
%26 = tail call i32 (i32*, ...) bitcast (i32 (...)* @closedir to i32 (i32*, ...)*)(i32* %9)
br label %27
27: ; preds = %24, %8
%28 = phi i32 [ %25, %24 ], [ -1, %8 ]
ret i32 %28
}