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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ XkbGetState(int /*<<< orphan*/ *, int, TYPE_1__ *);
int XkbMajorVersion;
int XkbMinorVersion;
#define XkbOD_BadLibraryVersion 132
#define XkbOD_BadServerVersion 131
#define XkbOD_ConnectionRefused 130
#define XkbOD_NonXkbServer 129
#define XkbOD_Success 128
int /*<<< orphan*/ *XkbOpenDisplay(char *, int *, int *, int *, int *, int *);
int XkbUseCoreKbd;
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char *displayName = "";
  int eventCode;
  int errorReturn;
  int major = XkbMajorVersion;
  int minor = XkbMinorVersion;
  ;
  int reasonReturn;
  Display *_display = XkbOpenDisplay(displayName, &eventCode, &errorReturn,
                                     &major, &minor, &reasonReturn);
  bool error = false;
  switch (reasonReturn) {
  case XkbOD_BadLibraryVersion:
    do {
      if (0) {
        printf("Bad XKB library version.\n");
      }
    } while (0);
    error = true;
    break;
  case XkbOD_ConnectionRefused:
    do {
      if (0) {
        printf("Connection to X server refused.\n");
      }
    } while (0);
    error = true;
    break;
  case XkbOD_BadServerVersion:
    do {
      if (0) {
        printf("Bad X11 server version.\n");
      }
    } while (0);
    error = true;
    break;
  case XkbOD_NonXkbServer:
    do {
      if (0) {
        printf("XKB not present.\n");
      }
    } while (0);
    error = true;
    break;
  case XkbOD_Success:
    break;
  }
  if (error) {
    return EXIT_FAILURE;
  }
  int _deviceId = XkbUseCoreKbd;
  XkbStateRec xkbState;
  XkbGetState(_display, _deviceId, &xkbState);
  printf("%d\n", xkbState.group);
  return 0;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
lea    -0x24(%rbp),%r9
call   1050 <XkbOpenDisplay@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x4,%eax
ja     1210 <main+0xe0>
mov    -0x48(%rbp),%rax
lea    0xe56(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11b8 <main+0x88>
jmp    11bd <main+0x8d>
movl   $0x1,-0x34(%rbp)
jmp    1210 <main+0xe0>
jmp    11ce <main+0x9e>
jmp    11d3 <main+0xa3>
movl   $0x1,-0x34(%rbp)
jmp    1210 <main+0xe0>
jmp    11e4 <main+0xb4>
jmp    11e9 <main+0xb9>
movl   $0x1,-0x34(%rbp)
jmp    1210 <main+0xe0>
jmp    11fa <main+0xca>
jmp    11ff <main+0xcf>
movl   $0x1,-0x34(%rbp)
jmp    1210 <main+0xe0>
jmp    1210 <main+0xe0>
cmpl   $0x0,-0x34(%rbp)
je     122b <main+0xfb>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125f <main+0x12f>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%esi
lea    -0x40(%rbp),%rdx
call   1030 <XkbGetState@plt>
mov    -0x40(%rbp),%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0xead(%rip),%rdi
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
call   1050 <XkbOpenDisplay@plt>
mov    $0xffffff7f,%ecx
add    0xc(%rsp),%ecx
cmp    $0x3,%ecx
ja     118d <main+0x5d>
mov    0x2e47(%rip),%rax
mov    (%rax),%ebx
jmp    11b7 <main+0x87>
mov    0x2e54(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1030 <XkbGetState@plt>
mov    0x8(%rsp),%esi
lea    0xe52(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@.str = [1 x i8] zeroinitializer
@XkbMajorVersion = global i32 0
@XkbMinorVersion = global i32 0
@EXIT_FAILURE = global i32 0
@XkbUseCoreKbd = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.TYPE_3__
store i32 0, i32* %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
%12 = load i32, i32* @XkbMajorVersion
store i32 %12, i32* %5
%13 = load i32, i32* @XkbMinorVersion
store i32 %13, i32* %6
%14 = load i8*, i8** %2
%15 = call i32* @XkbOpenDisplay(i8* %14, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7)
store i32* %15, i32** %8
store i32 0, i32* %9
%16 = load i32, i32* %7
switch i32 %16, label %30 [
i32 132, label %17
i32 130, label %20
i32 131, label %23
i32 129, label %26
i32 128, label %29
]
17: ; preds = %0
br label %18
18: ; preds = %17
br label %19
19: ; preds = %18
store i32 1, i32* %9
br label %30
20: ; preds = %0
br label %21
21: ; preds = %20
br label %22
22: ; preds = %21
store i32 1, i32* %9
br label %30
23: ; preds = %0
br label %24
24: ; preds = %23
br label %25
25: ; preds = %24
store i32 1, i32* %9
br label %30
26: ; preds = %0
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27
store i32 1, i32* %9
br label %30
29: ; preds = %0
br label %30
30: ; preds = %0, %29, %28, %25, %22, %19
%31 = load i32, i32* %9
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* @EXIT_FAILURE
store i32 %34, i32* %1
br label %43
35: ; preds = %30
%36 = load i32, i32* @XkbUseCoreKbd
store i32 %36, i32* %10
%37 = load i32*, i32** %8
%38 = load i32, i32* %10
%39 = call i32 @XkbGetState(i32* %37, i32 %38, %struct.TYPE_3__* %11)
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %41)
store i32 0, i32* %1
br label %43
43: ; preds = %35, %33
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@.str = [1 x i8] zeroinitializer
@XkbMajorVersion = global i32 0
@XkbMinorVersion = global i32 0
@EXIT_FAILURE = global i32 0
@XkbUseCoreKbd = global i32 0
@.str.1 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_3__
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = load i32, i32* @XkbMajorVersion
store i32 %10, i32* %3
%11 = bitcast i32* %4 to i8*
%12 = load i32, i32* @XkbMinorVersion
store i32 %12, i32* %4
%13 = bitcast i32* %5 to i8*
%14 = call i32* @XkbOpenDisplay(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4, i32* %5)
%15 = load i32, i32* %5
%16 = add i32 %15, -129
%17 = icmp ult i32 %16, 4
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = load i32, i32* @EXIT_FAILURE
br label %27
20: ; preds = %0
%21 = load i32, i32* @XkbUseCoreKbd
%22 = bitcast %struct.TYPE_3__* %6 to i8*
%23 = call i32 @XkbGetState(i32* %14, i32 %21, %struct.TYPE_3__* %6)
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %20, %18
%28 = phi i32 [ %19, %18 ], [ 0, %20 ]
ret i32 %28
}