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

/* Variables and functions */
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ True;
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XQueryTree(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ **, unsigned int *);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ x_alt_tab(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             unsigned int);
int main(int argc, char **argv) {
  Display *dpy;
  unsigned int nwins = 0;
  Window root, parent, *wins = 0;
  if ((dpy = XOpenDisplay(NULL)) == NULL)
    return 1;
  XSync(dpy, True);
  XQueryTree(dpy, DefaultRootWindow(dpy), &root, &parent, &wins, &nwins);
  if (nwins <= 1)
    return 0;
  x_alt_tab(dpy, wins, nwins);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1198 <main+0x48>
movl   $0x1,-0x4(%rbp)
jmp    1203 <main+0xb3>
mov    -0x18(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1060 <XSync@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x1c(%rbp),%r9
call   1040 <XQueryTree@plt>
cmpl   $0x1,-0x1c(%rbp)
ja     11ec <main+0x9c>
movl   $0x0,-0x4(%rbp)
jmp    1203 <main+0xb3>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <x_alt_tab@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x4(%rsp)
movq   $0x0,0x8(%rsp)
xor    %r14d,%r14d
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
test   %rax,%rax
je     11c9 <main+0x79>
mov    %rax,%rbx
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <XSync@plt>
mov    %rbx,%rdi
call   1030 <DefaultRootWindow@plt>
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <XQueryTree@plt>
mov    0x4(%rsp),%edx
cmp    $0x2,%edx
jb     11cf <main+0x7f>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <x_alt_tab@plt>
jmp    11cf <main+0x7f>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@True = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32* null, i32** %10
%11 = call i32* @XOpenDisplay(i32* null)
store i32* %11, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %30
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = load i32, i32* @True
%17 = call i32 @XSync(i32* %15, i32 %16)
%18 = load i32*, i32** %6
%19 = load i32*, i32** %6
%20 = call i32 @DefaultRootWindow(i32* %19)
%21 = call i32 @XQueryTree(i32* %18, i32 %20, i32* %8, i32* %9, i32** %10, i32* %7)
%22 = load i32, i32* %7
%23 = icmp ule i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %14
store i32 0, i32* %3
br label %30
25: ; preds = %14
%26 = load i32*, i32** %6
%27 = load i32*, i32** %10
%28 = load i32, i32* %7
%29 = call i32 @x_alt_tab(i32* %26, i32* %27, i32 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %25, %24, %13
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@True = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32** %6 to i8*
store i32* null, i32** %6
%11 = tail call i32* @XOpenDisplay(i32* null)
%12 = icmp eq i32* %11, null
br i1 %12, label %23, label %13
13: ; preds = %2
%14 = load i32, i32* @True
%15 = tail call i32 @XSync(i32* %11, i32 %14)
%16 = tail call i32 @DefaultRootWindow(i32* %11)
%17 = call i32 @XQueryTree(i32* %11, i32 %16, i32* %4, i32* %5, i32** %6, i32* %3)
%18 = load i32, i32* %3
%19 = icmp ult i32 %18, 2
br i1 %19, label %23, label %20
20: ; preds = %13
%21 = load i32*, i32** %6
%22 = call i32 @x_alt_tab(i32* %11, i32* %21, i32 %18)
br label %23
23: ; preds = %13, %2, %20
%24 = phi i32 [ 0, %20 ], [ 1, %2 ], [ 0, %13 ]
ret i32 %24
}