#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char const);
int /*<<< orphan*/ usage();
bool parse_filename(char *_filename, char *_basename) {
  char substr[256];
  char *subptr;
  int i0, i1;
  char pathsep = '/';
  const char tag[] = "_autotest.h";
  subptr = strrchr(_filename, pathsep);
  if (subptr == NULL) {
    i0 = 0;
  } else {
    i0 = subptr - _filename + 1;
  }
  subptr = strrchr(_filename, tag[0]);
  if (subptr == NULL) {
    fprintf(stderr, "error: autotestgen, tag not found in \"%s\"\n", _filename);
    usage();
    exit(1);
    return false;
  } else {
    i1 = subptr - _filename;
  }
  if (i0 >= i1) {
    fprintf(stderr, "error: autotestgen, invalid path name in \"%s\"\n",
            _filename);
    usage();
    exit(1);
    return false;
  }
  if (strncmp(tag, &_filename[i1], strlen(tag)) != 0) {
    fprintf(stderr,
            "error: autotestgen, invalid tag (comparison failed) in \"%s\"\n",
            _filename);
    usage();
    exit(1);
    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    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x2f,-0x121(%rbp)
mov    0xe6f(%rip),%rax
mov    %rax,-0x12d(%rbp)
mov    0xe6a(%rip),%eax
mov    %eax,-0x125(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x121(%rbp),%esi
call   1060 <strrchr@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    11d8 <parse_filename+0x68>
movl   $0x0,-0x11c(%rbp)
jmp    11f0 <parse_filename+0x80>
mov    -0x118(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x11c(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x12d(%rbp),%esi
call   1060 <strrchr@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    123f <parse_filename+0xcf>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xde3(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x118(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x120(%rbp)
mov    -0x11c(%rbp),%eax
cmp    -0x120(%rbp),%eax
jl     128f <parse_filename+0x11f>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdbe(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x12d(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x120(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x138(%rbp)
lea    -0x12d(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x140(%rbp),%rdi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1307 <parse_filename+0x197>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd75(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1080 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    130c <parse_filename+0x19c>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x11c(%rbp),%rax
add    %rax,%rsi
mov    -0x120(%rbp),%edx
sub    -0x11c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x120(%rbp),%eax
sub    -0x11c(%rbp),%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    $0x1,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movabs $0x7365746f7475615f,%rax
74 65 73
mov    %rax,(%rsp)
movl   $0x682e74,0x8(%rsp)
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %eax,%ecx
sub    %r15d,%ecx
add    $0x1,%ecx
xor    %ebp,%ebp
test   %rax,%rax
cmovne %ecx,%ebp
mov    %r15,%rdi
mov    $0x5f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     123f <parse_filename+0xcf>
mov    %rax,%rbx
sub    %r15,%rbx
cmp    %ebx,%ebp
jge    1251 <parse_filename+0xe1>
movslq %ebx,%r12
add    %r15,%r12
mov    %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    1263 <parse_filename+0xf3>
movslq %ebp,%rax
add    %rax,%r15
sub    %ebp,%ebx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    $0x1,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
jmp    1273 <parse_filename+0x103>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
jmp    1273 <parse_filename+0x103>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1080 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@__const.parse_filename.tag = [12 x i8] c"_autotest.h\00"
@stderr = global i32 0
@.str = [43 x i8] c"error: autotestgen, tag not found in \22%s\22\0A\00"
@.str.1 = [47 x i8] c"error: autotestgen, invalid path name in \22%s\22\0A\00"
@.str.2 = [61 x i8] c"error: autotestgen, invalid tag (comparison failed) in \22%s\22\0A\00"
define i32 @parse_filename(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [12 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [12 x i8], [12 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 %17, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %0)
%20 = tail call i32 (...) @usage()
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = ptrtoint i8* %15 to i64
%24 = sub i64 %23, %10
%25 = trunc i64 %24 to i32
%26 = icmp slt i32 %14, %25
br i1 %26, label %32, label %27
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%30 = tail call i32 (...) @usage()
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %22
%33 = shl i64 %24, 32
%34 = ashr exact i64 %33, 32
%35 = getelementptr inbounds i8, i8* %0, i64 %34
%36 = call i32 @strlen(i8* %6)
%37 = call i64 @strncmp(i8* %6, i8* %35, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%42 = call i32 (...) @usage()
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %32
%45 = sext i32 %14 to i64
%46 = getelementptr inbounds i8, i8* %0, i64 %45
%47 = sub nsw i32 %25, %14
%48 = call i32 @strncpy(i8* %5, i8* %46, i32 %47)
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %49
store i8 0, i8* %50
%51 = call i32 @strncpy(i8* %1, i8* %5, i32 256)
ret i32 1
}