#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 scalar_t__ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
scalar_t__ XFetchName(int /*<<< orphan*/ *, scalar_t__, char **);
int /*<<< orphan*/ XFree(char *);
int /*<<< orphan*/ XQueryTree(int /*<<< orphan*/ *, scalar_t__, scalar_t__ *,
                              scalar_t__ *, scalar_t__ **, unsigned int *);
int /*<<< orphan*/ strcmp(char *, char *);
Window Window_With_Name(Display *dpy, Window top, char *name) {
  Window *children, dummy;
  unsigned int nchildren;
  int i;
  Window w = 0;
  char *window_name;
  if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
    return (top);
  if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
    return (0);
  for (i = 0; i < nchildren; i++) {
    w = Window_With_Name(dpy, children[i], name);
    if (w)
      break;
  }
  if (children)
    XFree((char *)children);
  return (w);
}


x86 assembly (clang, -O0):
<Window_With_Name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <XFetchName@plt>
cmp    $0x0,%rax
je     11aa <Window_With_Name+0x5a>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11aa <Window_With_Name+0x5a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124b <Window_With_Name+0xfb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rcx
lea    -0x28(%rbp),%r8
lea    -0x34(%rbp),%r9
mov    %rcx,%rdx
call   1030 <XQueryTree@plt>
cmp    $0x0,%eax
jne    11dc <Window_With_Name+0x8c>
movq   $0x0,-0x8(%rbp)
jmp    124b <Window_With_Name+0xfb>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jae    122f <Window_With_Name+0xdf>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <Window_With_Name@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     121c <Window_With_Name+0xcc>
jmp    122f <Window_With_Name+0xdf>
jmp    1221 <Window_With_Name+0xd1>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11e3 <Window_With_Name+0x93>
cmpq   $0x0,-0x28(%rbp)
je     1243 <Window_With_Name+0xf3>
mov    -0x28(%rbp),%rdi
call   1040 <XFree@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Window_With_Name>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x18(%rsp),%rdx
call   1050 <XFetchName@plt>
test   %rax,%rax
je     1188 <Window_With_Name+0x38>
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1204 <Window_With_Name+0xb4>
lea    0x20(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rcx,%rdx
call   1030 <XQueryTree@plt>
test   %eax,%eax
je     11e8 <Window_With_Name+0x98>
cmpl   $0x0,0xc(%rsp)
je     11ed <Window_With_Name+0x9d>
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,8),%rsi
mov    %r12,%rdi
mov    %r15,%rdx
call   1070 <Window_With_Name@plt>
test   %rax,%rax
jne    11f2 <Window_With_Name+0xa2>
add    $0x1,%rbx
mov    0xc(%rsp),%eax
cmp    %rax,%rbx
jb     11c0 <Window_With_Name+0x70>
jmp    11f5 <Window_With_Name+0xa5>
xor    %r14d,%r14d
jmp    1204 <Window_With_Name+0xb4>
xor    %r14d,%r14d
jmp    11f5 <Window_With_Name+0xa5>
mov    %rax,%r14
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1204 <Window_With_Name+0xb4>
call   1040 <XFree@plt>
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @Window_With_Name(i32* %0, i64 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i8*
store i32* %0, i32** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 0, i64* %12
%14 = load i32*, i32** %5
%15 = load i64, i64* %6
%16 = call i64 @XFetchName(i32* %14, i64 %15, i8** %13)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %3
%19 = load i8*, i8** %13
%20 = load i8*, i8** %7
%21 = call i32 @strcmp(i8* %19, i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = load i64, i64* %6
store i64 %24, i64* %4
br label %61
25: ; preds = %18, %3
%26 = load i32*, i32** %5
%27 = load i64, i64* %6
%28 = call i32 @XQueryTree(i32* %26, i64 %27, i64* %9, i64* %9, i64** %8, i32* %10)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
store i64 0, i64* %4
br label %61
31: ; preds = %25
store i32 0, i32* %11
br label %32
32: ; preds = %49, %31
%33 = load i32, i32* %11
%34 = load i32, i32* %10
%35 = icmp ult i32 %33, %34
br i1 %35, label %36, label %52
36: ; preds = %32
%37 = load i32*, i32** %5
%38 = load i64*, i64** %8
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i64, i64* %38, i64 %40
%42 = load i64, i64* %41
%43 = load i8*, i8** %7
%44 = call i64 @Window_With_Name(i32* %37, i64 %42, i8* %43)
store i64 %44, i64* %12
%45 = load i64, i64* %12
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %36
br label %52
48: ; preds = %36
br label %49
49: ; preds = %48
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %32
52: ; preds = %47, %32
%53 = load i64*, i64** %8
%54 = icmp ne i64* %53, null
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i64*, i64** %8
%57 = bitcast i64* %56 to i8*
%58 = call i32 @XFree(i8* %57)
br label %59
59: ; preds = %55, %52
%60 = load i64, i64* %12
store i64 %60, i64* %4
br label %61
61: ; preds = %59, %30, %23
%62 = load i64, i64* %4
ret i64 %62
}

LLVM IR (-O2):
define i64 @Window_With_Name(i32* %0, i64 %1, i8* nocapture %2) {
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = bitcast i64** %4 to i8*
%9 = bitcast i64* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i8** %7 to i8*
%12 = call i64 @XFetchName(i32* %0, i64 %1, i8** %7)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(1) %2)
%17 = icmp eq i32 %16, 0
br i1 %17, label %43, label %18
18: ; preds = %14, %3
%19 = call i32 @XQueryTree(i32* %0, i64 %1, i64* %5, i64* %5, i64** %4, i32* %6)
%20 = icmp eq i32 %19, 0
br i1 %20, label %43, label %21
21: ; preds = %18
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 0
br i1 %23, label %36, label %28
24: ; preds = %28
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = icmp ult i64 %35, %26
br i1 %27, label %28, label %36
28: ; preds = %21, %24
%29 = phi i64 [ %35, %24 ], [ 0, %21 ]
%30 = load i64*, i64** %4
%31 = getelementptr inbounds i64, i64* %30, i64 %29
%32 = load i64, i64* %31
%33 = call i64 @Window_With_Name(i32* %0, i64 %32, i8* %2)
%34 = icmp eq i64 %33, 0
%35 = add nuw nsw i64 %29, 1
br i1 %34, label %24, label %36
36: ; preds = %24, %28, %21
%37 = phi i64 [ 0, %21 ], [ %33, %28 ], [ 0, %24 ]
%38 = load i64*, i64** %4
%39 = icmp eq i64* %38, null
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = bitcast i64* %38 to i8*
%42 = call i32 @XFree(i8* %41)
br label %43
43: ; preds = %36, %40, %18, %14
%44 = phi i64 [ %1, %14 ], [ 0, %18 ], [ %37, %40 ], [ %37, %36 ]
ret i64 %44
}