#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__ {
  int mods;
};
typedef TYPE_1__ XkbStateRec;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int ControlMask;
int LockMask;
int Mod1Mask;
int Mod2Mask;
int Mod3Mask;
int Mod4Mask;
int Mod5Mask;
int ShiftMask;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XkbGetState(int /*<<< orphan*/ *, int /*<<< orphan*/,
                               TYPE_1__ *);
int XkbQueryExtension(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                      int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                      int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ XkbUseCoreKbd;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  Display *dpy;
  int res;
  XkbStateRec state;
  dpy = XOpenDisplay(NULL);
  if (!dpy) {
    fputs("Can't open display\n", stderr);
    exit(1);
  }
  res = XkbQueryExtension(dpy, NULL, NULL, NULL, NULL, NULL);
  if (!res) {
    fputs("Can't init XKB\n", stderr);
    exit(1);
  }
  XkbGetState(dpy, XkbUseCoreKbd, &state);
  if (ShiftMask & state.mods)
    fputs("+Shift", stdout);
  if (LockMask & state.mods)
    fputs("+Lock", stdout);
  if (ControlMask & state.mods)
    fputs("+Control", stdout);
  if (Mod1Mask & state.mods)
    fputs("+Mod1", stdout);
  if (Mod2Mask & state.mods)
    fputs("+Mod2", stdout);
  if (Mod3Mask & state.mods)
    fputs("+Mod3", stdout);
  if (Mod4Mask & state.mods)
    fputs("+Mod4", stdout);
  if (Mod5Mask & state.mods)
    fputs("+Mod5", stdout);
  XCloseDisplay(dpy);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ad <main+0x4d>
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rsi
mov    %r9,%rdx
mov    %r9,%rcx
mov    %r9,%r8
call   1060 <XkbQueryExtension@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11f3 <main+0x93>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <XkbGetState@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
and    -0x20(%rbp),%eax
cmp    $0x0,%eax
je     1233 <main+0xd3>
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
lea    0xdf6(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
and    -0x20(%rbp),%eax
cmp    $0x0,%eax
je     125d <main+0xfd>
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
lea    0xdd3(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
and    -0x20(%rbp),%eax
cmp    $0x0,%eax
je     1287 <main+0x127>
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
lea    0xdaf(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
and    -0x20(%rbp),%eax
cmp    $0x0,%eax
je     12b1 <main+0x151>
mov    0x2cfd(%rip),%rax
mov    (%rax),%esi
lea    0xd8e(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
and    -0x20(%rbp),%eax
cmp    $0x0,%eax
je     12db <main+0x17b>
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
lea    0xd6a(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
and    -0x20(%rbp),%eax
cmp    $0x0,%eax
je     1305 <main+0x1a5>
mov    0x2ca9(%rip),%rax
mov    (%rax),%esi
lea    0xd46(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
and    -0x20(%rbp),%eax
cmp    $0x0,%eax
je     132f <main+0x1cf>
mov    0x2c7f(%rip),%rax
mov    (%rax),%esi
lea    0xd22(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%eax
and    -0x20(%rbp),%eax
cmp    $0x0,%eax
je     1359 <main+0x1f9>
mov    0x2c55(%rip),%rax
mov    (%rax),%esi
lea    0xcfe(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1080 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
test   %rax,%rax
je     12da <main+0x17a>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <XkbQueryExtension@plt>
test   %eax,%eax
je     12ec <main+0x18c>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <XkbGetState@plt>
mov    0x2e27(%rip),%rcx
mov    0x8(%rsp),%eax
test   %eax,(%rcx)
je     11d2 <main+0x72>
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1040 <fputs@plt>
mov    0x8(%rsp),%eax
mov    0x2dcf(%rip),%rcx
test   %eax,(%rcx)
je     11f6 <main+0x96>
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1040 <fputs@plt>
mov    0x8(%rsp),%eax
mov    0x2dd3(%rip),%rcx
test   %eax,(%rcx)
je     121a <main+0xba>
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
lea    0xe20(%rip),%rdi
call   1040 <fputs@plt>
mov    0x8(%rsp),%eax
mov    0x2da7(%rip),%rcx
test   %eax,(%rcx)
je     123e <main+0xde>
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
lea    0xe05(%rip),%rdi
call   1040 <fputs@plt>
mov    0x8(%rsp),%eax
mov    0x2d53(%rip),%rcx
test   %eax,(%rcx)
je     1262 <main+0x102>
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
lea    0xde7(%rip),%rdi
call   1040 <fputs@plt>
mov    0x8(%rsp),%eax
mov    0x2d57(%rip),%rcx
test   %eax,(%rcx)
je     1286 <main+0x126>
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
lea    0xdc9(%rip),%rdi
call   1040 <fputs@plt>
mov    0x8(%rsp),%eax
mov    0x2d63(%rip),%rcx
test   %eax,(%rcx)
je     12aa <main+0x14a>
mov    0x2d08(%rip),%rax
mov    (%rax),%esi
lea    0xdab(%rip),%rdi
call   1040 <fputs@plt>
mov    0x8(%rsp),%eax
mov    0x2cd7(%rip),%rcx
test   %eax,(%rcx)
je     12ca <main+0x16a>
mov    0x2ce4(%rip),%rax
mov    (%rax),%esi
lea    0xd8d(%rip),%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1080 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2ccf(%rip),%rax
mov    (%rax),%esi
lea    0xd16(%rip),%rdi
jmp    12fc <main+0x19c>
mov    0x2cbd(%rip),%rax
mov    (%rax),%esi
lea    0xd18(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@.str = [20 x i8] c"Can't open display\0A\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Can't init XKB\0A\00"
@XkbUseCoreKbd = global i32 0
@ShiftMask = global i32 0
@.str.2 = [7 x i8] c"+Shift\00"
@stdout = global i32 0
@LockMask = global i32 0
@.str.3 = [6 x i8] c"+Lock\00"
@ControlMask = global i32 0
@.str.4 = [9 x i8] c"+Control\00"
@Mod1Mask = global i32 0
@.str.5 = [6 x i8] c"+Mod1\00"
@Mod2Mask = global i32 0
@.str.6 = [6 x i8] c"+Mod2\00"
@Mod3Mask = global i32 0
@.str.7 = [6 x i8] c"+Mod3\00"
@Mod4Mask = global i32 0
@.str.8 = [6 x i8] c"+Mod4\00"
@Mod5Mask = global i32 0
@.str.9 = [6 x i8] c"+Mod5\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.TYPE_3__
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @XOpenDisplay(i32* null)
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = call i32 @XkbQueryExtension(i32* %17, i32* null, i32* null, i32* null, i32* null, i32* null)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
%26 = load i32*, i32** %6
%27 = load i32, i32* @XkbUseCoreKbd
%28 = call i32 @XkbGetState(i32* %26, i32 %27, %struct.TYPE_3__* %8)
%29 = load i32, i32* @ShiftMask
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %29, %31
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %25
%35 = load i32, i32* @stdout
%36 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %34, %25
%38 = load i32, i32* @LockMask
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%40 = load i32, i32* %39
%41 = and i32 %38, %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = load i32, i32* @stdout
%45 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %43, %37
%47 = load i32, i32* @ControlMask
%48 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%49 = load i32, i32* %48
%50 = and i32 %47, %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = load i32, i32* @stdout
%54 = call i32 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %52, %46
%56 = load i32, i32* @Mod1Mask
%57 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%58 = load i32, i32* %57
%59 = and i32 %56, %58
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %55
%62 = load i32, i32* @stdout
%63 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %61, %55
%65 = load i32, i32* @Mod2Mask
%66 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%67 = load i32, i32* %66
%68 = and i32 %65, %67
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = load i32, i32* @stdout
%72 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %70, %64
%74 = load i32, i32* @Mod3Mask
%75 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%76 = load i32, i32* %75
%77 = and i32 %74, %76
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %73
%80 = load i32, i32* @stdout
%81 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %79, %73
%83 = load i32, i32* @Mod4Mask
%84 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%85 = load i32, i32* %84
%86 = and i32 %83, %85
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %82
%89 = load i32, i32* @stdout
%90 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %89)
br label %91
91: ; preds = %88, %82
%92 = load i32, i32* @Mod5Mask
%93 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%94 = load i32, i32* %93
%95 = and i32 %92, %94
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %91
%98 = load i32, i32* @stdout
%99 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %98)
br label %100
100: ; preds = %97, %91
%101 = load i32*, i32** %6
%102 = call i32 @XCloseDisplay(i32* %101)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@.str = [20 x i8] c"Can't open display\0A\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Can't init XKB\0A\00"
@XkbUseCoreKbd = global i32 0
@ShiftMask = global i32 0
@.str.2 = [7 x i8] c"+Shift\00"
@stdout = global i32 0
@LockMask = global i32 0
@.str.3 = [6 x i8] c"+Lock\00"
@ControlMask = global i32 0
@.str.4 = [9 x i8] c"+Control\00"
@Mod1Mask = global i32 0
@.str.5 = [6 x i8] c"+Mod1\00"
@Mod2Mask = global i32 0
@.str.6 = [6 x i8] c"+Mod2\00"
@Mod3Mask = global i32 0
@.str.7 = [6 x i8] c"+Mod3\00"
@Mod4Mask = global i32 0
@.str.8 = [6 x i8] c"+Mod4\00"
@Mod5Mask = global i32 0
@.str.9 = [6 x i8] c"+Mod5\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.TYPE_3__
%4 = bitcast %struct.TYPE_3__* %3 to i8*
%5 = tail call i32* @XOpenDisplay(i32* null)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i32 @XkbQueryExtension(i32* %5, i32* null, i32* null, i32* null, i32* null, i32* null)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i32, i32* @XkbUseCoreKbd
%20 = call i32 @XkbGetState(i32* %5, i32 %19, %struct.TYPE_3__* %3)
%21 = load i32, i32* @ShiftMask
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%23 = load i32, i32* %22
%24 = and i32 %23, %21
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = load i32, i32* @stdout
%28 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %22
br label %30
30: ; preds = %26, %18
%31 = phi i32 [ %29, %26 ], [ %23, %18 ]
%32 = load i32, i32* @LockMask
%33 = and i32 %31, %32
%34 = icmp eq i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %30
%36 = load i32, i32* @stdout
%37 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %22
br label %39
39: ; preds = %35, %30
%40 = phi i32 [ %38, %35 ], [ %31, %30 ]
%41 = load i32, i32* @ControlMask
%42 = and i32 %40, %41
%43 = icmp eq i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %39
%45 = load i32, i32* @stdout
%46 = call i32 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %22
br label %48
48: ; preds = %44, %39
%49 = phi i32 [ %47, %44 ], [ %40, %39 ]
%50 = load i32, i32* @Mod1Mask
%51 = and i32 %49, %50
%52 = icmp eq i32 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %48
%54 = load i32, i32* @stdout
%55 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %22
br label %57
57: ; preds = %53, %48
%58 = phi i32 [ %56, %53 ], [ %49, %48 ]
%59 = load i32, i32* @Mod2Mask
%60 = and i32 %58, %59
%61 = icmp eq i32 %60, 0
br i1 %61, label %66, label %62
62: ; preds = %57
%63 = load i32, i32* @stdout
%64 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %63)
%65 = load i32, i32* %22
br label %66
66: ; preds = %62, %57
%67 = phi i32 [ %65, %62 ], [ %58, %57 ]
%68 = load i32, i32* @Mod3Mask
%69 = and i32 %67, %68
%70 = icmp eq i32 %69, 0
br i1 %70, label %75, label %71
71: ; preds = %66
%72 = load i32, i32* @stdout
%73 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %22
br label %75
75: ; preds = %71, %66
%76 = phi i32 [ %74, %71 ], [ %67, %66 ]
%77 = load i32, i32* @Mod4Mask
%78 = and i32 %76, %77
%79 = icmp eq i32 %78, 0
br i1 %79, label %84, label %80
80: ; preds = %75
%81 = load i32, i32* @stdout
%82 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %22
br label %84
84: ; preds = %80, %75
%85 = phi i32 [ %83, %80 ], [ %76, %75 ]
%86 = load i32, i32* @Mod5Mask
%87 = and i32 %85, %86
%88 = icmp eq i32 %87, 0
br i1 %88, label %92, label %89
89: ; preds = %84
%90 = load i32, i32* @stdout
%91 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %89, %84
%93 = call i32 @XCloseDisplay(i32* %5)
ret i32 0
}