#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
int xdg_check_file(char *, int *);
int xdg_check_dir(const char *directory, int *invalid_dir_list) {
  int invalid, exists;
  char *file_name;
  assert(directory != NULL);
  file_name = malloc(strlen(directory) + strlen("/mime/mime.cache") + 1);
  strcpy(file_name, directory);
  strcat(file_name, "/mime/mime.cache");
  invalid = xdg_check_file(file_name, &exists);
  free(file_name);
  if (invalid) {
    *invalid_dir_list = (!(0));
    return (!(0));
  } else if (exists) {
    return (0);
  }
  file_name = malloc(strlen(directory) + strlen("/mime/globs") + 1);
  strcpy(file_name, directory);
  strcat(file_name, "/mime/globs");
  invalid = xdg_check_file(file_name, NULL);
  free(file_name);
  if (invalid) {
    *invalid_dir_list = (!(0));
    return (!(0));
  }
  file_name = malloc(strlen(directory) + strlen("/mime/magic") + 1);
  strcpy(file_name, directory);
  strcat(file_name, "/mime/magic");
  invalid = xdg_check_file(file_name, NULL);
  free(file_name);
  if (invalid) {
    *invalid_dir_list = (!(0));
    return (!(0));
  }
  return (0);
}


x86 assembly (clang, -O0):
<xdg_check_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe5a(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <xdg_check_file@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1215 <xdg_check_dir+0xa5>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    133d <xdg_check_dir+0x1cd>
cmpl   $0x0,-0x20(%rbp)
je     122b <xdg_check_dir+0xbb>
movl   $0x0,-0x4(%rbp)
jmp    133d <xdg_check_dir+0x1cd>
jmp    1230 <xdg_check_dir+0xc0>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x38(%rbp)
lea    0xdcd(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xd9c(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <xdg_check_file@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12b3 <xdg_check_dir+0x143>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    133d <xdg_check_dir+0x1cd>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x40(%rbp)
lea    0xd56(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xd25(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <xdg_check_file@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1336 <xdg_check_dir+0x1c6>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    133d <xdg_check_dir+0x1cd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xdg_check_dir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1070 <assert@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0x11(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <xdg_check_file@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11e8 <xdg_check_dir+0x78>
movl   $0x1,(%r14)
mov    $0x1,%r15d
jmp    11f2 <xdg_check_dir+0x82>
xor    %r15d,%r15d
cmpl   $0x0,0xc(%rsp)
je     1202 <xdg_check_dir+0x92>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0xc(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xde9(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <xdg_check_file@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
jne    11d9 <xdg_check_dir+0x69>
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    0xc(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
lea    0xdac(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <xdg_check_file@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
jne    11d9 <xdg_check_dir+0x69>
jmp    11f2 <xdg_check_dir+0x82>

LLVM IR (-O0):
@.str = [17 x i8] c"/mime/mime.cache\00"
@.str.1 = [12 x i8] c"/mime/globs\00"
@.str.2 = [12 x i8] c"/mime/magic\00"
define i32 @xdg_check_dir(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
%15 = call i64 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%16 = add nsw i64 %14, %15
%17 = add nsw i64 %16, 1
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = load i8*, i8** %4
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %8
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%24 = load i8*, i8** %8
%25 = call i32 @xdg_check_file(i8* %24, i32* %7)
store i32 %25, i32* %6
%26 = load i8*, i8** %8
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %2
%31 = load i32*, i32** %5
store i32 1, i32* %31
store i32 1, i32* %3
br label %78
32: ; preds = %2
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 0, i32* %3
br label %78
36: ; preds = %32
br label %37
37: ; preds = %36
%38 = load i8*, i8** %4
%39 = call i64 @strlen(i8* %38)
%40 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%41 = add nsw i64 %39, %40
%42 = add nsw i64 %41, 1
%43 = call i8* @malloc(i64 %42)
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = load i8*, i8** %4
%46 = call i32 @strcpy(i8* %44, i8* %45)
%47 = load i8*, i8** %8
%48 = call i32 @strcat(i8* %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%49 = load i8*, i8** %8
%50 = call i32 @xdg_check_file(i8* %49, i32* null)
store i32 %50, i32* %6
%51 = load i8*, i8** %8
%52 = call i32 @free(i8* %51)
%53 = load i32, i32* %6
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %37
%56 = load i32*, i32** %5
store i32 1, i32* %56
store i32 1, i32* %3
br label %78
57: ; preds = %37
%58 = load i8*, i8** %4
%59 = call i64 @strlen(i8* %58)
%60 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%61 = add nsw i64 %59, %60
%62 = add nsw i64 %61, 1
%63 = call i8* @malloc(i64 %62)
store i8* %63, i8** %8
%64 = load i8*, i8** %8
%65 = load i8*, i8** %4
%66 = call i32 @strcpy(i8* %64, i8* %65)
%67 = load i8*, i8** %8
%68 = call i32 @strcat(i8* %67, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%69 = load i8*, i8** %8
%70 = call i32 @xdg_check_file(i8* %69, i32* null)
store i32 %70, i32* %6
%71 = load i8*, i8** %8
%72 = call i32 @free(i8* %71)
%73 = load i32, i32* %6
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %57
%76 = load i32*, i32** %5
store i32 1, i32* %76
store i32 1, i32* %3
br label %78
77: ; preds = %57
store i32 0, i32* %3
br label %78
78: ; preds = %77, %75, %55, %35, %30
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [17 x i8] c"/mime/mime.cache\00"
@.str.1 = [12 x i8] c"/mime/globs\00"
@.str.2 = [12 x i8] c"/mime/magic\00"
define i32 @xdg_check_dir(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = add nsw i64 %8, 17
%10 = tail call i8* @malloc(i64 %9)
%11 = tail call i32 @strcpy(i8* %10, i8* %0)
%12 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @xdg_check_file(i8* %10, i32* %3)
%14 = call i32 @free(i8* %10)
%15 = icmp eq i32 %13, 0
br i1 %15, label %16, label %37
16: ; preds = %2
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %16
%20 = call i64 @strlen(i8* dereferenceable(1) %0)
%21 = add nsw i64 %20, 12
%22 = call i8* @malloc(i64 %21)
%23 = call i32 @strcpy(i8* %22, i8* %0)
%24 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @xdg_check_file(i8* %22, i32* null)
%26 = call i32 @free(i8* %22)
%27 = icmp eq i32 %25, 0
br i1 %27, label %28, label %37
28: ; preds = %19
%29 = call i64 @strlen(i8* dereferenceable(1) %0)
%30 = add nsw i64 %29, 12
%31 = call i8* @malloc(i64 %30)
%32 = call i32 @strcpy(i8* %31, i8* %0)
%33 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @xdg_check_file(i8* %31, i32* null)
%35 = call i32 @free(i8* %31)
%36 = icmp eq i32 %34, 0
br i1 %36, label %38, label %37
37: ; preds = %28, %19, %2
store i32 1, i32* %1
br label %38
38: ; preds = %37, %28, %16
%39 = phi i32 [ 0, %16 ], [ 0, %28 ], [ 1, %37 ]
ret i32 %39
}