#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *XcursorLibraryPath();
char *_XcursorBuildFullname(char *, char *, char const *);
char *_XcursorBuildThemeDir(char const *, char const *);
char *_XcursorNextPath(char const *);
char *_XcursorThemeInherits(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
FILE *XcursorScanTheme(const char *theme, const char *name) {
  FILE *f = NULL;
  char *full;
  char *dir;
  const char *path;
  char *inherits = NULL;
  const char *i;
  char *xcursor_path;
  if (!theme || !name)
    return NULL;
  xcursor_path = XcursorLibraryPath();
  for (path = xcursor_path; path && f == NULL; path = _XcursorNextPath(path)) {
    dir = _XcursorBuildThemeDir(path, theme);
    if (dir) {
      full = _XcursorBuildFullname(dir, "cursors", name);
      if (full) {
        f = fopen(full, "r");
        free(full);
      }
      if (!f && !inherits) {
        full = _XcursorBuildFullname(dir, "", "index.theme");
        if (full) {
          inherits = _XcursorThemeInherits(full);
          free(full);
        }
      }
      free(dir);
    }
  }
  for (i = inherits; i && f == NULL; i = _XcursorNextPath(i))
    f = XcursorScanTheme(i, name);
  if (inherits != NULL)
    free(inherits);
  free(xcursor_path);
  return f;
}


x86 assembly (clang, -O0):
<XcursorScanTheme>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b6 <XcursorScanTheme+0x36>
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <XcursorScanTheme+0x43>
movq   $0x0,-0x8(%rbp)
jmp    134f <XcursorScanTheme+0x1cf>
mov    $0x0,%al
call   1070 <XcursorLibraryPath@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x51(%rbp)
je     11f1 <XcursorScanTheme+0x71>
cmpq   $0x0,-0x20(%rbp)
sete   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1201 <XcursorScanTheme+0x81>
jmp    12d4 <XcursorScanTheme+0x154>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <_XcursorBuildThemeDir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12bd <XcursorScanTheme+0x13d>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdd4(%rip),%rsi
call   1090 <_XcursorBuildFullname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     125d <XcursorScanTheme+0xdd>
mov    -0x28(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12b4 <XcursorScanTheme+0x134>
cmpq   $0x0,-0x40(%rbp)
jne    12b4 <XcursorScanTheme+0x134>
mov    -0x30(%rbp),%rdi
lea    0xd97(%rip),%rsi
lea    0xd85(%rip),%rdx
call   1090 <_XcursorBuildFullname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12af <XcursorScanTheme+0x12f>
mov    -0x28(%rbp),%rdi
call   10a0 <_XcursorThemeInherits@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    12b4 <XcursorScanTheme+0x134>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12c2 <XcursorScanTheme+0x142>
mov    -0x38(%rbp),%rdi
call   1040 <_XcursorNextPath@plt>
mov    %rax,-0x38(%rbp)
jmp    11d6 <XcursorScanTheme+0x56>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x48(%rbp)
mov    %al,-0x52(%rbp)
je     12f7 <XcursorScanTheme+0x177>
cmpq   $0x0,-0x20(%rbp)
sete   %al
mov    %al,-0x52(%rbp)
mov    -0x52(%rbp),%al
test   $0x1,%al
jne    1307 <XcursorScanTheme+0x187>
jmp    132a <XcursorScanTheme+0x1aa>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <XcursorScanTheme@plt>
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <_XcursorNextPath@plt>
mov    %rax,-0x48(%rbp)
jmp    12dc <XcursorScanTheme+0x15c>
cmpq   $0x0,-0x40(%rbp)
je     133e <XcursorScanTheme+0x1be>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XcursorScanTheme>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
test   %rdi,%rdi
je     12fd <XcursorScanTheme+0x17d>
mov    %rsi,%rbp
test   %rsi,%rsi
je     12fd <XcursorScanTheme+0x17d>
mov    %rdi,%r13
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <XcursorLibraryPath@plt>
test   %rax,%rax
je     12f5 <XcursorScanTheme+0x175>
mov    %rbp,0x10(%rsp)
xor    %r15d,%r15d
mov    %rax,0x8(%rsp)
mov    %rax,%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <_XcursorBuildThemeDir@plt>
test   %rax,%rax
je     1220 <XcursorScanTheme+0xa0>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xe13(%rip),%rsi
mov    0x10(%rsp),%rdx
call   1090 <_XcursorBuildFullname@plt>
test   %rax,%rax
je     1230 <XcursorScanTheme+0xb0>
mov    %rax,%r12
mov    %rax,%rdi
lea    0xdff(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     1237 <XcursorScanTheme+0xb7>
jmp    1280 <XcursorScanTheme+0x100>
xor    %ebx,%ebx
jmp    1288 <XcursorScanTheme+0x108>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebx,%ebx
test   %rbx,%rbx
jne    1280 <XcursorScanTheme+0x100>
test   %r15,%r15
jne    1280 <XcursorScanTheme+0x100>
mov    %rbp,%rdi
lea    0xdcf(%rip),%rsi
lea    0xdbd(%rip),%rdx
call   1090 <_XcursorBuildFullname@plt>
test   %rax,%rax
je     126f <XcursorScanTheme+0xef>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <_XcursorThemeInherits@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1280 <XcursorScanTheme+0x100>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <_XcursorNextPath@plt>
test   %rbx,%rbx
jne    12a1 <XcursorScanTheme+0x121>
mov    %rax,%r14
test   %rax,%rax
jne    11d0 <XcursorScanTheme+0x50>
test   %r15,%r15
mov    0x10(%rsp),%r14
je     12e3 <XcursorScanTheme+0x163>
test   %rbx,%rbx
jne    12e3 <XcursorScanTheme+0x163>
mov    %r15,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <XcursorScanTheme@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <_XcursorNextPath@plt>
test   %rax,%rax
je     12e3 <XcursorScanTheme+0x163>
mov    %rax,%rbp
test   %rbx,%rbx
je     12c0 <XcursorScanTheme+0x140>
test   %r15,%r15
je     12f0 <XcursorScanTheme+0x170>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"cursors\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [12 x i8] c"index.theme\00"
define i32* @XcursorScanTheme(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i8* null, i8** %10
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15, %2
store i32* null, i32** %3
br label %98
19: ; preds = %15
%20 = call i8* (...) @XcursorLibraryPath()
store i8* %20, i8** %12
%21 = load i8*, i8** %12
store i8* %21, i8** %9
br label %22
22: ; preds = %68, %19
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32*, i32** %6
%27 = icmp eq i32* %26, null
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ false, %22 ], [ %27, %25 ]
br i1 %29, label %30, label %71
30: ; preds = %28
%31 = load i8*, i8** %9
%32 = load i8*, i8** %4
%33 = call i8* @_XcursorBuildThemeDir(i8* %31, i8* %32)
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %67
36: ; preds = %30
%37 = load i8*, i8** %8
%38 = load i8*, i8** %5
%39 = call i8* @_XcursorBuildFullname(i8* %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %38)
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %47
42: ; preds = %36
%43 = load i8*, i8** %7
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %44, i32** %6
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
br label %47
47: ; preds = %42, %36
%48 = load i32*, i32** %6
%49 = icmp ne i32* %48, null
br i1 %49, label %64, label %50
50: ; preds = %47
%51 = load i8*, i8** %10
%52 = icmp ne i8* %51, null
br i1 %52, label %64, label %53
53: ; preds = %50
%54 = load i8*, i8** %8
%55 = call i8* @_XcursorBuildFullname(i8* %54, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i8* %55, i8** %7
%56 = load i8*, i8** %7
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %63
58: ; preds = %53
%59 = load i8*, i8** %7
%60 = call i8* @_XcursorThemeInherits(i8* %59)
store i8* %60, i8** %10
%61 = load i8*, i8** %7
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %58, %53
br label %64
64: ; preds = %63, %50, %47
%65 = load i8*, i8** %8
%66 = call i32 @free(i8* %65)
br label %67
67: ; preds = %64, %30
br label %68
68: ; preds = %67
%69 = load i8*, i8** %9
%70 = call i8* @_XcursorNextPath(i8* %69)
store i8* %70, i8** %9
br label %22
71: ; preds = %28
%72 = load i8*, i8** %10
store i8* %72, i8** %11
br label %73
73: ; preds = %85, %71
%74 = load i8*, i8** %11
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %79
76: ; preds = %73
%77 = load i32*, i32** %6
%78 = icmp eq i32* %77, null
br label %79
79: ; preds = %76, %73
%80 = phi i1 [ false, %73 ], [ %78, %76 ]
br i1 %80, label %81, label %88
81: ; preds = %79
%82 = load i8*, i8** %11
%83 = load i8*, i8** %5
%84 = call i32* @XcursorScanTheme(i8* %82, i8* %83)
store i32* %84, i32** %6
br label %85
85: ; preds = %81
%86 = load i8*, i8** %11
%87 = call i8* @_XcursorNextPath(i8* %86)
store i8* %87, i8** %11
br label %73
88: ; preds = %79
%89 = load i8*, i8** %10
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i8*, i8** %10
%93 = call i32 @free(i8* %92)
br label %94
94: ; preds = %91, %88
%95 = load i8*, i8** %12
%96 = call i32 @free(i8* %95)
%97 = load i32*, i32** %6
store i32* %97, i32** %3
br label %98
98: ; preds = %94, %18
%99 = load i32*, i32** %3
ret i32* %99
}

LLVM IR (-O2):
@.str = [8 x i8] c"cursors\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [12 x i8] c"index.theme\00"
define i32* @XcursorScanTheme(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 %60
6: ; preds = %2
%7 = tail call i8* (...) @XcursorLibraryPath()
%8 = icmp eq i8* %7, null
br i1 %8, label %57, label %13
9: ; preds = %38
%10 = icmp ne i8* %40, null
%11 = icmp eq i32* %39, null
%12 = and i1 %10, %11
br i1 %12, label %45, label %52
13: ; preds = %6, %38
%14 = phi i8* [ %40, %38 ], [ null, %6 ]
%15 = phi i8* [ %41, %38 ], [ %7, %6 ]
%16 = tail call i8* @_XcursorBuildThemeDir(i8* %15, i8* %0)
%17 = icmp eq i8* %16, null
br i1 %17, label %38, label %18
18: ; preds = %13
%19 = tail call i8* @_XcursorBuildFullname(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @free(i8* %19)
br label %24
24: ; preds = %21, %18
%25 = phi i32* [ %22, %21 ], [ null, %18 ]
%26 = icmp ne i32* %25, null
%27 = icmp ne i8* %14, null
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %35, label %29
29: ; preds = %24
%30 = tail call i8* @_XcursorBuildFullname(i8* %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i8* %30, null
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = tail call i8* @_XcursorThemeInherits(i8* %30)
%34 = tail call i32 @free(i8* %30)
br label %35
35: ; preds = %29, %32, %24
%36 = phi i8* [ %14, %24 ], [ %33, %32 ], [ null, %29 ]
%37 = tail call i32 @free(i8* %16)
br label %38
38: ; preds = %13, %35
%39 = phi i32* [ %25, %35 ], [ null, %13 ]
%40 = phi i8* [ %36, %35 ], [ %14, %13 ]
%41 = tail call i8* @_XcursorNextPath(i8* %15)
%42 = icmp ne i8* %41, null
%43 = icmp eq i32* %39, null
%44 = and i1 %43, %42
br i1 %44, label %13, label %9
45: ; preds = %9, %45
%46 = phi i8* [ %48, %45 ], [ %40, %9 ]
%47 = tail call i32* @XcursorScanTheme(i8* %46, i8* %1)
%48 = tail call i8* @_XcursorNextPath(i8* %46)
%49 = icmp ne i8* %48, null
%50 = icmp eq i32* %47, null
%51 = select i1 %49, i1 %50, i1 false
br i1 %51, label %45, label %52
52: ; preds = %45, %9
%53 = phi i32* [ %39, %9 ], [ %47, %45 ]
%54 = icmp eq i8* %40, null
br i1 %54, label %57, label %55
55: ; preds = %52
%56 = tail call i32 @free(i8* %40)
br label %57
57: ; preds = %6, %55, %52
%58 = phi i32* [ %53, %55 ], [ %53, %52 ], [ null, %6 ]
%59 = tail call i32 @free(i8* %7)
br label %60
60: ; preds = %2, %57
%61 = phi i32* [ %58, %57 ], [ null, %2 ]
ret i32* %61
}