int max_version(pathname)
char *pathname;
{
  register char *p;
  register char *filename;
  int pathlen = strlen(pathname);
  int version;
  p = pathname + pathlen - 1;
  while (p > pathname && *p != '/')
    p--;
  if (*p == '/') {
    int dirlen = p - pathname;
    register char *dirname;
    filename = p + 1;
    dirname = xmalloc(dirlen + 1);
    strncpy(dirname, pathname, (dirlen));
    dirname[dirlen] = '\0';
    version = highest_version(filename, dirname);
    free(dirname);
    return version;
  }
  filename = pathname;
  version = highest_version(filename, ".");
  return version;
}


x86 assembly (clang, -O0):
<max_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x39(%rbp)
jbe    119e <max_version+0x4e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11ae <max_version+0x5e>
jmp    11bf <max_version+0x6f>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    117b <max_version+0x2b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    123f <max_version+0xef>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
mov    $0x0,%al
call   1060 <xmalloc@plt>
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x0,%al
call   1070 <highest_version@plt>
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1262 <max_version+0x112>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1070 <highest_version@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<max_version>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
movabs $0xffffffff00000000,%r12
ff ff ff
call   1050 <strlen@plt>
mov    %rax,%rcx
shl    $0x20,%rcx
movslq %eax,%rdx
add    %r14,%rdx
add    $0xffffffffffffffff,%rdx
add    %r12,%rcx
nop
mov    %rdx,%r13
mov    %rcx,%r15
mov    %eax,%edi
movzbl (%rdx),%ebx
cmp    %r14,%rdx
jbe    11a2 <max_version+0x52>
lea    -0x1(%r13),%rdx
lea    (%r15,%r12,1),%rcx
lea    -0x1(%rdi),%eax
cmp    $0x2f,%bl
jne    1180 <max_version+0x30>
jmp    11a7 <max_version+0x57>
cmp    $0x2f,%bl
jne    11ef <max_version+0x9f>
xor    %eax,%eax
call   1060 <xmalloc@plt>
movslq %eax,%r12
sar    $0x20,%r15
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <strncpy@plt>
movb   $0x0,(%r12,%r15,1)
add    $0x1,%r13
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <highest_version@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe0a(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1070 <highest_version@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i32 @max_version(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
store i32 %12, i32* %6
%13 = load i8*, i8** %3
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -1
store i8* %17, i8** %4
br label %18
18: ; preds = %29, %1
%19 = load i8*, i8** %4
%20 = load i8*, i8** %3
%21 = icmp ugt i8* %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 47
br label %27
27: ; preds = %22, %18
%28 = phi i1 [ false, %18 ], [ %26, %22 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %4
br label %18
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %65
37: ; preds = %32
%38 = load i8*, i8** %4
%39 = load i8*, i8** %3
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = trunc i64 %42 to i32
store i32 %43, i32* %8
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8* %45, i8** %5
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
%48 = call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %47)
%49 = sext i32 %48 to i64
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %9
%51 = load i8*, i8** %9
%52 = load i8*, i8** %3
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = call i8* @strncpy(i8* %51, i8* %52, i64 %54)
%56 = load i8*, i8** %9
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 0, i8* %59
%60 = load i8*, i8** %5
%61 = load i8*, i8** %9
%62 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @highest_version to i32 (i8*, i8*, ...)*)(i8* %60, i8* %61)
store i32 %62, i32* %7
%63 = load i8*, i8** %9
%64 = load i32, i32* %7
store i32 %64, i32* %2
br label %70
65: ; preds = %32
%66 = load i8*, i8** %3
store i8* %66, i8** %5
%67 = load i8*, i8** %5
%68 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @highest_version to i32 (i8*, i8*, ...)*)(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %68, i32* %7
%69 = load i32, i32* %7
store i32 %69, i32* %2
br label %70
70: ; preds = %65, %37
%71 = load i32, i32* %2
ret i32 %71
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @max_version(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = shl i64 %2, 32
%4 = ashr exact i64 %3, 32
%5 = getelementptr inbounds i8, i8* %0, i64 %4
br label %6
6: ; preds = %12, %1
%7 = phi i8* [ %5, %1 ], [ %8, %12 ]
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp ugt i8* %8, %0
%10 = load i8, i8* %8
%11 = icmp eq i8 %10, 47
br i1 %9, label %12, label %13
12: ; preds = %6
br i1 %11, label %14, label %6
13: ; preds = %6
br i1 %11, label %14, label %28
14: ; preds = %12, %13
%15 = ptrtoint i8* %8 to i64
%16 = ptrtoint i8* %0 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = add nsw i32 %18, 1
%20 = tail call i32 (i32, ...) bitcast (i32 (...)* @xmalloc to i32 (i32, ...)*)(i32 %19)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
%23 = shl i64 %17, 32
%24 = ashr exact i64 %23, 32
%25 = tail call i8* @strncpy(i8* dereferenceable(1) %22, i8* %0, i64 %24)
%26 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 0, i8* %26
%27 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @highest_version to i32 (i8*, i8*, ...)*)(i8* %7, i8* %22)
tail call void @free(i8* %22)
br label %30
28: ; preds = %13
%29 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @highest_version to i32 (i8*, i8*, ...)*)(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %14
%31 = phi i32 [ %27, %14 ], [ %29, %28 ]
ret i32 %31
}