#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 */

/* Type definitions */

/* Variables and functions */
char *strchr(char const *, int);
int ibmgfx(int ch) {
  const char *vt100 = "lmkjnqxtuvwah~-";
  const char *cp437 = "\xDA\xC0\xBF\xD9\xC5\xC4\xB3"
                      "\xC3\xB4\xC1\xC2\xB1\xB0\xFA\x18";
  char *p;
  if (ch & 0x100) {
    ch ^= 0x100;
    p = strchr(vt100, ch);
    if (p)
      return cp437[p - vt100];
  }
  return ch;
}


x86 assembly (clang, -O0):
<ibmgfx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    0xede(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xee3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
and    $0x100,%eax
cmp    $0x0,%eax
je     1188 <ibmgfx+0x78>
mov    -0x8(%rbp),%eax
xor    $0x100,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1183 <ibmgfx+0x73>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <ibmgfx+0x7e>
jmp    1188 <ibmgfx+0x78>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibmgfx>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
test   $0x100,%edi
je     114d <ibmgfx+0x3d>
xor    $0x100,%ebx
lea    0xed5(%rip),%r14
mov    $0x10,%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <memchr@plt>
test   %rax,%rax
je     114d <ibmgfx+0x3d>
sub    %r14,%rax
lea    0xec7(%rip),%rcx
movsbl (%rax,%rcx,1),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"lmkjnqxtuvwah~-\00"
@.str.1 = [16 x i8] c"\DA\C0\BF\D9\C5\C4\B3\C3\B4\C1\C2\B1\B0\FA\18\00"
define i32 @ibmgfx(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %5
%7 = load i32, i32* %3
%8 = and i32 %7, 256
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %1
%11 = load i32, i32* %3
%12 = xor i32 %11, 256
store i32 %12, i32* %3
%13 = load i8*, i8** %4
%14 = load i32, i32* %3
%15 = call i8* @strchr(i8* %13, i32 %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %28
18: ; preds = %10
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = load i8*, i8** %4
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = getelementptr inbounds i8, i8* %19, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
store i32 %27, i32* %2
br label %31
28: ; preds = %10
br label %29
29: ; preds = %28, %1
%30 = load i32, i32* %3
store i32 %30, i32* %2
br label %31
31: ; preds = %29, %18
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [16 x i8] c"lmkjnqxtuvwah~-\00"
@.str.1 = [16 x i8] c"\DA\C0\BF\D9\C5\C4\B3\C3\B4\C1\C2\B1\B0\FA\18\00"
define i32 @ibmgfx(i32 %0) {
%2 = and i32 %0, 256
%3 = icmp eq i32 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = xor i32 %0, 256
%6 = tail call i8* @memchr(i8* dereferenceable(16) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5, i64 16)
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = ptrtoint i8* %6 to i64
%10 = sub i64 %9, ptrtoint ([16 x i8]* @.str to i64)
%11 = getelementptr inbounds [16 x i8], [16 x i8]* @.str.1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
br label %14
14: ; preds = %1, %4, %8
%15 = phi i32 [ %13, %8 ], [ %5, %4 ], [ %0, %1 ]
ret i32 %15
}