#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 */
scalar_t__ strcmp(char *, char *);
char *strstr(char *, char *);
int FileNameMatch(char *pa, char *pb) {
  char *pa2, *pb2;
  int isPa = 0;
  if (!pa || !pb) {
    return -1;
  }
  pa2 = strstr(pa, "MB");
  if (pa2) {
    isPa = 1;
    pb2 = strstr(pb, "MA");
    if (pb2) {
      pa2 += 2;
      pb2 += 2;
    } else {
      return -1;
    }
  } else {
    pb2 = strstr(pb, "MB");
    pa2 = strstr(pa, "MA");
    if (pa2 && pb2) {
      isPa = 0;
      pa2 += 2;
      pb2 += 2;
    } else {
      return -2;
    }
  }
  if (strcmp(pa2, pb2) == 0) {
    return isPa;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<FileNameMatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114d <FileNameMatch+0x2d>
cmpq   $0x0,-0x18(%rbp)
jne    1159 <FileNameMatch+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1268 <FileNameMatch+0x148>
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11cc <FileNameMatch+0xac>
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11bb <FileNameMatch+0x9b>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    11c7 <FileNameMatch+0xa7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1268 <FileNameMatch+0x148>
jmp    123f <FileNameMatch+0x11f>
mov    -0x18(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     122e <FileNameMatch+0x10e>
cmpq   $0x0,-0x28(%rbp)
je     122e <FileNameMatch+0x10e>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    123a <FileNameMatch+0x11a>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1268 <FileNameMatch+0x148>
jmp    123f <FileNameMatch+0x11f>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1261 <FileNameMatch+0x141>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1268 <FileNameMatch+0x148>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileNameMatch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r12d
test   %rdi,%rdi
je     11ca <FileNameMatch+0xaa>
mov    %rsi,%rbp
test   %rsi,%rsi
je     11ca <FileNameMatch+0xaa>
mov    %rdi,%rbx
lea    0xeb3(%rip),%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1178 <FileNameMatch+0x58>
mov    %rax,%r14
lea    0xea2(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     11ca <FileNameMatch+0xaa>
mov    %rax,%r15
mov    $0x1,%ebx
jmp    11ae <FileNameMatch+0x8e>
lea    0xe81(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strstr@plt>
mov    %rax,%r15
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
mov    $0xfffffffe,%r12d
test   %rax,%rax
je     11ca <FileNameMatch+0xaa>
test   %r15,%r15
je     11ca <FileNameMatch+0xaa>
mov    %rax,%r14
xor    %ebx,%ebx
add    $0x2,%r15
add    $0x2,%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
neg    %rax
sbb    %r12d,%r12d
or     %ebx,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"MB\00"
@.str.1 = [3 x i8] c"MA\00"
define i32 @FileNameMatch(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11, %2
store i32 -1, i32* %3
br label %57
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i8* @strstr(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %32
20: ; preds = %15
store i32 1, i32* %8
%21 = load i8*, i8** %5
%22 = call i8* @strstr(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8* %27, i8** %6
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 2
store i8* %29, i8** %7
br label %31
30: ; preds = %20
store i32 -1, i32* %3
br label %57
31: ; preds = %25
br label %49
32: ; preds = %15
%33 = load i8*, i8** %5
%34 = call i8* @strstr(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %34, i8** %7
%35 = load i8*, i8** %4
%36 = call i8* @strstr(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %47
39: ; preds = %32
%40 = load i8*, i8** %7
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %47
42: ; preds = %39
store i32 0, i32* %8
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i64 2
store i8* %44, i8** %6
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i64 2
store i8* %46, i8** %7
br label %48
47: ; preds = %39, %32
store i32 -2, i32* %3
br label %57
48: ; preds = %42
br label %49
49: ; preds = %48, %31
%50 = load i8*, i8** %6
%51 = load i8*, i8** %7
%52 = call i64 @strcmp(i8* %50, i8* %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = load i32, i32* %8
store i32 %55, i32* %3
br label %57
56: ; preds = %49
store i32 -1, i32* %3
br label %57
57: ; preds = %56, %54, %47, %30, %14
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [3 x i8] c"MB\00"
@.str.1 = [3 x i8] c"MA\00"
define i32 @FileNameMatch(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %27
6: ; preds = %2
%7 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i8* @strstr(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %27, label %18
12: ; preds = %6
%13 = tail call i8* @strstr(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i8* %14, null
%16 = icmp ne i8* %13, null
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %27
18: ; preds = %12, %9
%19 = phi i8* [ %7, %9 ], [ %14, %12 ]
%20 = phi i8* [ %10, %9 ], [ %13, %12 ]
%21 = phi i32 [ 1, %9 ], [ 0, %12 ]
%22 = getelementptr inbounds i8, i8* %20, i64 2
%23 = getelementptr inbounds i8, i8* %19, i64 2
%24 = tail call i64 @strcmp(i8* %23, i8* %22)
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i32 %21, i32 -1
br label %27
27: ; preds = %18, %12, %9, %2
%28 = phi i32 [ -1, %2 ], [ -1, %9 ], [ -2, %12 ], [ %26, %18 ]
ret i32 %28
}