#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 */
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcasecmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
signed char directory_has_ifo_file(const char *dirname) {
  DIR *d;
  struct dirent *de;
  int len;
  char *buffer;
  len = strlen(dirname);
  if (dirname[len - 1] == '/')
    --len;
  buffer = malloc(len + 10);
  strncpy(buffer, dirname, len);
  strcat(buffer, "/VIDEO_TS");
  d = opendir(buffer);
  free(buffer);
  while ((de = readdir(d)) != 0) {
    if (strcasecmp(de->d_name, "VIDEO_TS.IFO") == 0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<directory_has_ifo_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11bb <directory_has_ifo_file+0x3b>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <strncpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1241 <directory_has_ifo_file+0xc1>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    123c <directory_has_ifo_file+0xbc>
movb   $0x1,-0x1(%rbp)
jmp    1245 <directory_has_ifo_file+0xc5>
jmp    1200 <directory_has_ifo_file+0x80>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<directory_has_ifo_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1070 <strlen@plt>
movslq %eax,%rbx
cmpb   $0x2f,-0x1(%r14,%rbx,1)
lea    -0x1(%rbx),%rax
cmove  %eax,%ebx
lea    0xa(%rbx),%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <strncpy@plt>
lea    0xe44(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strcat@plt>
mov    %r15,%rdi
call   1060 <opendir@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
lea    0xe2c(%rip),%r14
xchg   %ax,%ax
mov    %rbx,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1200 <directory_has_ifo_file+0x80>
mov    (%rax),%edi
mov    %r14,%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
jne    11e0 <directory_has_ifo_file+0x60>
mov    $0x1,%al
jmp    1202 <directory_has_ifo_file+0x82>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [10 x i8] c"/VIDEO_TS\00"
@.str.1 = [13 x i8] c"VIDEO_TS.IFO\00"
define signext i8 @directory_has_ifo_file(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i8*, i8** %3
%11 = load i32, i32* %6
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = load i32, i32* %6
%20 = add nsw i32 %19, -1
store i32 %20, i32* %6
br label %21
21: ; preds = %18, %1
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 10
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = call i32 @strncpy(i8* %25, i8* %26, i32 %27)
%29 = load i8*, i8** %7
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %7
%32 = call i32* @opendir(i8* %31)
store i32* %32, i32** %4
%33 = load i8*, i8** %7
%34 = call i32 @free(i8* %33)
br label %35
35: ; preds = %46, %21
%36 = load i32*, i32** %4
%37 = call %struct.dirent* @readdir(i32* %36)
store %struct.dirent* %37, %struct.dirent** %5
%38 = icmp ne %struct.dirent* %37, null
br i1 %38, label %39, label %47
39: ; preds = %35
%40 = load %struct.dirent*, %struct.dirent** %5
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @strcasecmp(i32 %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
store i8 1, i8* %2
br label %48
46: ; preds = %39
br label %35
47: ; preds = %35
store i8 0, i8* %2
br label %48
48: ; preds = %47, %45
%49 = load i8, i8* %2
ret i8 %49
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [10 x i8] c"/VIDEO_TS\00"
@.str.1 = [13 x i8] c"VIDEO_TS.IFO\00"
define signext i8 @directory_has_ifo_file(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 47
%8 = select i1 %7, i32 %3, i32 %2
%9 = add nsw i32 %8, 10
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @strncpy(i8* %10, i8* %0, i32 %8)
%12 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32* @opendir(i8* %10)
%14 = tail call i32 @free(i8* %10)
br label %15
15: ; preds = %18, %1
%16 = tail call %struct.dirent* @readdir(i32* %13)
%17 = icmp eq %struct.dirent* %16, null
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%20 = load i32, i32* %19
%21 = tail call i64 @strcasecmp(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %15
23: ; preds = %15, %18
%24 = phi i8 [ 1, %18 ], [ 0, %15 ]
ret i8 %24
}