#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__ my_strcasestr(char const *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncasecmp(char const *, char const *, int);
int fosfat_isdirname(const char *realname, const char *searchname) {
  if ((my_strcasestr(realname, ".dir") &&
       !strncasecmp(realname, searchname, strlen(realname) - 4) &&
       strlen(searchname) == strlen(realname) - 4) ||
      (!strncasecmp(realname, searchname, strlen(realname)) &&
       strlen(searchname) == strlen(realname)))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<fosfat_isdirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <my_strcasestr@plt>
cmp    $0x0,%rax
je     11b3 <fosfat_isdirname+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
sub    $0x4,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11b3 <fosfat_isdirname+0x83>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    $0x4,%ecx
cmp    %ecx,%eax
je     1206 <fosfat_isdirname+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1212 <fosfat_isdirname+0xe2>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jne    1212 <fosfat_isdirname+0xe2>
movl   $0x1,-0x4(%rbp)
jmp    1219 <fosfat_isdirname+0xe9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fosfat_isdirname>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xebf(%rip),%rsi
call   1050 <my_strcasestr@plt>
test   %rax,%rax
je     1185 <fosfat_isdirname+0x55>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    -0x4(%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    1185 <fosfat_isdirname+0x55>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0xfffffffc,%ecx
mov    $0x1,%eax
cmp    %ecx,%ebp
je     11bd <fosfat_isdirname+0x8d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    11bb <fosfat_isdirname+0x8b>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%ebp
je     11bd <fosfat_isdirname+0x8d>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".dir\00"
define i32 @fosfat_isdirname(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = call i64 @my_strcasestr(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 4
%15 = call i32 @strncasecmp(i8* %10, i8* %11, i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %9
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 4
%23 = icmp eq i32 %19, %22
br i1 %23, label %37, label %24
24: ; preds = %17, %9, %2
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = load i8*, i8** %4
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @strncasecmp(i8* %25, i8* %26, i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %24
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = load i8*, i8** %4
%35 = call i32 @strlen(i8* %34)
%36 = icmp eq i32 %33, %35
br i1 %36, label %37, label %38
37: ; preds = %31, %17
store i32 1, i32* %3
br label %39
38: ; preds = %31, %24
store i32 0, i32* %3
br label %39
39: ; preds = %38, %37
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [5 x i8] c".dir\00"
define i32 @fosfat_isdirname(i8* %0, i8* %1) {
%3 = tail call i64 @my_strcasestr(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, -4
%8 = tail call i32 @strncasecmp(i8* %0, i8* %1, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = tail call i32 @strlen(i8* %1)
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, -4
%14 = icmp eq i32 %11, %13
br i1 %14, label %24, label %15
15: ; preds = %10, %5, %2
%16 = tail call i32 @strlen(i8* %0)
%17 = tail call i32 @strncasecmp(i8* %0, i8* %1, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i32 @strlen(i8* %1)
%21 = tail call i32 @strlen(i8* %0)
%22 = icmp eq i32 %20, %21
br i1 %22, label %24, label %23
23: ; preds = %19, %15
br label %24
24: ; preds = %10, %19, %23
%25 = phi i32 [ 0, %23 ], [ 1, %19 ], [ 1, %10 ]
ret i32 %25
}