#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 *);
int /*<<< orphan*/ printf(char *, char const *, char const *);
scalar_t__ strcmp(char const *, char const *);
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)) {
    if (strcmp(i, theme) != 0)
      f = XcursorScanTheme(i, name);
    else
      printf(
          "Not calling XcursorScanTheme because of circular dependency: %s. %s",
          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     11d6 <XcursorScanTheme+0x36>
cmpq   $0x0,-0x18(%rbp)
jne    11e3 <XcursorScanTheme+0x43>
movq   $0x0,-0x8(%rbp)
jmp    1393 <XcursorScanTheme+0x1f3>
mov    $0x0,%al
call   1090 <XcursorLibraryPath@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x38(%rbp)
mov    %al,-0x49(%rbp)
je     1209 <XcursorScanTheme+0x69>
cmpq   $0x0,-0x20(%rbp)
sete   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1219 <XcursorScanTheme+0x79>
jmp    12ec <XcursorScanTheme+0x14c>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <_XcursorBuildThemeDir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12d5 <XcursorScanTheme+0x135>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdbc(%rip),%rsi
call   10b0 <_XcursorBuildFullname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1275 <XcursorScanTheme+0xd5>
mov    -0x28(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12cc <XcursorScanTheme+0x12c>
cmpq   $0x0,-0x40(%rbp)
jne    12cc <XcursorScanTheme+0x12c>
mov    -0x30(%rbp),%rdi
lea    0xd7f(%rip),%rsi
lea    0xd6d(%rip),%rdx
call   10b0 <_XcursorBuildFullname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12c7 <XcursorScanTheme+0x127>
mov    -0x28(%rbp),%rdi
call   10c0 <_XcursorThemeInherits@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    12cc <XcursorScanTheme+0x12c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12da <XcursorScanTheme+0x13a>
mov    -0x38(%rbp),%rdi
call   1040 <_XcursorNextPath@plt>
mov    %rax,-0x38(%rbp)
jmp    11ee <XcursorScanTheme+0x4e>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x48(%rbp)
mov    %al,-0x4a(%rbp)
je     130f <XcursorScanTheme+0x16f>
cmpq   $0x0,-0x20(%rbp)
sete   %al
mov    %al,-0x4a(%rbp)
mov    -0x4a(%rbp),%al
test   $0x1,%al
jne    131f <XcursorScanTheme+0x17f>
jmp    1377 <XcursorScanTheme+0x1d7>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     134c <XcursorScanTheme+0x1ac>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <XcursorScanTheme@plt>
mov    %rax,-0x20(%rbp)
jmp    1360 <XcursorScanTheme+0x1c0>
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xcbb(%rip),%rdi
call   1050 <printf@plt>
jmp    1365 <XcursorScanTheme+0x1c5>
mov    -0x48(%rbp),%rdi
call   1040 <_XcursorNextPath@plt>
mov    %rax,-0x48(%rbp)
jmp    12f4 <XcursorScanTheme+0x154>
cmpq   $0x0,-0x40(%rbp)
je     138b <XcursorScanTheme+0x1eb>
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     1334 <XcursorScanTheme+0x194>
mov    %rsi,%r14
test   %rsi,%rsi
je     1334 <XcursorScanTheme+0x194>
mov    %rdi,%r12
xor    %r13d,%r13d
xor    %eax,%eax
call   1090 <XcursorLibraryPath@plt>
test   %rax,%rax
je     1334 <XcursorScanTheme+0x194>
mov    %rax,%rbx
xor    %eax,%eax
mov    %rax,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <_XcursorBuildThemeDir@plt>
test   %rax,%rax
je     1240 <XcursorScanTheme+0xa0>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xdf3(%rip),%rsi
mov    %r14,%rdx
call   10b0 <_XcursorBuildFullname@plt>
test   %rax,%rax
je     1250 <XcursorScanTheme+0xb0>
mov    %rax,%r15
mov    %rax,%rdi
lea    0xde1(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1030 <free@plt>
test   %r13,%r13
je     1258 <XcursorScanTheme+0xb8>
jmp    12a0 <XcursorScanTheme+0x100>
xchg   %ax,%ax
xor    %r13d,%r13d
jmp    12a8 <XcursorScanTheme+0x108>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r13d,%r13d
test   %r13,%r13
jne    12a0 <XcursorScanTheme+0x100>
cmpq   $0x0,(%rsp)
jne    12a0 <XcursorScanTheme+0x100>
mov    %rbp,%rdi
lea    0xdac(%rip),%rsi
lea    0xd9a(%rip),%rdx
call   10b0 <_XcursorBuildFullname@plt>
test   %rax,%rax
je     1293 <XcursorScanTheme+0xf3>
mov    %rax,%r15
mov    %rax,%rdi
call   10c0 <_XcursorThemeInherits@plt>
mov    %rax,(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
jmp    12a0 <XcursorScanTheme+0x100>
xor    %eax,%eax
mov    %rax,(%rsp)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <_XcursorNextPath@plt>
test   %r13,%r13
jne    12c1 <XcursorScanTheme+0x121>
mov    %rax,%rbx
test   %rax,%rax
jne    11f0 <XcursorScanTheme+0x50>
cmpq   $0x0,(%rsp)
je     1326 <XcursorScanTheme+0x186>
test   %r13,%r13
jne    1326 <XcursorScanTheme+0x186>
lea    0xd42(%rip),%rbx
mov    (%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1300 <XcursorScanTheme+0x160>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <XcursorScanTheme@plt>
mov    %rax,%r13
jmp    1311 <XcursorScanTheme+0x171>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
xor    %r13d,%r13d
mov    %rbp,%rdi
call   1040 <_XcursorNextPath@plt>
test   %rax,%rax
je     1326 <XcursorScanTheme+0x186>
mov    %rax,%rbp
test   %r13,%r13
je     12e0 <XcursorScanTheme+0x140>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1334 <XcursorScanTheme+0x194>
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"
@.str.4 = [68 x i8] c"Not calling XcursorScanTheme because of circular dependency: %s. %s\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 %104
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 = %93, %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 %96
79: ; preds = %77
%80 = load i8*, i8** %11
%81 = load i8*, i8** %4
%82 = call i64 @strcmp(i8* %80, i8* %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %79
%85 = load i8*, i8** %11
%86 = load i8*, i8** %5
%87 = call i32* @XcursorScanTheme(i8* %85, i8* %86)
store i32* %87, i32** %6
br label %92
88: ; preds = %79
%89 = load i8*, i8** %11
%90 = load i8*, i8** %5
%91 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i8* %89, i8* %90)
br label %92
92: ; preds = %88, %84
br label %93
93: ; preds = %92
%94 = load i8*, i8** %11
%95 = call i8* @_XcursorNextPath(i8* %94)
store i8* %95, i8** %11
br label %71
96: ; preds = %77
%97 = load i8*, i8** %10
%98 = icmp ne i8* %97, null
br i1 %98, label %99, label %102
99: ; preds = %96
%100 = load i8*, i8** %10
%101 = call i32 @free(i8* %100)
br label %102
102: ; preds = %99, %96
%103 = load i32*, i32** %6
store i32* %103, i32** %3
br label %104
104: ; preds = %102, %17
%105 = load i32*, i32** %3
ret i32* %105
}

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"
@.str.4 = [68 x i8] c"Not calling XcursorScanTheme because of circular dependency: %s. %s\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 %64
6: ; preds = %2
%7 = tail call i8* (...) @XcursorLibraryPath()
%8 = icmp eq i8* %7, null
br i1 %8, label %64, 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 %59
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, %53
%46 = phi i8* [ %55, %53 ], [ %40, %9 ]
%47 = tail call i64 @strcmp(i8* %46, i8* %0)
%48 = icmp eq i64 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %45
%50 = tail call i32* @XcursorScanTheme(i8* %46, i8* %1)
br label %53
51: ; preds = %45
%52 = tail call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i8* %46, i8* %1)
br label %53
53: ; preds = %49, %51
%54 = phi i32* [ %50, %49 ], [ null, %51 ]
%55 = tail call i8* @_XcursorNextPath(i8* %46)
%56 = icmp ne i8* %55, null
%57 = icmp eq i32* %54, null
%58 = select i1 %56, i1 %57, i1 false
br i1 %58, label %45, label %59
59: ; preds = %53, %9
%60 = phi i32* [ %39, %9 ], [ %54, %53 ]
%61 = icmp eq i8* %40, null
br i1 %61, label %64, label %62
62: ; preds = %59
%63 = tail call i32 @free(i8* %40)
br label %64
64: ; preds = %6, %59, %62, %2
%65 = phi i32* [ null, %2 ], [ %60, %62 ], [ %60, %59 ], [ null, %6 ]
ret i32* %65
}