#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;
  if (!theme || !name)
    return NULL;
  for (path = XcursorLibraryPath(); 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);
  return f;
}


x86 assembly (clang, -O0):
<XcursorScanTheme>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    133e <XcursorScanTheme+0x1be>
mov    $0x0,%al
call   1070 <XcursorLibraryPath@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x49(%rbp)
je     11e9 <XcursorScanTheme+0x69>
cmpq   $0x0,-0x20(%rbp)
sete   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11f9 <XcursorScanTheme+0x79>
jmp    12cc <XcursorScanTheme+0x14c>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <_XcursorBuildThemeDir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12b5 <XcursorScanTheme+0x135>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xddc(%rip),%rsi
call   1090 <_XcursorBuildFullname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1255 <XcursorScanTheme+0xd5>
mov    -0x28(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12ac <XcursorScanTheme+0x12c>
cmpq   $0x0,-0x40(%rbp)
jne    12ac <XcursorScanTheme+0x12c>
mov    -0x30(%rbp),%rdi
lea    0xd9f(%rip),%rsi
lea    0xd8d(%rip),%rdx
call   1090 <_XcursorBuildFullname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12a7 <XcursorScanTheme+0x127>
mov    -0x28(%rbp),%rdi
call   10a0 <_XcursorThemeInherits@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    12ac <XcursorScanTheme+0x12c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12ba <XcursorScanTheme+0x13a>
mov    -0x38(%rbp),%rdi
call   1040 <_XcursorNextPath@plt>
mov    %rax,-0x38(%rbp)
jmp    11ce <XcursorScanTheme+0x4e>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x48(%rbp)
mov    %al,-0x4a(%rbp)
je     12ef <XcursorScanTheme+0x16f>
cmpq   $0x0,-0x20(%rbp)
sete   %al
mov    %al,-0x4a(%rbp)
mov    -0x4a(%rbp),%al
test   $0x1,%al
jne    12ff <XcursorScanTheme+0x17f>
jmp    1322 <XcursorScanTheme+0x1a2>
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    12d4 <XcursorScanTheme+0x154>
cmpq   $0x0,-0x40(%rbp)
je     1336 <XcursorScanTheme+0x1b6>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XcursorScanTheme>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
test   %rdi,%rdi
je     12f0 <XcursorScanTheme+0x170>
mov    %rsi,%rbp
test   %rsi,%rsi
je     12f0 <XcursorScanTheme+0x170>
mov    %rdi,%r12
xor    %r13d,%r13d
xor    %eax,%eax
call   1070 <XcursorLibraryPath@plt>
test   %rax,%rax
je     12f0 <XcursorScanTheme+0x170>
mov    %rax,%rbx
mov    %rbp,(%rsp)
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <_XcursorBuildThemeDir@plt>
test   %rax,%rax
je     1220 <XcursorScanTheme+0xa0>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xe13(%rip),%rsi
mov    (%rsp),%rdx
call   1090 <_XcursorBuildFullname@plt>
test   %rax,%rax
je     1230 <XcursorScanTheme+0xb0>
mov    %rax,%r14
mov    %rax,%rdi
lea    0xe00(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1030 <free@plt>
test   %r13,%r13
je     1238 <XcursorScanTheme+0xb8>
jmp    1280 <XcursorScanTheme+0x100>
nop
xor    %r13d,%r13d
jmp    1288 <XcursorScanTheme+0x108>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r13d,%r13d
test   %r13,%r13
jne    1280 <XcursorScanTheme+0x100>
test   %r15,%r15
jne    1280 <XcursorScanTheme+0x100>
mov    %rbp,%rdi
lea    0xdce(%rip),%rsi
lea    0xdbc(%rip),%rdx
call   1090 <_XcursorBuildFullname@plt>
test   %rax,%rax
je     1270 <XcursorScanTheme+0xf0>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <_XcursorThemeInherits@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1280 <XcursorScanTheme+0x100>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <_XcursorNextPath@plt>
test   %r13,%r13
jne    12a1 <XcursorScanTheme+0x121>
mov    %rax,%rbx
test   %rax,%rax
jne    11d0 <XcursorScanTheme+0x50>
test   %r15,%r15
je     12e3 <XcursorScanTheme+0x163>
test   %r13,%r13
mov    (%rsp),%rbp
jne    12e3 <XcursorScanTheme+0x163>
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <XcursorScanTheme@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <_XcursorNextPath@plt>
test   %rax,%rax
je     12e3 <XcursorScanTheme+0x163>
mov    %rax,%rbx
test   %r13,%r13
je     12c0 <XcursorScanTheme+0x140>
test   %r15,%r15
je     12f0 <XcursorScanTheme+0x170>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rax
add    $0x8,%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*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* null, i32** %6
store i8* null, i8** %10
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14, %2
store i32* null, i32** %3
br label %94
18: ; preds = %14
%19 = call i8* (...) @XcursorLibraryPath()
store i8* %19, i8** %9
br label %20
20: ; preds = %66, %18
%21 = load i8*, i8** %9
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br label %26
26: ; preds = %23, %20
%27 = phi i1 [ false, %20 ], [ %25, %23 ]
br i1 %27, label %28, label %69
28: ; preds = %26
%29 = load i8*, i8** %9
%30 = load i8*, i8** %4
%31 = call i8* @_XcursorBuildThemeDir(i8* %29, i8* %30)
store i8* %31, i8** %8
%32 = load i8*, i8** %8
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %65
34: ; preds = %28
%35 = load i8*, i8** %8
%36 = load i8*, i8** %5
%37 = call i8* @_XcursorBuildFullname(i8* %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %36)
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %45
40: ; preds = %34
%41 = load i8*, i8** %7
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %42, i32** %6
%43 = load i8*, i8** %7
%44 = call i32 @free(i8* %43)
br label %45
45: ; preds = %40, %34
%46 = load i32*, i32** %6
%47 = icmp ne i32* %46, null
br i1 %47, label %62, label %48
48: ; preds = %45
%49 = load i8*, i8** %10
%50 = icmp ne i8* %49, null
br i1 %50, label %62, label %51
51: ; preds = %48
%52 = load i8*, i8** %8
%53 = call i8* @_XcursorBuildFullname(i8* %52, 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* %53, i8** %7
%54 = load i8*, i8** %7
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = load i8*, i8** %7
%58 = call i8* @_XcursorThemeInherits(i8* %57)
store i8* %58, i8** %10
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
br label %61
61: ; preds = %56, %51
br label %62
62: ; preds = %61, %48, %45
%63 = load i8*, i8** %8
%64 = call i32 @free(i8* %63)
br label %65
65: ; preds = %62, %28
br label %66
66: ; preds = %65
%67 = load i8*, i8** %9
%68 = call i8* @_XcursorNextPath(i8* %67)
store i8* %68, i8** %9
br label %20
69: ; preds = %26
%70 = load i8*, i8** %10
store i8* %70, i8** %11
br label %71
71: ; preds = %83, %69
%72 = load i8*, i8** %11
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = load i32*, i32** %6
%76 = icmp eq i32* %75, null
br label %77
77: ; preds = %74, %71
%78 = phi i1 [ false, %71 ], [ %76, %74 ]
br i1 %78, label %79, label %86
79: ; preds = %77
%80 = load i8*, i8** %11
%81 = load i8*, i8** %5
%82 = call i32* @XcursorScanTheme(i8* %80, i8* %81)
store i32* %82, i32** %6
br label %83
83: ; preds = %79
%84 = load i8*, i8** %11
%85 = call i8* @_XcursorNextPath(i8* %84)
store i8* %85, i8** %11
br label %71
86: ; preds = %77
%87 = load i8*, i8** %10
%88 = icmp ne i8* %87, null
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i8*, i8** %10
%91 = call i32 @free(i8* %90)
br label %92
92: ; preds = %89, %86
%93 = load i32*, i32** %6
store i32* %93, i32** %3
br label %94
94: ; preds = %92, %17
%95 = load i32*, i32** %3
ret i32* %95
}

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 %57
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, %52, %55, %2
%58 = phi i32* [ null, %2 ], [ %53, %55 ], [ %53, %52 ], [ null, %6 ]
ret i32* %58
}