#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__ *names;
};
struct TYPE_6__ {
  scalar_t__ *groups;
};
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
scalar_t__ Success;
char *XGetAtomName(int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ XkbFreeNames(TYPE_2__ *, int /*<<< orphan*/,
                                int /*<<< orphan*/);
scalar_t__ XkbGetNames(int /*<<< orphan*/ *, int /*<<< orphan*/, TYPE_2__ *);
int /*<<< orphan*/ XkbGroupNamesMask;
int /*<<< orphan*/ eprint(char *);
int /*<<< orphan*/ snprintf(char *, int, char *);
void get_gr_names(Display *dpy, XkbDescPtr kb, int ngroups, char **groups) {
  char *name = NULL;
  int i;
  if (XkbGetNames(dpy, XkbGroupNamesMask, kb) != Success)
    eprint("skb: XkbGetNames() failed");
  for (i = 0; i < ngroups; i++) {
    if (kb->names->groups[i]) {
      if ((name = XGetAtomName(dpy, kb->names->groups[i])))
        snprintf(groups[i], 3 + 1, name);
      else
        eprint("skb: XGetAtomName() failed\n");
    }
  }
  XkbFreeNames(kb, XkbGroupNamesMask, 0);
}


x86 assembly (clang, -O0):
<get_gr_names>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1060 <XkbGetNames@plt>
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
je     11a1 <get_gr_names+0x51>
lea    0xe64(%rip),%rdi
call   1070 <eprint@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1239 <get_gr_names+0xe9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1226 <get_gr_names+0xd6>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <XGetAtomName@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1215 <get_gr_names+0xc5>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x4,%esi
call   1030 <snprintf@plt>
jmp    1221 <get_gr_names+0xd1>
lea    0xdfe(%rip),%rdi
call   1070 <eprint@plt>
jmp    1226 <get_gr_names+0xd6>
jmp    122b <get_gr_names+0xdb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a8 <get_gr_names+0x58>
mov    -0x10(%rbp),%rdi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <XkbFreeNames@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_gr_names>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1060 <XkbGetNames@plt>
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
je     118f <get_gr_names+0x3f>
lea    0xe76(%rip),%rdi
call   1070 <eprint@plt>
test   %ebp,%ebp
jle    11f0 <get_gr_names+0xa0>
mov    %ebp,%ebp
xor    %r13d,%r13d
lea    0xe7b(%rip),%r12
jmp    11c1 <get_gr_names+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <eprint@plt>
add    $0x1,%r13
cmp    %r13,%rbp
je     11f0 <get_gr_names+0xa0>
mov    (%rbx),%rax
mov    (%rax),%rax
mov    (%rax,%r13,8),%rsi
test   %rsi,%rsi
je     11b8 <get_gr_names+0x68>
mov    %r15,%rdi
call   1050 <XGetAtomName@plt>
test   %rax,%rax
je     11b0 <get_gr_names+0x60>
mov    (%r14,%r13,8),%rdi
mov    $0x4,%esi
mov    %rax,%rdx
call   1030 <snprintf@plt>
jmp    11b8 <get_gr_names+0x68>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <XkbFreeNames@plt>

LLVM IR (-O0):
%struct.TYPE_7__ = type { %struct.TYPE_6__* }
%struct.TYPE_6__ = type { i64* }
@XkbGroupNamesMask = global i32 0
@Success = global i64 0
@.str = [26 x i8] c"skb: XkbGetNames() failed\00"
@.str.1 = [28 x i8] c"skb: XGetAtomName() failed\0A\00"
define void @get_gr_names(i32* %0, %struct.TYPE_7__* %1, i32 %2, i8** %3) {
%5 = alloca i32*
%6 = alloca %struct.TYPE_7__*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %5
store %struct.TYPE_7__* %1, %struct.TYPE_7__** %6
store i32 %2, i32* %7
store i8** %3, i8*** %8
store i8* null, i8** %9
%11 = load i32*, i32** %5
%12 = load i32, i32* @XkbGroupNamesMask
%13 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%14 = call i64 @XkbGetNames(i32* %11, 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 = %4
%18 = call i32 @eprint(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %4
store i32 0, i32* %10
br label %20
20: ; preds = %60, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %63
24: ; preds = %20
%25 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%26 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %25, i32 0, i32 0
%27 = load %struct.TYPE_6__*, %struct.TYPE_6__** %26
%28 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %27, i32 0, i32 0
%29 = load i64*, i64** %28
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i64, i64* %29, i64 %31
%33 = load i64, i64* %32
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %59
35: ; preds = %24
%36 = load i32*, i32** %5
%37 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%38 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %37, i32 0, i32 0
%39 = load %struct.TYPE_6__*, %struct.TYPE_6__** %38
%40 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %39, i32 0, i32 0
%41 = load i64*, i64** %40
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i64, i64* %41, i64 %43
%45 = load i64, i64* %44
%46 = call i8* @XGetAtomName(i32* %36, i64 %45)
store i8* %46, i8** %9
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %56
48: ; preds = %35
%49 = load i8**, i8*** %8
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = load i8*, i8** %9
%55 = call i32 @snprintf(i8* %53, i32 4, i8* %54)
br label %58
56: ; preds = %35
%57 = call i32 @eprint(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %58
58: ; preds = %56, %48
br label %59
59: ; preds = %58, %24
br label %60
60: ; preds = %59
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 1
store i32 %62, i32* %10
br label %20
63: ; preds = %20
%64 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%65 = load i32, i32* @XkbGroupNamesMask
%66 = call i32 @XkbFreeNames(%struct.TYPE_7__* %64, i32 %65, i32 0)
ret void
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { %struct.TYPE_6__* }
%struct.TYPE_6__ = type { i64* }
@XkbGroupNamesMask = global i32 0
@Success = global i64 0
@.str = [26 x i8] c"skb: XkbGetNames() failed\00"
@.str.1 = [28 x i8] c"skb: XGetAtomName() failed\0A\00"
define void @get_gr_names(i32* %0, %struct.TYPE_7__* %1, i32 %2, i8** nocapture %3) {
%5 = load i32, i32* @XkbGroupNamesMask
%6 = tail call i64 @XkbGetNames(i32* %0, i32 %5, %struct.TYPE_7__* %1)
%7 = load i64, i64* @Success
%8 = icmp eq i64 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @eprint(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %36
13: ; preds = %11
%14 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %1, i64 0, i32 0
%15 = zext i32 %2 to i64
br label %16
16: ; preds = %13, %33
%17 = phi i64 [ 0, %13 ], [ %34, %33 ]
%18 = load %struct.TYPE_6__*, %struct.TYPE_6__** %14
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %18, i64 0, i32 0
%20 = load i64*, i64** %19
%21 = getelementptr inbounds i64, i64* %20, i64 %17
%22 = load i64, i64* %21
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %16
%25 = tail call i8* @XGetAtomName(i32* %0, i64 %22)
%26 = icmp eq i8* %25, null
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = getelementptr inbounds i8*, i8** %3, i64 %17
%29 = load i8*, i8** %28
%30 = tail call i32 @snprintf(i8* %29, i32 4, i8* %25)
br label %33
31: ; preds = %24
%32 = tail call i32 @eprint(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %16, %31, %27
%34 = add nuw nsw i64 %17, 1
%35 = icmp eq i64 %34, %15
br i1 %35, label %36, label %16
36: ; preds = %33, %11
%37 = load i32, i32* @XkbGroupNamesMask
%38 = tail call i32 @XkbFreeNames(%struct.TYPE_7__* %1, i32 %37, i32 0)
ret void
}