#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ map_state;
  scalar_t__ override_redirect;
};
typedef TYPE_1__ XWindowAttributes;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ CurrentTime;
scalar_t__ IsViewable;
int /*<<< orphan*/ RevertToPointerRoot;
int /*<<< orphan*/ True;
int /*<<< orphan*/ XGetWMHints(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XGetWindowAttributes(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ XLowerWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XRaiseWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XRestackWindows(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   unsigned int);
int /*<<< orphan*/ XSetInputFocus(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int /*<<< orphan*/);
void x_alt_tab(Display *dpy, Window *wins, unsigned int nwins) {
  Window *viewables[nwins], *w = 0;
  unsigned int vc = 0;
  for (w = wins; w - wins < nwins; w++) {
    XWindowAttributes attr;
    if (!XGetWMHints(dpy, *w))
      continue;
    if (!XGetWindowAttributes(dpy, *w, &attr))
      continue;
    if (attr.override_redirect)
      continue;
    if (attr.map_state != IsViewable)
      continue;
    viewables[vc++] = w;
  }
  viewables[vc] = NULL;
  wins[nwins - 1] = *viewables[vc - 2];
  wins[nwins - 2] = *viewables[vc - 1];
  XLowerWindow(dpy, *(viewables[vc - 1]));
  w = viewables[vc - 2];
  XRaiseWindow(dpy, *w);
  XSetInputFocus(dpy, *w, RevertToPointerRoot, CurrentTime);
  XRestackWindows(dpy, wins, vc);
  XSync(dpy, True);
}


x86 assembly (clang, -O0):
<x_alt_tab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
jge    126d <x_alt_tab+0xfd>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
call   1070 <XGetWMHints@plt>
cmp    $0x0,%eax
jne    11f9 <x_alt_tab+0x89>
jmp    125c <x_alt_tab+0xec>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1060 <XGetWindowAttributes@plt>
cmp    $0x0,%eax
jne    121a <x_alt_tab+0xaa>
jmp    125c <x_alt_tab+0xec>
cmpq   $0x0,-0x40(%rbp)
je     122a <x_alt_tab+0xba>
jmp    125c <x_alt_tab+0xec>
mov    -0x48(%rbp),%rax
mov    0x2d93(%rip),%rcx
cmp    (%rcx),%rax
je     1243 <x_alt_tab+0xd3>
jmp    125c <x_alt_tab+0xec>
mov    -0x50(%rbp),%rax
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
mov    %ecx,%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    11c1 <x_alt_tab+0x51>
mov    -0x50(%rbp),%rax
mov    -0x34(%rbp),%ecx
movq   $0x0,(%rax,%rcx,8)
mov    -0x34(%rbp),%ecx
sub    $0x2,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rcx
mov    (%rcx),%esi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    %edx,%edx
mov    %esi,(%rcx,%rdx,4)
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rcx
mov    (%rcx),%esi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x2,%edx
mov    %edx,%edx
mov    %esi,(%rcx,%rdx,4)
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%esi
call   1040 <XLowerWindow@plt>
mov    -0x50(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x2,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
call   1080 <XRaiseWindow@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    0x2ce7(%rip),%rax
mov    (%rax),%edx
mov    0x2cd6(%rip),%rax
mov    (%rax),%ecx
call   1090 <XSetInputFocus@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <XRestackWindows@plt>
mov    -0x8(%rbp),%rdi
mov    0x2cac(%rip),%rax
mov    (%rax),%esi
call   1030 <XSync@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x_alt_tab>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%r13d
mov    %rsp,%rcx
lea    0xf(,%r13,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rdx,-0x40(%rbp)
test   %edx,%edx
je     1225 <x_alt_tab+0xb5>
xor    %r12d,%r12d
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11d0 <x_alt_tab+0x60>
cs nopw 0x0(%rax,%rax,1)
add    $0x4,%r12
mov    %r12,%rax
sar    $0x2,%rax
cmp    %r13,%rax
jge    122b <x_alt_tab+0xbb>
mov    (%r14,%r12,1),%esi
mov    %rbx,%rdi
call   1070 <XGetWMHints@plt>
test   %eax,%eax
je     11c0 <x_alt_tab+0x50>
lea    (%r14,%r12,1),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
lea    -0x50(%rbp),%rdx
call   1060 <XGetWindowAttributes@plt>
test   %eax,%eax
je     11c0 <x_alt_tab+0x50>
cmpq   $0x0,-0x48(%rbp)
jne    11c0 <x_alt_tab+0x50>
mov    -0x50(%rbp),%rax
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <x_alt_tab+0x50>
mov    -0x30(%rbp),%rcx
mov    %ecx,%eax
add    $0x1,%ecx
mov    %rcx,-0x30(%rbp)
mov    -0x38(%rbp),%rcx
mov    %r15,(%rcx,%rax,8)
jmp    11c0 <x_alt_tab+0x50>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%r12
lea    -0x2(%r12),%eax
mov    -0x38(%rbp),%rsi
mov    (%rsi,%rax,8),%r15
mov    (%r15),%eax
mov    -0x40(%rbp),%rdx
lea    -0x1(%rdx),%ecx
mov    %eax,(%r14,%rcx,4)
lea    -0x1(%r12),%eax
mov    (%rsi,%rax,8),%rax
mov    (%rax),%ecx
add    $0xfffffffe,%edx
mov    %ecx,(%r14,%rdx,4)
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <XLowerWindow@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1080 <XRaiseWindow@plt>
mov    (%r15),%esi
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
mov    0x2d5c(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
call   1090 <XSetInputFocus@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <XRestackWindows@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <XSync@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
@IsViewable = global i64 0
@RevertToPointerRoot = global i32 0
@CurrentTime = global i32 0
@True = global i32 0
define void @x_alt_tab(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
%11 = alloca %struct.TYPE_3__
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%12 = load i32, i32* %6
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i32*, i64 %13
store i64 %13, i64* %8
store i32* null, i32** %9
store i32 0, i32* %10
%16 = load i32*, i32** %5
store i32* %16, i32** %9
br label %17
17: ; preds = %58, %3
%18 = load i32*, i32** %9
%19 = load i32*, i32** %5
%20 = ptrtoint i32* %18 to i64
%21 = ptrtoint i32* %19 to i64
%22 = sub i64 %20, %21
%23 = sdiv exact i64 %22, 4
%24 = load i32, i32* %6
%25 = zext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %27, label %61
27: ; preds = %17
%28 = load i32*, i32** %4
%29 = load i32*, i32** %9
%30 = load i32, i32* %29
%31 = call i32 @XGetWMHints(i32* %28, i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %27
br label %58
34: ; preds = %27
%35 = load i32*, i32** %4
%36 = load i32*, i32** %9
%37 = load i32, i32* %36
%38 = call i32 @XGetWindowAttributes(i32* %35, i32 %37, %struct.TYPE_3__* %11)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %34
br label %58
41: ; preds = %34
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 1
%43 = load i64, i64* %42
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
br label %58
46: ; preds = %41
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%48 = load i64, i64* %47
%49 = load i64, i64* @IsViewable
%50 = icmp ne i64 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %46
br label %58
52: ; preds = %46
%53 = load i32*, i32** %9
%54 = load i32, i32* %10
%55 = add i32 %54, 1
store i32 %55, i32* %10
%56 = zext i32 %54 to i64
%57 = getelementptr inbounds i32*, i32** %15, i64 %56
store i32* %53, i32** %57
br label %58
58: ; preds = %52, %51, %45, %40, %33
%59 = load i32*, i32** %9
%60 = getelementptr inbounds i32, i32* %59, i32 1
store i32* %60, i32** %9
br label %17
61: ; preds = %17
%62 = load i32, i32* %10
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds i32*, i32** %15, i64 %63
store i32* null, i32** %64
%65 = load i32, i32* %10
%66 = sub i32 %65, 2
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds i32*, i32** %15, i64 %67
%69 = load i32*, i32** %68
%70 = load i32, i32* %69
%71 = load i32*, i32** %5
%72 = load i32, i32* %6
%73 = sub i32 %72, 1
%74 = zext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %71, i64 %74
store i32 %70, i32* %75
%76 = load i32, i32* %10
%77 = sub i32 %76, 1
%78 = zext i32 %77 to i64
%79 = getelementptr inbounds i32*, i32** %15, i64 %78
%80 = load i32*, i32** %79
%81 = load i32, i32* %80
%82 = load i32*, i32** %5
%83 = load i32, i32* %6
%84 = sub i32 %83, 2
%85 = zext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %82, i64 %85
store i32 %81, i32* %86
%87 = load i32*, i32** %4
%88 = load i32, i32* %10
%89 = sub i32 %88, 1
%90 = zext i32 %89 to i64
%91 = getelementptr inbounds i32*, i32** %15, i64 %90
%92 = load i32*, i32** %91
%93 = load i32, i32* %92
%94 = call i32 @XLowerWindow(i32* %87, i32 %93)
%95 = load i32, i32* %10
%96 = sub i32 %95, 2
%97 = zext i32 %96 to i64
%98 = getelementptr inbounds i32*, i32** %15, i64 %97
%99 = load i32*, i32** %98
store i32* %99, i32** %9
%100 = load i32*, i32** %4
%101 = load i32*, i32** %9
%102 = load i32, i32* %101
%103 = call i32 @XRaiseWindow(i32* %100, i32 %102)
%104 = load i32*, i32** %4
%105 = load i32*, i32** %9
%106 = load i32, i32* %105
%107 = load i32, i32* @RevertToPointerRoot
%108 = load i32, i32* @CurrentTime
%109 = call i32 @XSetInputFocus(i32* %104, i32 %106, i32 %107, i32 %108)
%110 = load i32*, i32** %4
%111 = load i32*, i32** %5
%112 = load i32, i32* %10
%113 = call i32 @XRestackWindows(i32* %110, i32* %111, i32 %112)
%114 = load i32*, i32** %4
%115 = load i32, i32* @True
%116 = call i32 @XSync(i32* %114, i32 %115)
%117 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
@IsViewable = global i64 0
@RevertToPointerRoot = global i32 0
@CurrentTime = global i32 0
@True = global i32 0
define void @x_alt_tab(i32* %0, i32* %1, i32 %2) {
%4 = alloca %struct.TYPE_3__
%5 = zext i32 %2 to i64
%6 = alloca i32*, i64 %5
%7 = ptrtoint i32* %1 to i64
%8 = icmp eq i32 %2, 0
br i1 %8, label %41, label %9
9: ; preds = %3
%10 = bitcast %struct.TYPE_3__* %4 to i8*
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 0
br label %13
13: ; preds = %9, %34
%14 = phi i32 [ 0, %9 ], [ %35, %34 ]
%15 = phi i32* [ %1, %9 ], [ %36, %34 ]
%16 = load i32, i32* %15
%17 = call i32 @XGetWMHints(i32* %0, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %34, label %19
19: ; preds = %13
%20 = load i32, i32* %15
%21 = call i32 @XGetWindowAttributes(i32* %0, i32 %20, %struct.TYPE_3__* %4)
%22 = icmp ne i32 %21, 0
%23 = load i64, i64* %11
%24 = icmp eq i64 %23, 0
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %26, label %34
26: ; preds = %19
%27 = load i64, i64* %12
%28 = load i64, i64* @IsViewable
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = add i32 %14, 1
%32 = zext i32 %14 to i64
%33 = getelementptr inbounds i32*, i32** %6, i64 %32
store i32* %15, i32** %33
br label %34
34: ; preds = %26, %19, %13, %30
%35 = phi i32 [ %31, %30 ], [ %14, %13 ], [ %14, %19 ], [ %14, %26 ]
%36 = getelementptr inbounds i32, i32* %15, i64 1
%37 = ptrtoint i32* %36 to i64
%38 = sub i64 %37, %7
%39 = ashr exact i64 %38, 2
%40 = icmp slt i64 %39, %5
br i1 %40, label %13, label %41
41: ; preds = %34, %3
%42 = phi i32 [ 0, %3 ], [ %35, %34 ]
%43 = add i32 %42, -2
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i32*, i32** %6, i64 %44
%46 = load i32*, i32** %45
%47 = load i32, i32* %46
%48 = add i32 %2, -1
%49 = zext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %1, i64 %49
store i32 %47, i32* %50
%51 = add i32 %42, -1
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i32*, i32** %6, i64 %52
%54 = load i32*, i32** %53
%55 = load i32, i32* %54
%56 = add i32 %2, -2
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %1, i64 %57
store i32 %55, i32* %58
%59 = load i32, i32* %54
%60 = call i32 @XLowerWindow(i32* %0, i32 %59)
%61 = load i32, i32* %46
%62 = call i32 @XRaiseWindow(i32* %0, i32 %61)
%63 = load i32, i32* %46
%64 = load i32, i32* @RevertToPointerRoot
%65 = load i32, i32* @CurrentTime
%66 = call i32 @XSetInputFocus(i32* %0, i32 %63, i32 %64, i32 %65)
%67 = call i32 @XRestackWindows(i32* %0, i32* %1, i32 %42)
%68 = load i32, i32* @True
%69 = call i32 @XSync(i32* %0, i32 %68)
ret void
}