#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 FileString_GetExtension(char *);
scalar_t__ FileString_StrCmpNoCase(char *, char *, int);
int FileString_TrimLength(char *, int);
scalar_t__ strlen(char *);
int fatfs_compare_names(char *strA, char *strB) {
  char *ext1 = 0;
  char *ext2 = 0;
  int ext1Pos, ext2Pos;
  int file1Len, file2Len;
  ext1Pos = FileString_GetExtension(strA);
  ext2Pos = FileString_GetExtension(strB);
  if ((ext1Pos == -1) && (ext2Pos != -1))
    return 0;
  if ((ext2Pos == -1) && (ext1Pos != -1))
    return 0;
  if (ext1Pos != -1) {
    ext1 = strA + ext1Pos + 1;
    ext2 = strB + ext2Pos + 1;
    if (strlen(ext1) != strlen(ext2))
      return 0;
    if (FileString_StrCmpNoCase(ext1, ext2, (int)strlen(ext1)) != 0)
      return 0;
    file1Len = ext1Pos;
    file2Len = ext2Pos;
  } else {
    file1Len = (int)strlen(strA);
    file2Len = (int)strlen(strB);
  }
  file1Len = FileString_TrimLength(strA, file1Len);
  file2Len = FileString_TrimLength(strB, file2Len);
  if (file1Len != file2Len)
    return 0;
  if (FileString_StrCmpNoCase(strA, strB, file1Len) != 0)
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<fatfs_compare_names>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <FileString_GetExtension@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <FileString_GetExtension@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1198 <fatfs_compare_names+0x58>
cmpl   $0xffffffff,-0x30(%rbp)
je     1198 <fatfs_compare_names+0x58>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <fatfs_compare_names+0x1a4>
cmpl   $0xffffffff,-0x30(%rbp)
jne    11b8 <fatfs_compare_names+0x78>
cmpl   $0xffffffff,-0x2c(%rbp)
je     11b8 <fatfs_compare_names+0x78>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <fatfs_compare_names+0x1a4>
cmpl   $0xffffffff,-0x2c(%rbp)
je     1269 <fatfs_compare_names+0x129>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     121a <fatfs_compare_names+0xda>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <fatfs_compare_names+0x1a4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1050 <FileString_StrCmpNoCase@plt>
cmp    $0x0,%rax
je     1258 <fatfs_compare_names+0x118>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <fatfs_compare_names+0x1a4>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1281 <fatfs_compare_names+0x141>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1060 <FileString_TrimLength@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1060 <FileString_TrimLength@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     12b7 <fatfs_compare_names+0x177>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <fatfs_compare_names+0x1a4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <FileString_StrCmpNoCase@plt>
cmp    $0x0,%rax
je     12dd <fatfs_compare_names+0x19d>
movl   $0x0,-0x4(%rbp)
jmp    12e4 <fatfs_compare_names+0x1a4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fatfs_compare_names>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <FileString_GetExtension@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <FileString_GetExtension@plt>
mov    %eax,%ebp
xor    %r14d,%r14d
cmp    $0xffffffff,%ebx
jne    1176 <fatfs_compare_names+0x36>
cmp    $0xffffffff,%ebp
jne    121f <fatfs_compare_names+0xdf>
cmp    $0xffffffff,%ebp
jne    1184 <fatfs_compare_names+0x44>
cmp    $0xffffffff,%ebx
jne    121f <fatfs_compare_names+0xdf>
cmp    $0xffffffff,%ebx
je     11d8 <fatfs_compare_names+0x98>
movslq %ebx,%rax
lea    (%r12,%rax,1),%rdi
add    $0x1,%rdi
movslq %ebp,%rax
add    %r15,%rax
add    $0x1,%rax
mov    %rax,0x8(%rsp)
mov    %rdi,0x10(%rsp)
call   1040 <strlen@plt>
mov    %rax,%r13
mov    0x8(%rsp),%rdi
call   1040 <strlen@plt>
cmp    %rax,%r13
jne    121f <fatfs_compare_names+0xdf>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    %r13d,%edx
call   1050 <FileString_StrCmpNoCase@plt>
test   %rax,%rax
jne    121f <fatfs_compare_names+0xdf>
jmp    11ee <fatfs_compare_names+0xae>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <FileString_TrimLength@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
call   1060 <FileString_TrimLength@plt>
cmp    %eax,%ebx
jne    121f <fatfs_compare_names+0xdf>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <FileString_StrCmpNoCase@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fatfs_compare_names(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i8* null, i8** %7
%12 = load i8*, i8** %4
%13 = call i32 @FileString_GetExtension(i8* %12)
store i32 %13, i32* %8
%14 = load i8*, i8** %5
%15 = call i32 @FileString_GetExtension(i8* %14)
store i32 %15, i32* %9
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 0, i32* %3
br label %87
22: ; preds = %18, %2
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %3
br label %87
29: ; preds = %25, %22
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %61
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8* %37, i8** %6
%38 = load i8*, i8** %5
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8* %42, i8** %7
%43 = load i8*, i8** %6
%44 = call i64 @strlen(i8* %43)
%45 = load i8*, i8** %7
%46 = call i64 @strlen(i8* %45)
%47 = icmp ne i64 %44, %46
br i1 %47, label %48, label %49
48: ; preds = %32
store i32 0, i32* %3
br label %87
49: ; preds = %32
%50 = load i8*, i8** %6
%51 = load i8*, i8** %7
%52 = load i8*, i8** %6
%53 = call i64 @strlen(i8* %52)
%54 = trunc i64 %53 to i32
%55 = call i64 @FileString_StrCmpNoCase(i8* %50, i8* %51, i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %49
store i32 0, i32* %3
br label %87
58: ; preds = %49
%59 = load i32, i32* %8
store i32 %59, i32* %10
%60 = load i32, i32* %9
store i32 %60, i32* %11
br label %68
61: ; preds = %29
%62 = load i8*, i8** %4
%63 = call i64 @strlen(i8* %62)
%64 = trunc i64 %63 to i32
store i32 %64, i32* %10
%65 = load i8*, i8** %5
%66 = call i64 @strlen(i8* %65)
%67 = trunc i64 %66 to i32
store i32 %67, i32* %11
br label %68
68: ; preds = %61, %58
%69 = load i8*, i8** %4
%70 = load i32, i32* %10
%71 = call i32 @FileString_TrimLength(i8* %69, i32 %70)
store i32 %71, i32* %10
%72 = load i8*, i8** %5
%73 = load i32, i32* %11
%74 = call i32 @FileString_TrimLength(i8* %72, i32 %73)
store i32 %74, i32* %11
%75 = load i32, i32* %10
%76 = load i32, i32* %11
%77 = icmp ne i32 %75, %76
br i1 %77, label %78, label %79
78: ; preds = %68
store i32 0, i32* %3
br label %87
79: ; preds = %68
%80 = load i8*, i8** %4
%81 = load i8*, i8** %5
%82 = load i32, i32* %10
%83 = call i64 @FileString_StrCmpNoCase(i8* %80, i8* %81, i32 %82)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %79
store i32 0, i32* %3
br label %87
86: ; preds = %79
store i32 1, i32* %3
br label %87
87: ; preds = %86, %85, %78, %57, %48, %28, %21
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
define i32 @fatfs_compare_names(i8* %0, i8* %1) {
%3 = tail call i32 @FileString_GetExtension(i8* %0)
%4 = tail call i32 @FileString_GetExtension(i8* %1)
%5 = icmp eq i32 %3, -1
%6 = icmp ne i32 %4, -1
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %42, label %8
8: ; preds = %2
%9 = icmp eq i32 %4, -1
%10 = icmp ne i32 %3, -1
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %42, label %12
12: ; preds = %8
br i1 %10, label %13, label %27
13: ; preds = %12
%14 = sext i32 %3 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = sext i32 %4 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = tail call i64 @strlen(i8* %16)
%21 = tail call i64 @strlen(i8* %19)
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %42
23: ; preds = %13
%24 = trunc i64 %20 to i32
%25 = tail call i64 @FileString_StrCmpNoCase(i8* %16, i8* %19, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %42
27: ; preds = %12
%28 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%29 = trunc i64 %28 to i32
%30 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%31 = trunc i64 %30 to i32
br label %32
32: ; preds = %23, %27
%33 = phi i32 [ %29, %27 ], [ %3, %23 ]
%34 = phi i32 [ %31, %27 ], [ %4, %23 ]
%35 = tail call i32 @FileString_TrimLength(i8* %0, i32 %33)
%36 = tail call i32 @FileString_TrimLength(i8* %1, i32 %34)
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %32
%39 = tail call i64 @FileString_StrCmpNoCase(i8* %0, i8* %1, i32 %35)
%40 = icmp eq i64 %39, 0
%41 = zext i1 %40 to i32
br label %42
42: ; preds = %38, %32, %23, %13, %8, %2
%43 = phi i32 [ 0, %2 ], [ 0, %8 ], [ 0, %13 ], [ 0, %23 ], [ 0, %32 ], [ %41, %38 ]
ret i32 %43
}