#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*/ Display;

/* Variables and functions */
int /*<<< orphan*/ AnyKey;
int /*<<< orphan*/ AnyModifier;
int DefaultScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ RootWindow(int /*<<< orphan*/ *, int);
int ScreenCount(int /*<<< orphan*/ *);
int /*<<< orphan*/ XUngrabKey(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/);
void xhk_ungrab(Display *dpy) {
  int screen = DefaultScreen(dpy);
  for (screen = 0; screen < ScreenCount(dpy); screen++) {
    XUngrabKey(dpy, AnyKey, AnyModifier, RootWindow(dpy, screen));
  }
}


x86 assembly (clang, -O0):
<xhk_ungrab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <DefaultScreen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ScreenCount@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    11c6 <xhk_ungrab+0x86>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <RootWindow@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
call   1050 <XUngrabKey@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115f <xhk_ungrab+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xhk_ungrab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <DefaultScreen@plt>
mov    %r14,%rdi
call   1030 <ScreenCount@plt>
test   %eax,%eax
jle    11a0 <xhk_ungrab+0x60>
xor    %ebp,%ebp
mov    0x2e80(%rip),%r12
mov    0x2e71(%rip),%r13
nop
mov    (%r12),%ebx
mov    0x0(%r13),%r15d
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <RootWindow@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %eax,%ecx
call   1050 <XUngrabKey@plt>
add    $0x1,%ebp
mov    %r14,%rdi
call   1030 <ScreenCount@plt>
cmp    %eax,%ebp
jl     1170 <xhk_ungrab+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AnyKey = global i32 0
@AnyModifier = global i32 0
define void @xhk_ungrab(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 @DefaultScreen(i32* %4)
store i32 %5, i32* %3
store i32 0, i32* %3
br label %6
6: ; preds = %19, %1
%7 = load i32, i32* %3
%8 = load i32*, i32** %2
%9 = call i32 @ScreenCount(i32* %8)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %22
11: ; preds = %6
%12 = load i32*, i32** %2
%13 = load i32, i32* @AnyKey
%14 = load i32, i32* @AnyModifier
%15 = load i32*, i32** %2
%16 = load i32, i32* %3
%17 = call i32 @RootWindow(i32* %15, i32 %16)
%18 = call i32 @XUngrabKey(i32* %12, i32 %13, i32 %14, i32 %17)
br label %19
19: ; preds = %11
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %6
22: ; preds = %6
ret void
}

LLVM IR (-O2):
@AnyKey = global i32 0
@AnyModifier = global i32 0
define void @xhk_ungrab(i32* %0) {
%2 = tail call i32 @DefaultScreen(i32* %0)
%3 = tail call i32 @ScreenCount(i32* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1, %5
%6 = phi i32 [ %11, %5 ], [ 0, %1 ]
%7 = load i32, i32* @AnyKey
%8 = load i32, i32* @AnyModifier
%9 = tail call i32 @RootWindow(i32* %0, i32 %6)
%10 = tail call i32 @XUngrabKey(i32* %0, i32 %7, i32 %8, i32 %9)
%11 = add nuw nsw i32 %6, 1
%12 = tail call i32 @ScreenCount(i32* %0)
%13 = icmp slt i32 %11, %12
br i1 %13, label %5, label %14
14: ; preds = %5, %1
ret void
}