#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 */
size_t strlen(char const *);
scalar_t__ validate_name(char const *);
const char *validate_app_name(const char *name) {
  size_t len = strlen(name);
  const char *p = name + len - 1;
  while (p >= name) {
    if (*p == '/')
      break;
    p--;
  }
  p++;
  if (validate_name(p))
    return p;
  else
    return NULL;
}


x86 assembly (clang, -O0):
<validate_app_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     117d <validate_app_name+0x5d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    116c <validate_app_name+0x4c>
jmp    117d <validate_app_name+0x5d>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1149 <validate_app_name+0x29>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <validate_name@plt>
cmp    $0x0,%rax
je     11a9 <validate_app_name+0x89>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <validate_app_name+0x91>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_app_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
add    %r14,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rbx
cmp    %r14,%rax
jb     1151 <validate_app_name+0x31>
lea    -0x1(%rbx),%rax
cmpb   $0x2f,(%rbx)
jne    1140 <validate_app_name+0x20>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <validate_name@plt>
test   %rax,%rax
cmovne %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @validate_app_name(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = getelementptr inbounds i8, i8* %0, i64 %2
br label %4
4: ; preds = %8, %1
%5 = phi i8* [ %3, %1 ], [ %6, %8 ]
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = icmp ult i8* %6, %0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 47
br i1 %10, label %11, label %4
11: ; preds = %8, %4
%12 = tail call i64 @validate_name(i8* %5)
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* null, i8* %5
ret i8* %14
}