#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 */
typedef int wchar_t;
typedef int /*<<< orphan*/ e;
struct TYPE_4__ {
  int serial;
  int state;
  int keycode;
  void *same_screen;
  int /*<<< orphan*/ *display;
  void *send_event;
  int /*<<< orphan*/ type;
};
typedef TYPE_1__ XKeyPressedEvent;
typedef scalar_t__ KeySym;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ KeyPress;
int /*<<< orphan*/ LC_CTYPE;
void *True;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
char *XDisplayName(char *);
int XLookupString(TYPE_1__ *, char *, int, scalar_t__ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int mbstowcs(int *, char *, int);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  const char *programname;
  char text[256];
  char *displayname = NULL;
  char *outfname;
  char *sections[5] = {"noshift", "shift", "altgr", "capslock",
                       "shiftcapslock"};
  int states[5] = {0, 1, 0x80, 2, 3};
  int i;
  int idx;
  int char_count;
  int nbytes = 0;
  int unicode;
  Display *dpy;
  KeySym ks;
  FILE *outf;
  XKeyPressedEvent e;
  wchar_t wtext[256];
  setlocale(LC_CTYPE, "");
  programname = argv[0];
  if (argc != 2) {
    fprintf(stderr, "Usage: %s out_filename\n", programname);
    fprintf(stderr, "Example: %s /etc/xrdp/km-0409.ini\n", programname);
    return 1;
  }
  outfname = argv[1];
  dpy = XOpenDisplay(displayname);
  if (!dpy) {
    fprintf(stderr, "%s:  unable to open display '%s'\n", programname,
            XDisplayName(displayname));
    return 1;
  }
  outf = fopen(outfname, "w");
  if (outf == NULL) {
    fprintf(stderr, "%s:  unable to create file '%s'\n", programname, outfname);
    XCloseDisplay(dpy);
    return 1;
  }
  memset(&e, 0, sizeof(e));
  e.type = KeyPress;
  e.serial = 16;
  e.send_event = True;
  e.display = dpy;
  e.same_screen = True;
  for (idx = 0; idx < 5; idx++) {
    fprintf(outf, "[%s]\n", sections[idx]);
    e.state = states[idx];
    for (i = 8; i <= 137; i++) {
      e.keycode = i;
      nbytes = XLookupString(&e, text, 255, &ks, NULL);
      text[nbytes] = 0;
      char_count = mbstowcs(wtext, text, 255);
      unicode = 0;
      if (char_count == 1) {
        unicode = wtext[0];
      }
      fprintf(outf, "Key%d=%d:%d\n", i, (int)ks, unicode);
    }
    if (idx != 4) {
      fprintf(outf, "\n");
    }
  }
  XCloseDisplay(dpy);
  fclose(outf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x128(%rbp)
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    0xe22(%rip),%rax
mov    %rax,-0x160(%rbp)
lea    0xe16(%rip),%rax
mov    %rax,-0x158(%rbp)
lea    0xe0e(%rip),%rax
mov    %rax,-0x150(%rbp)
lea    0xe0b(%rip),%rax
mov    %rax,-0x148(%rbp)
lea    0xdf8(%rip),%rax
mov    %rax,-0x140(%rbp)
mov    0xe8c(%rip),%rax
mov    %rax,-0x180(%rbp)
mov    0xe86(%rip),%rax
mov    %rax,-0x178(%rbp)
mov    0xe81(%rip),%eax
mov    %eax,-0x170(%rbp)
movl   $0x0,-0x190(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   10a0 <setlocale@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     12bd <main+0x11d>
mov    0x2d48(%rip),%rax
movslq (%rax),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d2c(%rip),%rax
movslq (%rax),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1587 <main+0x3e7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x130(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <XOpenDisplay@plt>
mov    %rax,-0x1a0(%rbp)
cmpq   $0x0,-0x1a0(%rbp)
jne    1340 <main+0x1a0>
mov    0x2cd4(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x5f0(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x5e8(%rbp)
mov    -0x128(%rbp),%rdi
call   1090 <XDisplayName@plt>
mov    -0x5f0(%rbp),%rdi
mov    -0x5e8(%rbp),%rdx
mov    %rax,%rcx
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1587 <main+0x3e7>
mov    -0x130(%rbp),%rdi
lea    0xd2b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1b0(%rbp)
cmpq   $0x0,-0x1b0(%rbp)
jne    13a3 <main+0x203>
mov    0x2c59(%rip),%rax
movslq (%rax),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x130(%rbp),%rcx
lea    0xcf7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x1a0(%rbp),%rdi
call   10c0 <XCloseDisplay@plt>
movl   $0x1,-0x4(%rbp)
jmp    1587 <main+0x3e7>
lea    -0x1e0(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
mov    0x2c1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1b8(%rbp)
movl   $0x10,-0x1e0(%rbp)
mov    0x2c0a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x1c0(%rbp)
mov    -0x1a0(%rbp),%rax
mov    %rax,-0x1c8(%rbp)
mov    0x2beb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x1d0(%rbp)
movl   $0x0,-0x188(%rbp)
cmpl   $0x5,-0x188(%rbp)
jge    1568 <main+0x3c8>
mov    -0x1b0(%rbp),%rdi
movslq -0x188(%rbp),%rax
mov    -0x160(%rbp,%rax,8),%rdx
ff
lea    0xc69(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movslq -0x188(%rbp),%rax
mov    -0x180(%rbp,%rax,4),%eax
mov    %eax,-0x1dc(%rbp)
movl   $0x8,-0x184(%rbp)
cmpl   $0x89,-0x184(%rbp)
jg     152d <main+0x38d>
mov    -0x184(%rbp),%eax
mov    %eax,-0x1d8(%rbp)
lea    -0x120(%rbp),%rsi
lea    -0x1e0(%rbp),%rdi
mov    $0xff,%edx
lea    -0x1a8(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <XLookupString@plt>
mov    %eax,-0x190(%rbp)
movslq -0x190(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x5e0(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1040 <mbstowcs@plt>
mov    %eax,-0x18c(%rbp)
movl   $0x0,-0x194(%rbp)
cmpl   $0x1,-0x18c(%rbp)
jne    14ee <main+0x34e>
mov    -0x5e0(%rbp),%eax
mov    %eax,-0x194(%rbp)
mov    -0x1b0(%rbp),%rdi
mov    -0x184(%rbp),%edx
mov    -0x1a8(%rbp),%rax
mov    %eax,%ecx
mov    -0x194(%rbp),%r8d
lea    0xb90(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x184(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x184(%rbp)
jmp    1458 <main+0x2b8>
cmpl   $0x4,-0x188(%rbp)
je     154f <main+0x3af>
mov    -0x1b0(%rbp),%rdi
lea    0xb52(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1554 <main+0x3b4>
mov    -0x188(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x188(%rbp)
jmp    1409 <main+0x269>
mov    -0x1a0(%rbp),%rdi
call   10c0 <XCloseDisplay@plt>
mov    -0x1b0(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x5f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x588,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe33(%rip),%rax
mov    %rax,0x50(%rsp)
lea    0xe29(%rip),%rax
mov    %rax,0x58(%rsp)
lea    0xe23(%rip),%rax
mov    %rax,0x60(%rsp)
lea    0xe22(%rip),%rax
mov    %rax,0x68(%rsp)
lea    0xe11(%rip),%rax
mov    %rax,0x70(%rsp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   10b0 <setlocale@plt>
mov    (%rbx),%r15
cmp    $0x2,%ebp
jne    1386 <main+0x1d6>
mov    0x8(%rbx),%r14
xor    %edi,%edi
call   1080 <XOpenDisplay@plt>
test   %rax,%rax
je     13cd <main+0x21d>
mov    %rax,%rbp
lea    0xe38(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     13f7 <main+0x247>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
movl   $0x10,0x20(%rsp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x40(%rsp)
mov    %rbp,0x8(%rsp)
mov    %rbp,0x38(%rsp)
mov    %rax,0x30(%rsp)
lea    0x80(%rsp),%rbp
lea    0x18(%rsp),%r14
lea    0x180(%rsp),%r13
lea    0xded(%rip),%r12
xor    %r15d,%r15d
lea    0xd41(%rip),%rdx
nop
mov    %rbx,%rdi
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xdd8(%rip),%rax
mov    %r15,0x10(%rsp)
mov    (%rax,%r15,4),%eax
mov    %eax,0x24(%rsp)
mov    $0x8,%r15d
jmp    1311 <main+0x161>
nopl   (%rax)
mov    0x18(%rsp),%ecx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
add    $0x1,%r15d
cmp    $0x8a,%r15d
je     1360 <main+0x1b0>
mov    %r15d,0x28(%rsp)
lea    0x20(%rsp),%rdi
mov    %rbp,%rsi
mov    $0xff,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1030 <XLookupString@plt>
cltq
movb   $0x0,0x80(%rsp,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0xff,%edx
call   1040 <mbstowcs@plt>
mov    $0x0,%r8d
cmp    $0x1,%eax
jne    12f0 <main+0x140>
mov    0x180(%rsp),%r8d
jmp    12f0 <main+0x140>
nopl   (%rax)
mov    0x10(%rsp),%r15
cmp    $0x4,%r15
je     13b7 <main+0x207>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    0x58(%rsp,%r15,8),%rdx
add    $0x1,%r15
jmp    12c0 <main+0x110>
mov    0x2c3b(%rip),%rbx
movslq (%rbx),%rdi
lea    0xc85(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
movslq (%rbx),%rdi
lea    0xc89(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    141d <main+0x26d>
mov    0x8(%rsp),%rdi
call   10d0 <XCloseDisplay@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    1422 <main+0x272>
mov    0x2bf4(%rip),%rax
movslq (%rax),%rbx
xor    %edi,%edi
call   10a0 <XDisplayName@plt>
lea    0xc72(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    141d <main+0x26d>
mov    0x2bca(%rip),%rax
movslq (%rax),%rdi
lea    0xc73(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbp,%rdi
call   10d0 <XCloseDisplay@plt>
mov    $0x1,%eax
add    $0x588,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32, i32, i8*, i32*, i8*, i32 }
@.str = [8 x i8] c"noshift\00"
@.str.1 = [6 x i8] c"shift\00"
@.str.2 = [6 x i8] c"altgr\00"
@.str.3 = [9 x i8] c"capslock\00"
@.str.4 = [14 x i8] c"shiftcapslock\00"
@__const.main.states = [5 x i32] [i32 0, i32 1, i32 128, i32 2, i32 3]
@LC_CTYPE = global i32 0
@.str.5 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.6 = [24 x i8] c"Usage: %s out_filename\0A\00"
@.str.7 = [35 x i8] c"Example: %s /etc/xrdp/km-0409.ini\0A\00"
@.str.8 = [34 x i8] c"%s: unable to open display '%s'\0A\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [33 x i8] c"%s: unable to create file '%s'\0A\00"
@KeyPress = global i32 0
@True = global i8* null
@.str.11 = [6 x i8] c"[%s]\0A\00"
@.str.12 = [13 x i8] c"Key%d=%d:%d\0A\00"
@.str.13 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [5 x i8*]
%11 = alloca [5 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32*
%18 = alloca i64
%19 = alloca i32*
%20 = alloca %struct.TYPE_4__
%21 = alloca [256 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
%22 = bitcast [5 x i8*]* %10 to i8*
%23 = bitcast i8* %22 to [5 x i8*]*
%24 = getelementptr inbounds [5 x i8*], [5 x i8*]* %23, i32 0, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i8** %24
%25 = getelementptr inbounds [5 x i8*], [5 x i8*]* %23, i32 0, i32 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8** %25
%26 = getelementptr inbounds [5 x i8*], [5 x i8*]* %23, i32 0, i32 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8** %26
%27 = getelementptr inbounds [5 x i8*], [5 x i8*]* %23, i32 0, i32 3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8** %27
%28 = getelementptr inbounds [5 x i8*], [5 x i8*]* %23, i32 0, i32 4
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i32 0, i32 0), i8** %28
%29 = bitcast [5 x i32]* %11 to i8*
store i32 0, i32* %15
%30 = load i32, i32* @LC_CTYPE
%31 = call i32 @setlocale(i32 %30, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
store i8* %34, i8** %6
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 2
br i1 %36, label %37, label %48
37: ; preds = %2
%38 = load i32, i32* @stderr
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i32*
%41 = load i8*, i8** %6
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @stderr
%44 = sext i32 %43 to i64
%45 = inttoptr i64 %44 to i32*
%46 = load i8*, i8** %6
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %46)
store i32 1, i32* %3
br label %148
48: ; preds = %2
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
store i8* %51, i8** %9
%52 = load i8*, i8** %8
%53 = call i32* @XOpenDisplay(i8* %52)
store i32* %53, i32** %17
%54 = load i32*, i32** %17
%55 = icmp ne i32* %54, null
br i1 %55, label %64, label %56
56: ; preds = %48
%57 = load i32, i32* @stderr
%58 = sext i32 %57 to i64
%59 = inttoptr i64 %58 to i32*
%60 = load i8*, i8** %6
%61 = load i8*, i8** %8
%62 = call i8* @XDisplayName(i8* %61)
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8* %60, i8* %62)
store i32 1, i32* %3
br label %148
64: ; preds = %48
%65 = load i8*, i8** %9
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %66, i32** %19
%67 = load i32*, i32** %19
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %78
69: ; preds = %64
%70 = load i32, i32* @stderr
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i32*
%73 = load i8*, i8** %6
%74 = load i8*, i8** %9
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i8* %73, i8* %74)
%76 = load i32*, i32** %17
%77 = call i32 @XCloseDisplay(i32* %76)
store i32 1, i32* %3
br label %148
78: ; preds = %64
%79 = call i32 @memset(%struct.TYPE_4__* %20, i32 0, i32 48)
%80 = load i32, i32* @KeyPress
%81 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 6
store i32 %80, i32* %81
%82 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 0
store i32 16, i32* %82
%83 = load i8*, i8** @True
%84 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 5
store i8* %83, i8** %84
%85 = load i32*, i32** %17
%86 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 4
store i32* %85, i32** %86
%87 = load i8*, i8** @True
%88 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 3
store i8* %87, i8** %88
store i32 0, i32* %13
br label %89
89: ; preds = %140, %78
%90 = load i32, i32* %13
%91 = icmp slt i32 %90, 5
br i1 %91, label %92, label %143
92: ; preds = %89
%93 = load i32*, i32** %19
%94 = load i32, i32* %13
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [5 x i8*], [5 x i8*]* %10, i64 0, i64 %95
%97 = load i8*, i8** %96
%98 = call i32 (i32*, i8*, ...) @fprintf(i32* %93, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* %97)
%99 = load i32, i32* %13
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [5 x i32], [5 x i32]* %11, i64 0, i64 %100
%102 = load i32, i32* %101
%103 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 1
store i32 %102, i32* %103
store i32 8, i32* %12
br label %104
104: ; preds = %130, %92
%105 = load i32, i32* %12
%106 = icmp sle i32 %105, 137
br i1 %106, label %107, label %133
107: ; preds = %104
%108 = load i32, i32* %12
%109 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 2
store i32 %108, i32* %109
%110 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%111 = call i32 @XLookupString(%struct.TYPE_4__* %20, i8* %110, i32 255, i64* %18, i32* null)
store i32 %111, i32* %15
%112 = load i32, i32* %15
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %113
store i8 0, i8* %114
%115 = getelementptr inbounds [256 x i32], [256 x i32]* %21, i64 0, i64 0
%116 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%117 = call i32 @mbstowcs(i32* %115, i8* %116, i32 255)
store i32 %117, i32* %14
store i32 0, i32* %16
%118 = load i32, i32* %14
%119 = icmp eq i32 %118, 1
br i1 %119, label %120, label %123
120: ; preds = %107
%121 = getelementptr inbounds [256 x i32], [256 x i32]* %21, i64 0, i64 0
%122 = load i32, i32* %121
store i32 %122, i32* %16
br label %123
123: ; preds = %120, %107
%124 = load i32*, i32** %19
%125 = load i32, i32* %12
%126 = load i64, i64* %18
%127 = trunc i64 %126 to i32
%128 = load i32, i32* %16
%129 = call i32 (i32*, i8*, ...) @fprintf(i32* %124, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 %125, i32 %127, i32 %128)
br label %130
130: ; preds = %123
%131 = load i32, i32* %12
%132 = add nsw i32 %131, 1
store i32 %132, i32* %12
br label %104
133: ; preds = %104
%134 = load i32, i32* %13
%135 = icmp ne i32 %134, 4
br i1 %135, label %136, label %139
136: ; preds = %133
%137 = load i32*, i32** %19
%138 = call i32 (i32*, i8*, ...) @fprintf(i32* %137, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
br label %139
139: ; preds = %136, %133
br label %140
140: ; preds = %139
%141 = load i32, i32* %13
%142 = add nsw i32 %141, 1
store i32 %142, i32* %13
br label %89
143: ; preds = %89
%144 = load i32*, i32** %17
%145 = call i32 @XCloseDisplay(i32* %144)
%146 = load i32*, i32** %19
%147 = call i32 @fclose(i32* %146)
store i32 0, i32* %3
br label %148
148: ; preds = %143, %69, %56, %37
%149 = load i32, i32* %3
ret i32 %149
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32, i32, i8*, i32*, i8*, i32 }
@.str = [8 x i8] c"noshift\00"
@.str.1 = [6 x i8] c"shift\00"
@.str.2 = [6 x i8] c"altgr\00"
@.str.3 = [9 x i8] c"capslock\00"
@.str.4 = [14 x i8] c"shiftcapslock\00"
@__const.main.states = [5 x i32] [i32 0, i32 1, i32 128, i32 2, i32 3]
@LC_CTYPE = global i32 0
@.str.5 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.6 = [24 x i8] c"Usage: %s out_filename\0A\00"
@.str.7 = [35 x i8] c"Example: %s /etc/xrdp/km-0409.ini\0A\00"
@.str.8 = [34 x i8] c"%s: unable to open display '%s'\0A\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [33 x i8] c"%s: unable to create file '%s'\0A\00"
@KeyPress = global i32 0
@True = global i8* null
@.str.11 = [6 x i8] c"[%s]\0A\00"
@.str.12 = [13 x i8] c"Key%d=%d:%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [5 x i8*]
%5 = alloca i64
%6 = alloca %struct.TYPE_4__
%7 = alloca [256 x i32]
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = bitcast [5 x i8*]* %4 to i8*
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 4
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8** %14
%15 = bitcast i64* %5 to i8*
%16 = bitcast %struct.TYPE_4__* %6 to i8*
%17 = bitcast [256 x i32]* %7 to i8*
%18 = load i32, i32* @LC_CTYPE
%19 = tail call i32 @setlocale(i32 %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%20 = load i8*, i8** %1
%21 = icmp eq i32 %0, 2
br i1 %21, label %31, label %22
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = sext i32 %23 to i64
%25 = inttoptr i64 %24 to i32*
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %20)
%27 = load i32, i32* @stderr
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i32*
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i8* %20)
br label %93
31: ; preds = %2
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = tail call i32* @XOpenDisplay(i8* null)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = sext i32 %37 to i64
%39 = inttoptr i64 %38 to i32*
%40 = tail call i8* @XDisplayName(i8* null)
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8* %20, i8* %40)
br label %93
42: ; preds = %31
%43 = tail call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = sext i32 %46 to i64
%48 = inttoptr i64 %47 to i32*
%49 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i8* %20, i8* %33)
%50 = tail call i32 @XCloseDisplay(i32* %34)
br label %93
51: ; preds = %42
%52 = call i32 @memset(%struct.TYPE_4__* %6, i32 0, i32 48)
%53 = load i32, i32* @KeyPress
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 6
store i32 %53, i32* %54
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 0
store i32 16, i32* %55
%56 = load i8*, i8** @True
%57 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 5
store i8* %56, i8** %57
%58 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 4
store i32* %34, i32** %58
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 3
store i8* %56, i8** %59
%60 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 1
%61 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 2
%62 = getelementptr inbounds [256 x i32], [256 x i32]* %7, i64 0, i64 0
br label %63
63: ; preds = %85, %51
%64 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %51 ], [ %89, %85 ]
%65 = phi i64 [ 0, %51 ], [ %87, %85 ]
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* %64)
%67 = getelementptr inbounds [5 x i32], [5 x i32]* @__const.main.states, i64 0, i64 %65
%68 = load i32, i32* %67
store i32 %68, i32* %60
br label %69
69: ; preds = %63, %69
%70 = phi i32 [ 8, %63 ], [ %81, %69 ]
store i32 %70, i32* %61
%71 = call i32 @XLookupString(%struct.TYPE_4__* %6, i8* %8, i32 255, i64* %5, i32* null)
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %72
store i8 0, i8* %73
%74 = call i32 @mbstowcs(i32* %62, i8* %8, i32 255)
%75 = icmp eq i32 %74, 1
%76 = load i32, i32* %62
%77 = select i1 %75, i32 %76, i32 0
%78 = load i64, i64* %5
%79 = trunc i64 %78 to i32
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 %70, i32 %79, i32 %77)
%81 = add nuw nsw i32 %70, 1
%82 = icmp eq i32 %81, 138
br i1 %82, label %83, label %69
83: ; preds = %69
%84 = icmp eq i64 %65, 4
br i1 %84, label %90, label %85
85: ; preds = %83
%86 = call i32 @fputc(i32 10, i32* %43)
%87 = add nuw nsw i64 %65, 1
%88 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 %87
%89 = load i8*, i8** %88
br label %63
90: ; preds = %83
%91 = call i32 @XCloseDisplay(i32* %34)
%92 = call i32 @fclose(i32* %43)
br label %93
93: ; preds = %90, %45, %36, %22
%94 = phi i32 [ 1, %22 ], [ 1, %45 ], [ 0, %90 ], [ 1, %36 ]
ret i32 %94
}