#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 */
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char const);
bool parse_filename(char *_filename, char *_basename) {
  char substr[256];
  char *subptr;
  int i0, i1;
  char pathsep = '/';
  const char tag[] = "_benchmark.h";
  subptr = strrchr(_filename, pathsep);
  if (subptr == NULL) {
    i0 = 0;
  } else {
    i0 = subptr - _filename + 1;
  }
  subptr = strrchr(_filename, tag[0]);
  if (subptr == NULL) {
    return false;
  } else {
    i1 = subptr - _filename;
  }
  if (i0 >= i1) {
    return false;
  }
  if (strncmp(tag, &_filename[i1], strlen(tag)) != 0) {
    return false;
  } else {
  }
  strncpy(substr, _filename + i0, i1 - i0);
  substr[i1 - i0] = '\0';
  strncpy(_basename, substr, 256);
  return true;
}


x86 assembly (clang, -O0):
<parse_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movb   $0x2f,-0x131(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0x13e(%rbp)
mov    0xe9a(%rip),%eax
mov    %eax,-0x136(%rbp)
mov    0xe92(%rip),%al
mov    %al,-0x132(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x131(%rbp),%esi
call   1060 <strrchr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11b4 <parse_filename+0x74>
movl   $0x0,-0x12c(%rbp)
jmp    11cc <parse_filename+0x8c>
mov    -0x128(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x12c(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x13e(%rbp),%esi
call   1060 <strrchr@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11fd <parse_filename+0xbd>
movl   $0x0,-0x4(%rbp)
jmp    12e6 <parse_filename+0x1a6>
mov    -0x128(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x130(%rbp)
mov    -0x12c(%rbp),%eax
cmp    -0x130(%rbp),%eax
jl     122f <parse_filename+0xef>
movl   $0x0,-0x4(%rbp)
jmp    12e6 <parse_filename+0x1a6>
lea    -0x13e(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x130(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x148(%rbp)
lea    -0x13e(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x150(%rbp),%rdi
mov    -0x148(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1289 <parse_filename+0x149>
movl   $0x0,-0x4(%rbp)
jmp    12e6 <parse_filename+0x1a6>
jmp    128e <parse_filename+0x14e>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x12c(%rbp),%rax
add    %rax,%rsi
mov    -0x130(%rbp),%edx
sub    -0x12c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x130(%rbp),%eax
sub    -0x12c(%rbp),%eax
cltq
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%r12
mov    %rdi,%rbx
movabs $0x682e6b72616d68,%rax
mov    %rax,0x15(%rsp)
movabs $0x616d68636e65625f,%rax
68 6d 61
mov    %rax,0x10(%rsp)
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %eax,%r14d
sub    %ebx,%r14d
add    $0x1,%r14d
xor    %r15d,%r15d
test   %rax,%rax
cmove  %r15d,%r14d
mov    %rbx,%rdi
mov    $0x5f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     1215 <parse_filename+0xd5>
mov    %rax,%rbp
sub    %rbx,%rbp
cmp    %ebp,%r14d
jge    1215 <parse_filename+0xd5>
mov    %r12,0x8(%rsp)
movslq %ebp,%r12
add    %rbx,%r12
lea    0x10(%rsp),%r13
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1215 <parse_filename+0xd5>
movslq %r14d,%rax
add    %rax,%rbx
sub    %r14d,%ebp
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,0x20(%rsp,%rax,1)
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.parse_filename.tag = [13 x i8] c"_benchmark.h\00"
define i32 @parse_filename(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [13 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%8 = icmp eq i8* %7, null
%9 = ptrtoint i8* %7 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = add i32 %12, 1
%14 = select i1 %8, i32 0, i32 %13
%15 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 95)
%16 = icmp eq i8* %15, null
br i1 %16, label %37, label %17
17: ; preds = %2
%18 = ptrtoint i8* %15 to i64
%19 = sub i64 %18, %10
%20 = trunc i64 %19 to i32
%21 = icmp slt i32 %14, %20
br i1 %21, label %22, label %37
22: ; preds = %17
%23 = shl i64 %19, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = call i32 @strlen(i8* %6)
%27 = call i64 @strncmp(i8* %6, i8* %25, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %22
%30 = sext i32 %14 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
%32 = sub nsw i32 %20, %14
%33 = call i32 @strncpy(i8* %5, i8* %31, i32 %32)
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %34
store i8 0, i8* %35
%36 = call i32 @strncpy(i8* %1, i8* %5, i32 256)
br label %37
37: ; preds = %22, %17, %2, %29
%38 = phi i32 [ 1, %29 ], [ 0, %2 ], [ 0, %17 ], [ 0, %22 ]
ret i32 %38
}