#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ max_keypermod;
  int /*<<< orphan*/ modifiermap;
};
typedef TYPE_1__ XModifierKeymap;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ ControlMapIndex;
int /*<<< orphan*/ Mod1MapIndex;
int /*<<< orphan*/ Mod4MapIndex;
int /*<<< orphan*/ Mod5MapIndex;
int /*<<< orphan*/ ShiftMapIndex;
int /*<<< orphan*/ XFreeModifiermap(TYPE_1__ *);
TYPE_1__ *XGetModifierMapping(int /*<<< orphan*/ *);
int /*<<< orphan*/ XQueryKeymap(int /*<<< orphan*/ *, char *);
scalar_t__ iupdrvGetDisplay();
scalar_t__ xCheckModifier(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/, char *);
void iupdrvGetKeyState(char *key) {
  char keys[32];
  Display *display = (Display *)iupdrvGetDisplay();
  XModifierKeymap *modMap = XGetModifierMapping(display);
  XQueryKeymap(display, keys);
  if (xCheckModifier(modMap->modifiermap, modMap->max_keypermod, ShiftMapIndex,
                     keys))
    key[0] = 'S';
  else
    key[0] = ' ';
  if (xCheckModifier(modMap->modifiermap, modMap->max_keypermod,
                     ControlMapIndex, keys))
    key[1] = 'C';
  else
    key[1] = ' ';
  if (xCheckModifier(modMap->modifiermap, modMap->max_keypermod, Mod1MapIndex,
                     keys) ||
      xCheckModifier(modMap->modifiermap, modMap->max_keypermod, Mod5MapIndex,
                     keys))
    key[2] = 'A';
  else
    key[2] = ' ';
  if (xCheckModifier(modMap->modifiermap, modMap->max_keypermod, Mod4MapIndex,
                     keys))
    key[3] = 'Y';
  else
    key[3] = ' ';
  key[4] = 0;
  XFreeModifiermap(modMap);
}


