#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_7__ TYPE_2__;
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
typedef TYPE_2__ *XkbDescPtr;
struct TYPE_7__ {
  TYPE_1__ *ctrls;
};
struct TYPE_6__ {
  int num_groups;
};
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
scalar_t__ Success;
int XkbAllControlsMask;
int /*<<< orphan*/ XkbFreeControls(TYPE_2__ *, int, int /*<<< orphan*/);
scalar_t__ XkbGetControls(int /*<<< orphan*/ *, int, TYPE_2__ *);
int XkbIgnoreLockModsMask;
int XkbInternalModsMask;
int /*<<< orphan*/ printf(char *);
int get_gr_num(Display *dpy, XkbDescPtr kb) {
  int rv;
  if (XkbGetControls(
          dpy,
          (XkbAllControlsMask & ~(XkbInternalModsMask | XkbIgnoreLockModsMask)),
          kb) != Success)
    printf("XkbGetControls() failed\n");
  rv = kb->ctrls->num_groups;
  XkbFreeControls(
      kb, (XkbAllControlsMask & ~(XkbInternalModsMask | XkbIgnoreLockModsMask)),
      0);
  return rv;
}


x86 assembly (clang, -O0):
<get_gr_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    0x2e73(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1050 <XkbGetControls@plt>
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
je     1189 <get_gr_num+0x59>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    0x2e1e(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    %eax,%esi
xor    %edx,%edx
call   1040 <XkbFreeControls@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_gr_num>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e9f(%rip),%r15
mov    0x2e88(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    0x2e73(%rip),%r14
not    %esi
and    (%r14),%esi
mov    %rbx,%rdx
call   1050 <XkbGetControls@plt>
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%rax
je     117a <get_gr_num+0x4a>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rax
mov    0x0(%rbp),%esi
or     (%r15),%esi
mov    (%rax),%ebp
not    %esi
and    (%r14),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <XkbFreeControls@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { %struct.TYPE_6__* }
%struct.TYPE_6__ = type { i32 }
@XkbAllControlsMask = global i32 0
@XkbInternalModsMask = global i32 0
@XkbIgnoreLockModsMask = global i32 0
@Success = global i64 0
@.str = [25 x i8] c"XkbGetControls() failed\0A\00"
define i32 @get_gr_num(i32* %0, %struct.TYPE_7__* %1) {
%3 = alloca i32*
%4 = alloca %struct.TYPE_7__*
%5 = alloca i32
store i32* %0, i32** %3
store %struct.TYPE_7__* %1, %struct.TYPE_7__** %4
%6 = load i32*, i32** %3
%7 = load i32, i32* @XkbAllControlsMask
%8 = load i32, i32* @XkbInternalModsMask
%9 = load i32, i32* @XkbIgnoreLockModsMask
%10 = or i32 %8, %9
%11 = xor i32 %10, -1
%12 = and i32 %7, %11
%13 = load %struct.TYPE_7__*, %struct.TYPE_7__** %4
%14 = call i64 @XkbGetControls(i32* %6, i32 %12, %struct.TYPE_7__* %13)
%15 = load i64, i64* @Success
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = load %struct.TYPE_7__*, %struct.TYPE_7__** %4
%21 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %20, i32 0, i32 0
%22 = load %struct.TYPE_6__*, %struct.TYPE_6__** %21
%23 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %22, i32 0, i32 0
%24 = load i32, i32* %23
store i32 %24, i32* %5
%25 = load %struct.TYPE_7__*, %struct.TYPE_7__** %4
%26 = load i32, i32* @XkbAllControlsMask
%27 = load i32, i32* @XkbInternalModsMask
%28 = load i32, i32* @XkbIgnoreLockModsMask
%29 = or i32 %27, %28
%30 = xor i32 %29, -1
%31 = and i32 %26, %30
%32 = call i32 @XkbFreeControls(%struct.TYPE_7__* %25, i32 %31, i32 0)
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { %struct.TYPE_6__* }
%struct.TYPE_6__ = type { i32 }
@XkbAllControlsMask = global i32 0
@XkbInternalModsMask = global i32 0
@XkbIgnoreLockModsMask = global i32 0
@Success = global i64 0
@str = [24 x i8] c"XkbGetControls() failed\00"
define i32 @get_gr_num(i32* %0, %struct.TYPE_7__* %1) {
%3 = load i32, i32* @XkbAllControlsMask
%4 = load i32, i32* @XkbInternalModsMask
%5 = load i32, i32* @XkbIgnoreLockModsMask
%6 = or i32 %5, %4
%7 = xor i32 %6, -1
%8 = and i32 %3, %7
%9 = tail call i64 @XkbGetControls(i32* %0, i32 %8, %struct.TYPE_7__* %1)
%10 = load i64, i64* @Success
%11 = icmp eq i64 %9, %10
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %1, i64 0, i32 0
%16 = load %struct.TYPE_6__*, %struct.TYPE_6__** %15
%17 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %16, i64 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* @XkbAllControlsMask
%20 = load i32, i32* @XkbInternalModsMask
%21 = load i32, i32* @XkbIgnoreLockModsMask
%22 = or i32 %21, %20
%23 = xor i32 %22, -1
%24 = and i32 %19, %23
%25 = tail call i32 @XkbFreeControls(%struct.TYPE_7__* %1, i32 %24, i32 0)
ret i32 %18
}