#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_5__ TYPE_1__;

/* Type definitions */
typedef int wchar_t;
typedef int /*<<< orphan*/ ustr;
typedef int uint32_t;
typedef scalar_t__ iconv_t;
struct TYPE_5__ {
  int *value;
  int format;
  int nitems;
  int /*<<< orphan*/ encoding;
};
typedef TYPE_1__ XTextProperty;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int Success;
int /*<<< orphan*/ XCompoundTextStyle;
char *XDefaultString();
char *XGetAtomName(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XInternAtom(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int Xutf8TextListToTextProperty(int /*<<< orphan*/ *, char **, int,
                                int /*<<< orphan*/, TYPE_1__ *);
int Xutf8TextPropertyToTextList(int /*<<< orphan*/ *, TYPE_1__ *, char ***,
                                int *);
int XwcTextListToTextProperty(int /*<<< orphan*/ *, int **, int,
                              int /*<<< orphan*/, TYPE_1__ *);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
size_t iconv(scalar_t__, char **, size_t *, char **, size_t *);
scalar_t__ iconv_open(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int strlen(char const *);
int main(void) {
  Display *display;
  setlocale(LC_ALL, NULL);
  setlocale(LC_ALL, "ar_IN.UTF-8");
  setlocale(LC_ALL, "en_AU.ISO-8859-1");
  display = XOpenDisplay(NULL);
  printf("display %p\n", display);
  {
    iconv_t ic;
    uint32_t ucs = 0x9F9C;
    char *inbuf;
    static char ustr[16];
    char *outbuf;
    size_t inleft, outlen, iret, ulen;
    static char *ulist[2];
    static XTextProperty text_prop;
    int ret;
    int i;
    ic = iconv_open("utf-8", "utf-32le");
    if (ic == (iconv_t)-1) {
      perror("iconv_open");
      abort();
    }
    for (ucs = 0x100; ucs <= 0x2F1AD; ucs++) {
      inbuf = (char *)&ucs;
      inleft = 4;
      outbuf = ustr;
      outlen = sizeof(ustr) - 1;
      iret = iconv(ic, &inbuf, &inleft, &outbuf, &outlen);
      if (iret == -1) {
        continue;
        perror("iconv");
        abort();
      }
      if (iret != 0) {
        printf("iret %u\n", iret);
        abort();
      }
      ulen = outbuf - ustr;
      ustr[ulen] = '\0';
      ulist[0] = ustr;
      ret = Xutf8TextListToTextProperty(display, ulist, 1, XCompoundTextStyle,
                                        &text_prop);
      if (ret != 0) {
        continue;
      }
      if (text_prop.value[1] != 0x24) {
        continue;
      }
      if (text_prop.value[3] < 0x46) {
        continue;
      }
      printf("ret %d\n", ret);
      if (ret >= 0) {
        printf("ucs 0x%04X ustr [len %u] ", ucs, ulen);
        for (i = 0; i < ulen; i++) {
          printf(" %02X", (unsigned)(unsigned char)ustr[i]);
        }
        printf("\n");
        printf("text encoding %lu\n", text_prop.encoding);
        printf("text encoding %s\n", XGetAtomName(display, text_prop.encoding));
        printf("text format %d\n", text_prop.format);
        printf("text nitems %lu\n", text_prop.nitems);
        printf("text value: ");
        for (i = 0; i < text_prop.nitems; i++) {
          printf(" %02X", text_prop.value[i]);
        }
        printf("\n");
        break;
      }
    }
    return 0;
  }
  {
    static char ctext[] = "\x1B\x28\x4A\x7E";
    static XTextProperty text_prop;
    int ret;
    char **tlist;
    int tcount;
    int i;
    text_prop.encoding = XInternAtom(display, "COMPOUND_TEXT", 0);
    text_prop.format = 8;
    text_prop.nitems = strlen(ctext);
    text_prop.value = (unsigned char *)ctext;
    ret = Xutf8TextPropertyToTextList(display, &text_prop, &tlist, &tcount);
    printf("  Xutf8TextPropertyToTextList ret %d\n", ret);
    printf("  got utf8  ");
    for (i = 0; i < strlen(tlist[0]); i++) {
      printf(" %02X", (int)(unsigned char)tlist[0][i]);
    }
    printf("\n");
    return 0;
  }
  {
    const char *str = XDefaultString();
    int i;
    printf("XDefaultString [len %d] ", strlen(str));
    for (i = 0; i < strlen(str); i++) {
      printf(" %02X", (int)(unsigned char)str[i]);
    }
    printf("\n");
    printf("\"Success\" is %d\n", Success);
  }
  {
    FILE *fp = fopen("encode-emacs23.utf8", "r");
    if (!fp) {
      printf("cannot open\n");
      abort();
    }
    char buf[500000];
    size_t len = fread(buf, 1, 500000, fp);
    fclose(fp);
    buf[len] = '\0';
    static char *ulist[2];
    static XTextProperty text_prop;
    int ret;
    ulist[0] = buf;
    ret = Xutf8TextListToTextProperty(display, ulist, 1, XCompoundTextStyle,
                                      &text_prop);
    printf("ret %d\n", ret);
    if (ret >= 0) {
      printf("text encoding %lu\n", text_prop.encoding);
      printf("text encoding %s\n", XGetAtomName(display, text_prop.encoding));
      printf("text format %d\n", text_prop.format);
      printf("text nitems %lu\n", text_prop.nitems);
      printf("text value: ");
      FILE *fp = fopen("encode-emacs23xc.ctext", "w");
      if (!fp) {
        printf("cannot open\n");
        abort();
      }
      fwrite(text_prop.value, text_prop.nitems, 1, fp);
      fclose(fp);
    }
    return 0;
  }
  {
    static wchar_t wstr[2];
    static wchar_t *wlist[2];
    static XTextProperty text_prop;
    int ret;
    wchar_t c;
    int i;
    for (c = 32; c < 1000; c++) {
      wstr[0] = c;
      wlist[0] = wstr;
      ret = XwcTextListToTextProperty(display, wlist, 1, XCompoundTextStyle,
                                      &text_prop);
      printf("c=%d ret %d\n", c, ret);
      if (ret == 0) {
        printf("text encoding %lu\n", text_prop.encoding);
        printf("text encoding %s\n", XGetAtomName(display, text_prop.encoding));
        printf("text format %d\n", text_prop.format);
        printf("text nitems %lu\n", text_prop.nitems);
        printf("text value: ");
        for (i = 0; i < text_prop.nitems; i++) {
          printf(" %02X", text_prop.value[i]);
        }
        printf("\n");
      }
    }
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7a1d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <setlocale@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1090 <setlocale@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1090 <setlocale@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <XOpenDisplay@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x9f9c,-0x1c(%rbp)
lea    0xe1e(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   10b0 <iconv_open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1239 <main+0xa9>
lea    0xe0b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x100,-0x1c(%rbp)
cmpl   $0x2f1ad,-0x1c(%rbp)
jg     14a1 <main+0x311>
lea    -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x4,-0x38(%rbp)
lea    0x2e2c(%rip),%rax
mov    %rax,-0x30(%rbp)
movq   $0xf,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1040 <iconv@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0xffffffffffffffff,-0x48(%rbp)
jne    129d <main+0x10d>
jmp    1493 <main+0x303>
cmpq   $0x0,-0x48(%rbp)
je     12c1 <main+0x131>
mov    -0x48(%rbp),%rsi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x30(%rbp),%rax
lea    0x2dc4(%rip),%rcx
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rcx
lea    0x2db2(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2da7(%rip),%rax
mov    %rax,0x2db0(%rip)
mov    -0x10(%rbp),%rdi
mov    0x2ced(%rip),%rax
mov    (%rax),%ecx
lea    0x2d9c(%rip),%rsi
mov    $0x1,%edx
lea    0x2da0(%rip),%r8
call   1060 <Xutf8TextListToTextProperty@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     1327 <main+0x197>
jmp    1493 <main+0x303>
mov    0x2d82(%rip),%rax
cmpl   $0x24,0x4(%rax)
je     133d <main+0x1ad>
jmp    1493 <main+0x303>
mov    0x2d6c(%rip),%rax
cmpl   $0x46,0xc(%rax)
jge    1353 <main+0x1c3>
jmp    1493 <main+0x303>
mov    -0x54(%rbp),%esi
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x54(%rbp)
jl     148e <main+0x2fe>
mov    -0x1c(%rbp),%esi
mov    -0x50(%rbp),%rdx
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x58(%rbp)
movslq -0x58(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    13c3 <main+0x233>
movslq -0x58(%rbp),%rcx
lea    0x2ced(%rip),%rax
movzbl (%rax,%rcx,1),%esi
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    138a <main+0x1fa>
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ce9(%rip),%esi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2cd1(%rip),%esi
call   1080 <XGetAtomName@plt>
mov    %rax,%rsi
lea    0xc89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2cad(%rip),%esi
lea    0xc87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c9d(%rip),%esi
lea    0xc83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xc86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    0x2c71(%rip),%eax
jge    147b <main+0x2eb>
mov    0x2c58(%rip),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xc08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1442 <main+0x2b2>
lea    0xc25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14a1 <main+0x311>
jmp    1493 <main+0x303>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1240 <main+0xb0>
xor    %eax,%eax
add    $0x7a1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x2e23(%rip),%rbx
mov    (%rbx),%edi
xor    %esi,%esi
call   10a0 <setlocale@plt>
mov    (%rbx),%edi
lea    0xe39(%rip),%rsi
call   10a0 <setlocale@plt>
mov    (%rbx),%edi
lea    0xe37(%rip),%rsi
call   10a0 <setlocale@plt>
xor    %edi,%edi
call   1080 <XOpenDisplay@plt>
lea    0xe35(%rip),%rdi
mov    %rax,0x10(%rsp)
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2b(%rip),%rdi
lea    0xe2a(%rip),%rsi
call   10c0 <iconv_open@plt>
cmp    $0xffffffffffffffff,%rax
je     1427 <main+0x287>
mov    %rax,%r15
movl   $0x100,0xc(%rsp)
lea    0x2e6a(%rip),%r12
lea    0x28(%rsp),%r13
lea    0x18(%rsp),%rbp
lea    0x20(%rsp),%r14
jmp    1256 <main+0xb6>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x2f1ad,%eax
jge    13fe <main+0x25e>
lea    0xc(%rsp),%rax
mov    %rax,0x30(%rsp)
movq   $0x4,0x28(%rsp)
mov    %r12,0x18(%rsp)
movq   $0xf,0x20(%rsp)
mov    %r15,%rdi
lea    0x30(%rsp),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
call   1050 <iconv@plt>
cmp    $0xffffffffffffffff,%rax
je     1240 <main+0xa0>
test   %rax,%rax
jne    140f <main+0x26f>
mov    0x18(%rsp),%rbx
movb   $0x0,(%rbx)
mov    %r12,0x2df5(%rip)
mov    0x2d36(%rip),%rax
mov    (%rax),%ecx
mov    0x10(%rsp),%rdi
lea    0x2de0(%rip),%rsi
mov    $0x1,%edx
lea    0x2de4(%rip),%r8
call   1070 <Xutf8TextListToTextProperty@plt>
test   %eax,%eax
jne    1240 <main+0xa0>
mov    0x2dd0(%rip),%rax
cmpl   $0x24,0x4(%rax)
jne    1240 <main+0xa0>
cmpl   $0x46,0xc(%rax)
jl     1240 <main+0xa0>
sub    %r12,%rbx
lea    0xd4e(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xd42(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     1349 <main+0x1a9>
lea    0xd46(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl 0x0(%rbp,%r12,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1330 <main+0x190>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d67(%rip),%esi
lea    0xd14(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d53(%rip),%esi
mov    0x10(%rsp),%rdi
call   1090 <XGetAtomName@plt>
lea    0xd09(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d2a(%rip),%esi
lea    0xd04(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d1a(%rip),%esi
lea    0xd00(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd03(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0x2cf7(%rip)
jle    13f4 <main+0x254>
lea    0xca0(%rip),%rbx
xor    %ebp,%ebp
mov    0x2cd9(%rip),%rax
mov    (%rax,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
movslq 0x2ccd(%rip),%rax
cmp    %rax,%rbp
jl     13d0 <main+0x230>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc2d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <abort@plt>
lea    0xc0a(%rip),%rdi
call   10b0 <perror@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32*, i32, i32, i32 }
@LC_ALL = global i32 0
@.str = [12 x i8] c"ar_IN.UTF-8\00"
@.str.1 = [17 x i8] c"en_AU.ISO-8859-1\00"
@.str.2 = [12 x i8] c"display %p\0A\00"
@main.ustr = internal global [16 x i8] zeroinitializer
@main.ulist = internal global [2 x i8*] zeroinitializer
@main.text_prop = internal global %struct.TYPE_5__ zeroinitializer
@.str.3 = [6 x i8] c"utf-8\00"
@.str.4 = [9 x i8] c"utf-32le\00"
@.str.5 = [11 x i8] c"iconv_open\00"
@.str.6 = [9 x i8] c"iret %u\0A\00"
@XCompoundTextStyle = global i32 0
@.str.7 = [8 x i8] c"ret %d\0A\00"
@.str.8 = [26 x i8] c"ucs 0x%04X ustr [len %u] \00"
@.str.9 = [6 x i8] c" %02X\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [19 x i8] c"text encoding %lu\0A\00"
@.str.12 = [18 x i8] c"text encoding %s\0A\00"
@.str.13 = [16 x i8] c"text format %d\0A\00"
@.str.14 = [17 x i8] c"text nitems %lu\0A\00"
@.str.15 = [13 x i8] c"text value: \00"
@main.ctext = internal global [5 x i8] c"\1B(J~\00"
@main.text_prop.16 = internal global %struct.TYPE_5__ zeroinitializer
@main.ulist.17 = internal global [2 x i8*] zeroinitializer
@main.text_prop.18 = internal global %struct.TYPE_5__ zeroinitializer
@main.wstr = internal global [2 x i32] zeroinitializer
@main.wlist = internal global [2 x i32*] zeroinitializer
@main.text_prop.19 = internal global %struct.TYPE_5__ zeroinitializer
@Success = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8**
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32*
%20 = alloca [500000 x i8]
%21 = alloca i64
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
store i32 0, i32* %1
%26 = load i32, i32* @LC_ALL
%27 = call i32 @setlocale(i32 %26, i8* null)
%28 = load i32, i32* @LC_ALL
%29 = call i32 @setlocale(i32 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%30 = load i32, i32* @LC_ALL
%31 = call i32 @setlocale(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32* @XOpenDisplay(i32* null)
store i32* %32, i32** %2
%33 = load i32*, i32** %2
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %33)
store i32 40860, i32* %4
%35 = call i64 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i64 %35, i64* %3
%36 = load i64, i64* %3
%37 = icmp eq i64 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %0
%39 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %0
store i32 256, i32* %4
br label %42
42: ; preds = %137, %41
%43 = load i32, i32* %4
%44 = icmp sle i32 %43, 192941
br i1 %44, label %45, label %140
45: ; preds = %42
%46 = bitcast i32* %4 to i8*
store i8* %46, i8** %5
store i64 4, i64* %7
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.ustr, i64 0, i64 0), i8** %6
store i64 15, i64* %8
%47 = load i64, i64* %3
%48 = call i64 @iconv(i64 %47, i8** %5, i64* %7, i8** %6, i64* %8)
store i64 %48, i64* %9
%49 = load i64, i64* %9
%50 = icmp eq i64 %49, -1
br i1 %50, label %51, label %52
51: ; preds = %45
br label %137
52: ; preds = %45
%53 = load i64, i64* %9
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i64, i64* %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 %56)
%58 = call i32 (...) @abort()
unreachable
59: ; preds = %52
%60 = load i8*, i8** %6
%61 = ptrtoint i8* %60 to i64
%62 = sub i64 %61, ptrtoint ([16 x i8]* @main.ustr to i64)
store i64 %62, i64* %10
%63 = load i64, i64* %10
%64 = getelementptr inbounds [16 x i8], [16 x i8]* @main.ustr, i64 0, i64 %63
store i8 0, i8* %64
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.ustr, i64 0, i64 0), i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @main.ulist, i64 0, i64 0)
%65 = load i32*, i32** %2
%66 = load i32, i32* @XCompoundTextStyle
%67 = call i32 @Xutf8TextListToTextProperty(i32* %65, i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @main.ulist, i64 0, i64 0), i32 1, i32 %66, %struct.TYPE_5__* @main.text_prop)
store i32 %67, i32* %11
%68 = load i32, i32* %11
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %59
br label %137
71: ; preds = %59
%72 = load i32*, i32** getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i32 0, i32 0)
%73 = getelementptr inbounds i32, i32* %72, i64 1
%74 = load i32, i32* %73
%75 = icmp ne i32 %74, 36
br i1 %75, label %76, label %77
76: ; preds = %71
br label %137
77: ; preds = %71
%78 = load i32*, i32** getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i32 0, i32 0)
%79 = getelementptr inbounds i32, i32* %78, i64 3
%80 = load i32, i32* %79
%81 = icmp slt i32 %80, 70
br i1 %81, label %82, label %83
82: ; preds = %77
br label %137
83: ; preds = %77
%84 = load i32, i32* %11
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %84)
%86 = load i32, i32* %11
%87 = icmp sge i32 %86, 0
br i1 %87, label %88, label %136
88: ; preds = %83
%89 = load i32, i32* %4
%90 = load i64, i64* %10
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %89, i64 %90)
store i32 0, i32* %12
br label %92
92: ; preds = %104, %88
%93 = load i32, i32* %12
%94 = sext i32 %93 to i64
%95 = load i64, i64* %10
%96 = icmp ult i64 %94, %95
br i1 %96, label %97, label %107
97: ; preds = %92
%98 = load i32, i32* %12
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [16 x i8], [16 x i8]* @main.ustr, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = zext i8 %101 to i32
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %102)
br label %104
104: ; preds = %97
%105 = load i32, i32* %12
%106 = add nsw i32 %105, 1
store i32 %106, i32* %12
br label %92
107: ; preds = %92
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%109 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i32 0, i32 3)
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %109)
%111 = load i32*, i32** %2
%112 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i32 0, i32 3)
%113 = call i8* @XGetAtomName(i32* %111, i32 %112)
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i8* %113)
%115 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i32 0, i32 1)
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %115)
%117 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i32 0, i32 2)
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0), i32 %117)
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
store i32 0, i32* %12
br label %120
120: ; preds = %131, %107
%121 = load i32, i32* %12
%122 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i32 0, i32 2)
%123 = icmp slt i32 %121, %122
br i1 %123, label %124, label %134
124: ; preds = %120
%125 = load i32*, i32** getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i32 0, i32 0)
%126 = load i32, i32* %12
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i32, i32* %125, i64 %127
%129 = load i32, i32* %128
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %129)
br label %131
131: ; preds = %124
%132 = load i32, i32* %12
%133 = add nsw i32 %132, 1
store i32 %133, i32* %12
br label %120
134: ; preds = %120
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %140
136: ; preds = %83
br label %137
137: ; preds = %136, %82, %76, %70, %51
%138 = load i32, i32* %4
%139 = add nsw i32 %138, 1
store i32 %139, i32* %4
br label %42
140: ; preds = %134, %42
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32*, i32, i32, i32 }
@LC_ALL = global i32 0
@.str = [12 x i8] c"ar_IN.UTF-8\00"
@.str.1 = [17 x i8] c"en_AU.ISO-8859-1\00"
@.str.2 = [12 x i8] c"display %p\0A\00"
@main.ustr = internal global [16 x i8] zeroinitializer
@main.ulist = internal global [2 x i8*] zeroinitializer
@main.text_prop = internal global %struct.TYPE_5__ zeroinitializer
@.str.3 = [6 x i8] c"utf-8\00"
@.str.4 = [9 x i8] c"utf-32le\00"
@.str.5 = [11 x i8] c"iconv_open\00"
@.str.6 = [9 x i8] c"iret %u\0A\00"
@XCompoundTextStyle = global i32 0
@.str.7 = [8 x i8] c"ret %d\0A\00"
@.str.8 = [26 x i8] c"ucs 0x%04X ustr [len %u] \00"
@.str.9 = [6 x i8] c" %02X\00"
@.str.11 = [19 x i8] c"text encoding %lu\0A\00"
@.str.12 = [18 x i8] c"text encoding %s\0A\00"
@.str.13 = [16 x i8] c"text format %d\0A\00"
@.str.14 = [17 x i8] c"text nitems %lu\0A\00"
@.str.15 = [13 x i8] c"text value: \00"
@Success = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = load i32, i32* @LC_ALL
%7 = tail call i32 @setlocale(i32 %6, i8* null)
%8 = load i32, i32* @LC_ALL
%9 = tail call i32 @setlocale(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @LC_ALL
%11 = tail call i32 @setlocale(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32* @XOpenDisplay(i32* null)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %12)
%14 = bitcast i32* %1 to i8*
%15 = bitcast i8** %2 to i8*
%16 = bitcast i8** %3 to i8*
%17 = bitcast i64* %4 to i8*
%18 = bitcast i64* %5 to i8*
%19 = tail call i64 @iconv_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i64 %19, -1
br i1 %20, label %23, label %21
21: ; preds = %0
%22 = bitcast i8** %2 to i32**
store i32 256, i32* %1
br label %26
23: ; preds = %0
%24 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%25 = tail call i32 (...) @abort()
unreachable
26: ; preds = %21, %87
store i32* %1, i32** %22
store i64 4, i64* %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.ustr, i64 0, i64 0), i8** %3
store i64 15, i64* %5
%27 = call i64 @iconv(i64 %19, i8** %2, i64* %4, i8** %3, i64* %5)
switch i64 %27, label %28 [
i64 -1, label %87
i64 0, label %31
]
28: ; preds = %26
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 %27)
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = ptrtoint i8* %32 to i64
%34 = sub i64 %33, ptrtoint ([16 x i8]* @main.ustr to i64)
%35 = getelementptr inbounds [16 x i8], [16 x i8]* @main.ustr, i64 0, i64 %34
store i8 0, i8* %35
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.ustr, i64 0, i64 0), i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @main.ulist, i64 0, i64 0)
%36 = load i32, i32* @XCompoundTextStyle
%37 = call i32 @Xutf8TextListToTextProperty(i32* %12, i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @main.ulist, i64 0, i64 0), i32 1, i32 %36, %struct.TYPE_5__* @main.text_prop)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %87
39: ; preds = %31
%40 = load i32*, i32** getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i64 0, i32 0)
%41 = getelementptr inbounds i32, i32* %40, i64 1
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 36
br i1 %43, label %44, label %87
44: ; preds = %39
%45 = getelementptr inbounds i32, i32* %40, i64 3
%46 = load i32, i32* %45
%47 = icmp slt i32 %46, 70
br i1 %47, label %87, label %48
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 0)
%50 = load i32, i32* %1
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %50, i64 %34)
%52 = icmp eq i64 %34, 0
br i1 %52, label %61, label %53
53: ; preds = %48, %53
%54 = phi i64 [ %59, %53 ], [ 0, %48 ]
%55 = getelementptr inbounds [16 x i8], [16 x i8]* @main.ustr, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %57)
%59 = add nuw i64 %54, 1
%60 = icmp eq i64 %59, %34
br i1 %60, label %61, label %53
61: ; preds = %53, %48
%62 = call i32 @putchar(i32 10)
%63 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i64 0, i32 3)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %63)
%65 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i64 0, i32 3)
%66 = call i8* @XGetAtomName(i32* %12, i32 %65)
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i8* %66)
%68 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i64 0, i32 1)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %68)
%70 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i64 0, i32 2)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.14, i64 0, i64 0), i32 %70)
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%73 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i64 0, i32 2)
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %85
75: ; preds = %61, %75
%76 = phi i64 [ %81, %75 ], [ 0, %61 ]
%77 = load i32*, i32** getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i64 0, i32 0)
%78 = getelementptr inbounds i32, i32* %77, i64 %76
%79 = load i32, i32* %78
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 %79)
%81 = add nuw nsw i64 %76, 1
%82 = load i32, i32* getelementptr inbounds (%struct.TYPE_5__, %struct.TYPE_5__* @main.text_prop, i64 0, i32 2)
%83 = sext i32 %82 to i64
%84 = icmp slt i64 %81, %83
br i1 %84, label %75, label %85
85: ; preds = %75, %61
%86 = call i32 @putchar(i32 10)
br label %91
87: ; preds = %26, %44, %39, %31
%88 = load i32, i32* %1
%89 = add nsw i32 %88, 1
store i32 %89, i32* %1
%90 = icmp slt i32 %88, 192941
br i1 %90, label %26, label %91
91: ; preds = %87, %85
ret i32 0
}