x86 assembly (clang, -O0):
<iupdrvGetKeyState>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <iupdrvGetDisplay@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <XGetModifierMapping@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <XQueryKeymap@plt>
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1060 <xCheckModifier@plt>
cmp    $0x0,%rax
je     11b6 <iupdrvGetKeyState+0x66>
mov    -0x8(%rbp),%rax
movb   $0x53,(%rax)
jmp    11bd <iupdrvGetKeyState+0x6d>
mov    -0x8(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1060 <xCheckModifier@plt>
cmp    $0x0,%rax
je     11f3 <iupdrvGetKeyState+0xa3>
mov    -0x8(%rbp),%rax
movb   $0x43,0x1(%rax)
jmp    11fb <iupdrvGetKeyState+0xab>
mov    -0x8(%rbp),%rax
movb   $0x20,0x1(%rax)
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1060 <xCheckModifier@plt>
cmp    $0x0,%rax
jne    124d <iupdrvGetKeyState+0xfd>
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1060 <xCheckModifier@plt>
cmp    $0x0,%rax
je     125a <iupdrvGetKeyState+0x10a>
mov    -0x8(%rbp),%rax
movb   $0x41,0x2(%rax)
jmp    1262 <iupdrvGetKeyState+0x112>
mov    -0x8(%rbp),%rax
movb   $0x20,0x2(%rax)
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    0x2d42(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
call   1060 <xCheckModifier@plt>
cmp    $0x0,%rax
je     1298 <iupdrvGetKeyState+0x148>
mov    -0x8(%rbp),%rax
movb   $0x59,0x3(%rax)
jmp    12a0 <iupdrvGetKeyState+0x150>
mov    -0x8(%rbp),%rax
movb   $0x20,0x3(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <XFreeModifiermap@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iupdrvGetKeyState>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <iupdrvGetDisplay@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <XGetModifierMapping@plt>
mov    %rax,%r12
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <XQueryKeymap@plt>
mov    (%r12),%esi
mov    0x4(%r12),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rcx
call   1060 <xCheckModifier@plt>
test   %rax,%rax
mov    $0x20,%ebx
mov    $0x53,%eax
cmove  %ebx,%eax
mov    %al,(%r14)
mov    (%r12),%esi
mov    0x4(%r12),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rcx
call   1060 <xCheckModifier@plt>
test   %rax,%rax
mov    $0x43,%eax
cmove  %ebx,%eax
mov    %al,0x1(%r14)
mov    (%r12),%esi
mov    0x4(%r12),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rcx
call   1060 <xCheckModifier@plt>
mov    $0x41,%cl
test   %rax,%rax
jne    121d <iupdrvGetKeyState+0xcd>
mov    (%r12),%esi
mov    0x4(%r12),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
call   1060 <xCheckModifier@plt>
test   %rax,%rax
mov    $0x41,%ecx
cmove  %ebx,%ecx
mov    %cl,0x2(%r14)
mov    (%r12),%esi
mov    0x4(%r12),%edi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
call   1060 <xCheckModifier@plt>
test   %rax,%rax
mov    $0x59,%eax
cmove  %ebx,%eax
mov    %al,0x3(%r14)
movb   $0x0,0x4(%r14)
mov    %r12,%rdi
call   1030 <XFreeModifiermap@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32 }
@ShiftMapIndex = global i32 0
@ControlMapIndex = global i32 0
@Mod1MapIndex = global i32 0
@Mod5MapIndex = global i32 0
@Mod4MapIndex = global i32 0
define void @iupdrvGetKeyState(i8* %0) {
%2 = alloca i8*
%3 = alloca [32 x i8]
%4 = alloca i32*
%5 = alloca %struct.TYPE_4__*
store i8* %0, i8** %2
%6 = call i64 (...) @iupdrvGetDisplay()
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = call %struct.TYPE_4__* @XGetModifierMapping(i32* %8)
store %struct.TYPE_4__* %9, %struct.TYPE_4__** %5
%10 = load i32*, i32** %4
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%12 = call i32 @XQueryKeymap(i32* %10, i8* %11)
%13 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* @ShiftMapIndex
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%21 = call i64 @xCheckModifier(i32 %15, i32 %18, i32 %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %1
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 83, i8* %25
br label %29
26: ; preds = %1
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 32, i8* %28
br label %29
29: ; preds = %26, %23
%30 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %30, i32 0, i32 1
%32 = load i32, i32* %31
%33 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = load i32, i32* @ControlMapIndex
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%38 = call i64 @xCheckModifier(i32 %32, i32 %35, i32 %36, i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = load i8*, i8** %2
%42 = getelementptr inbounds i8, i8* %41, i64 1
store i8 67, i8* %42
br label %46
43: ; preds = %29
%44 = load i8*, i8** %2
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8 32, i8* %45
br label %46
46: ; preds = %43, %40
%47 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%48 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %47, i32 0, i32 1
%49 = load i32, i32* %48
%50 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%51 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load i32, i32* @Mod1MapIndex
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%55 = call i64 @xCheckModifier(i32 %49, i32 %52, i32 %53, i8* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %68, label %57
57: ; preds = %46
%58 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %58, i32 0, i32 1
%60 = load i32, i32* %59
%61 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%62 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %61, i32 0, i32 0
%63 = load i32, i32* %62
%64 = load i32, i32* @Mod5MapIndex
%65 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%66 = call i64 @xCheckModifier(i32 %60, i32 %63, i32 %64, i8* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %57, %46
%69 = load i8*, i8** %2
%70 = getelementptr inbounds i8, i8* %69, i64 2
store i8 65, i8* %70
br label %74
71: ; preds = %57
%72 = load i8*, i8** %2
%73 = getelementptr inbounds i8, i8* %72, i64 2
store i8 32, i8* %73
br label %74
74: ; preds = %71, %68
%75 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%76 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %75, i32 0, i32 1
%77 = load i32, i32* %76
%78 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%79 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %78, i32 0, i32 0
%80 = load i32, i32* %79
%81 = load i32, i32* @Mod4MapIndex
%82 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%83 = call i64 @xCheckModifier(i32 %77, i32 %80, i32 %81, i8* %82)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %74
%86 = load i8*, i8** %2
%87 = getelementptr inbounds i8, i8* %86, i64 3
store i8 89, i8* %87
br label %91
88: ; preds = %74
%89 = load i8*, i8** %2
%90 = getelementptr inbounds i8, i8* %89, i64 3
store i8 32, i8* %90
br label %91
91: ; preds = %88, %85
%92 = load i8*, i8** %2
%93 = getelementptr inbounds i8, i8* %92, i64 4
store i8 0, i8* %93
%94 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%95 = call i32 @XFreeModifiermap(%struct.TYPE_4__* %94)
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32 }
@ShiftMapIndex = global i32 0
@ControlMapIndex = global i32 0
@Mod1MapIndex = global i32 0
@Mod5MapIndex = global i32 0
@Mod4MapIndex = global i32 0
define void @iupdrvGetKeyState(i8* nocapture writeonly %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i64 (...) @iupdrvGetDisplay()
%5 = inttoptr i64 %4 to i32*
%6 = tail call %struct.TYPE_4__* @XGetModifierMapping(i32* %5)
%7 = call i32 @XQueryKeymap(i32* %5, i8* %3)
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @ShiftMapIndex
%13 = call i64 @xCheckModifier(i32 %9, i32 %11, i32 %12, i8* %3)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8 32, i8 83
store i8 %15, i8* %0
%16 = load i32, i32* %8
%17 = load i32, i32* %10
%18 = load i32, i32* @ControlMapIndex
%19 = call i64 @xCheckModifier(i32 %16, i32 %17, i32 %18, i8* %3)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8 32, i8 67
%22 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %21, i8* %22
%23 = load i32, i32* %8
%24 = load i32, i32* %10
%25 = load i32, i32* @Mod1MapIndex
%26 = call i64 @xCheckModifier(i32 %23, i32 %24, i32 %25, i8* %3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %1
%29 = load i32, i32* %8
%30 = load i32, i32* %10
%31 = load i32, i32* @Mod5MapIndex
%32 = call i64 @xCheckModifier(i32 %29, i32 %30, i32 %31, i8* %3)
%33 = icmp eq i64 %32, 0
%34 = select i1 %33, i8 32, i8 65
br label %35
35: ; preds = %28, %1
%36 = phi i8 [ 65, %1 ], [ %34, %28 ]
%37 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %36, i8* %37
%38 = load i32, i32* %8
%39 = load i32, i32* %10
%40 = load i32, i32* @Mod4MapIndex
%41 = call i64 @xCheckModifier(i32 %38, i32 %39, i32 %40, i8* %3)
%42 = icmp eq i64 %41, 0
%43 = select i1 %42, i8 32, i8 89
%44 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %43, i8* %44
%45 = getelementptr inbounds i8, i8* %0, i64 4
store i8 0, i8* %45
%46 = call i32 @XFreeModifiermap(%struct.TYPE_4__* %6)
ret void
}