#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 *GuessSubDir(char *, char *);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
char *strrchr(char *, char);
char *VerifyFileRange(char *path, char *last_file) {
  char *p, *q, *r;
  r = strdup(path);
  p = strrchr(r, '/');
  while (p) {
    *p = '\0';
    q = GuessSubDir(r, last_file);
    if (q) {
      free(r);
      return q;
    }
    p = strrchr(r, '/');
  }
  free(r);
  return last_file;
}


x86 assembly (clang, -O0):
<VerifyFileRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ca <VerifyFileRange+0x8a>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <GuessSubDir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11b3 <VerifyFileRange+0x73>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11db <VerifyFileRange+0x9b>
mov    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
jmp    116f <VerifyFileRange+0x2f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VerifyFileRange>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     118a <VerifyFileRange+0x4a>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <GuessSubDir@plt>
test   %rax,%rax
jne    1187 <VerifyFileRange+0x47>
mov    %rbx,%rdi
jmp    1160 <VerifyFileRange+0x20>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @VerifyFileRange(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = call i8* @strrchr(i8* %11, i8 signext 47)
store i8* %12, i8** %6
br label %13
13: ; preds = %27, %2
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i8*, i8** %6
store i8 0, i8* %17
%18 = load i8*, i8** %8
%19 = load i8*, i8** %5
%20 = call i8* @GuessSubDir(i8* %18, i8* %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i8*, i8** %8
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %7
store i8* %26, i8** %3
br label %34
27: ; preds = %16
%28 = load i8*, i8** %8
%29 = call i8* @strrchr(i8* %28, i8 signext 47)
store i8* %29, i8** %6
br label %13
30: ; preds = %13
%31 = load i8*, i8** %8
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %5
store i8* %33, i8** %3
br label %34
34: ; preds = %30, %23
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
define i8* @VerifyFileRange(i8* nocapture %0, i8* %1) {
%3 = tail call i8* @strdup(i8* %0)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %2, %10
%7 = phi i8* [ %11, %10 ], [ %4, %2 ]
store i8 0, i8* %7
%8 = tail call i8* @GuessSubDir(i8* %3, i8* %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 47)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %6
13: ; preds = %10, %6, %2
%14 = phi i8* [ %1, %2 ], [ %8, %6 ], [ %1, %10 ]
%15 = tail call i32 @free(i8* %3)
ret i8* %14
}