#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned short *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
                int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printchr16(int, int, unsigned short *, unsigned char **);
int strlen(unsigned char *);
int main() {
  unsigned char chr[16][2];
  unsigned char teststr[] = {0xd6, 0xf7, 0xb2, 0xbb, 0xd4,
                             0xda, 0xba, 0xf5, '\0'};
  int len = strlen(teststr);
  FILE *HzK = fopen("HZK16", "rb");
  if (HzK == NULL) {
    perror("fopen error\n");
    exit(1);
  }
  int fd_fb = open("/dev/fb0", O_RDWR);
  unsigned short *fb = (unsigned short *)mmap(
      0, 240 * 320 * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
  if (fb == MAP_FAILED) {
    perror("mmap error\n");
    exit(1);
  }
  int i;
  for (i = 0; i < len; i += 2) {
    int x = teststr[i] - 0xa0;
    int y = teststr[i + 1] - 0xa0;
    fseek(HzK, (94 * (x - 1) + (y - 1)) * 32, SEEK_SET);
    fread(chr, 32, 1, HzK);
    printchr16(90, 5 + 8 * i, fb, chr);
  }
  fclose(HzK);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe4a(%rip),%rax
mov    %rax,-0x39(%rbp)
mov    0xe48(%rip),%al
mov    %al,-0x31(%rbp)
lea    -0x39(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x40(%rbp)
lea    0xe33(%rip),%rdi
lea    0xe32(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1207 <main+0x67>
lea    0xe1a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
lea    0xe08(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x4c(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
mov    0x2d91(%rip),%rax
or     (%rax),%edx
mov    0x2db0(%rip),%rax
mov    (%rax),%ecx
mov    -0x4c(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x25800,%esi
mov    %r9d,%edi
call   1060 <mmap@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    0x2d5b(%rip),%rcx
cmp    (%rcx),%rax
jne    127c <main+0xdc>
lea    0xdbb(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    131b <main+0x17b>
movslq -0x5c(%rbp),%rax
movzbl -0x39(%rbp,%rax,1),%eax
sub    $0xa0,%eax
mov    %eax,-0x60(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
cltq
movzbl -0x39(%rbp,%rax,1),%eax
sub    $0xa0,%eax
mov    %eax,-0x64(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%eax
sub    $0x1,%eax
imul   $0x5e,%eax,%esi
mov    -0x64(%rbp),%eax
sub    $0x1,%eax
add    %eax,%esi
shl    $0x5,%esi
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
lea    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rcx
mov    $0x20,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x5c(%rbp),%esi
shl    $0x3,%esi
add    $0x5,%esi
mov    -0x58(%rbp),%rdx
lea    -0x30(%rbp),%rcx
mov    $0x5a,%edi
call   10b0 <printchr16@plt>
mov    -0x5c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x5c(%rbp)
jmp    1283 <main+0xe3>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movabs $0xf5badad4bbb2f7d6,%rax
da ba f5
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
mov    %rsp,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xe36(%rip),%rdi
lea    0xe35(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12d4 <main+0x134>
mov    %rax,%r13
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe24(%rip),%rdi
call   1080 <open@plt>
mov    0x2df1(%rip),%rcx
mov    0x2db2(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2dcf(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    $0x25800,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%r15
mov    0x2d81(%rip),%rax
cmp    %r15,(%rax)
je     12dd <main+0x13d>
test   %r14d,%r14d
jle    12bb <main+0x11b>
mov    $0x5,%ebp
xor    %ebx,%ebx
lea    0x10(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%rbx,1),%eax
movzbl 0x1(%rsp,%rbx,1),%ecx
imul   $0x5e,%eax,%esi
add    %ecx,%esi
shl    $0x5,%esi
add    $0xfff88820,%esi
mov    0x2d4a(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
call   1070 <fseek@plt>
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    $0x5a,%edi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   10b0 <printchr16@plt>
add    $0x2,%rbx
add    $0x10,%ebp
cmp    %ebx,%r14d
jg     1260 <main+0xc0>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd37(%rip),%rdi
jmp    12e4 <main+0x144>
lea    0xd44(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.main.teststr = [9 x i8] c"\D6\F7\B2\BB\D4\DA\BA\F5\00"
@.str = [6 x i8] c"HZK16\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"fopen error\0A\00"
@.str.3 = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i16* null
@.str.4 = [12 x i8] c"mmap error\0A\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x [2 x i8]]
%3 = alloca [9 x i8]
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i16*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = bitcast [9 x i8]* %3 to i8*
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %4
%14 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* @PROT_READ
%24 = load i32, i32* @PROT_WRITE
%25 = or i32 %23, %24
%26 = load i32, i32* @MAP_SHARED
%27 = load i32, i32* %6
%28 = call i64 @mmap(i32 0, i32 153600, i32 %25, i32 %26, i32 %27, i32 0)
%29 = inttoptr i64 %28 to i16*
store i16* %29, i16** %7
%30 = load i16*, i16** %7
%31 = load i16*, i16** @MAP_FAILED
%32 = icmp eq i16* %30, %31
br i1 %32, label %33, label %36
33: ; preds = %20
%34 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %20
store i32 0, i32* %8
br label %37
37: ; preds = %76, %36
%38 = load i32, i32* %8
%39 = load i32, i32* %4
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %79
41: ; preds = %37
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = sub nsw i32 %46, 160
store i32 %47, i32* %9
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = sub nsw i32 %53, 160
store i32 %54, i32* %10
%55 = load i32*, i32** %5
%56 = load i32, i32* %9
%57 = sub nsw i32 %56, 1
%58 = mul nsw i32 94, %57
%59 = load i32, i32* %10
%60 = sub nsw i32 %59, 1
%61 = add nsw i32 %58, %60
%62 = mul nsw i32 %61, 32
%63 = load i32, i32* @SEEK_SET
%64 = call i32 @fseek(i32* %55, i32 %62, i32 %63)
%65 = getelementptr inbounds [16 x [2 x i8]], [16 x [2 x i8]]* %2, i64 0, i64 0
%66 = bitcast [2 x i8]* %65 to i8**
%67 = load i32*, i32** %5
%68 = call i32 @fread(i8** %66, i32 32, i32 1, i32* %67)
%69 = load i32, i32* %8
%70 = mul nsw i32 8, %69
%71 = add nsw i32 5, %70
%72 = load i16*, i16** %7
%73 = getelementptr inbounds [16 x [2 x i8]], [16 x [2 x i8]]* %2, i64 0, i64 0
%74 = bitcast [2 x i8]* %73 to i8**
%75 = call i32 @printchr16(i32 90, i32 %71, i16* %72, i8** %74)
br label %76
76: ; preds = %41
%77 = load i32, i32* %8
%78 = add nsw i32 %77, 2
store i32 %78, i32* %8
br label %37
79: ; preds = %37
%80 = load i32*, i32** %5
%81 = call i32 @fclose(i32* %80)
ret i32 0
}

LLVM IR (-O2):
@__const.main.teststr = [9 x i8] c"\D6\F7\B2\BB\D4\DA\BA\F5\00"
@.str = [6 x i8] c"HZK16\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [13 x i8] c"fopen error\0A\00"
@.str.3 = [9 x i8] c"/dev/fb0\00"
@O_RDWR = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i16* null
@.str.4 = [12 x i8] c"mmap error\0A\00"
@SEEK_SET = global i32 0
define i32 @main() {
%1 = alloca [16 x [2 x i8]]
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [16 x [2 x i8]], [16 x [2 x i8]]* %1, i64 0, i64 0, i64 0
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @PROT_READ
%15 = load i32, i32* @PROT_WRITE
%16 = or i32 %15, %14
%17 = load i32, i32* @MAP_SHARED
%18 = call i64 @mmap(i32 0, i32 153600, i32 %16, i32 %17, i32 %13, i32 0)
%19 = inttoptr i64 %18 to i16*
%20 = load i16*, i16** @MAP_FAILED
%21 = icmp eq i16* %20, %19
br i1 %21, label %26, label %22
22: ; preds = %11
%23 = icmp sgt i32 %5, 0
br i1 %23, label %24, label %52
24: ; preds = %22
%25 = bitcast [16 x [2 x i8]]* %1 to i8**
br label %29
26: ; preds = %11
%27 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %24, %29
%30 = phi i64 [ 0, %24 ], [ %49, %29 ]
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = or i64 %30, 1
%35 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = mul nuw nsw i32 %33, 94
%39 = add nuw nsw i32 %38, %37
%40 = shl nuw nsw i32 %39, 5
%41 = add nsw i32 %40, -489440
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @fseek(i32* %6, i32 %41, i32 %42)
%44 = call i32 @fread(i8** %25, i32 32, i32 1, i32* %6)
%45 = trunc i64 %30 to i32
%46 = shl nsw i32 %45, 3
%47 = or i32 %46, 5
%48 = call i32 @printchr16(i32 90, i32 %47, i16* %19, i8** %25)
%49 = add nuw i64 %30, 2
%50 = trunc i64 %49 to i32
%51 = icmp sgt i32 %5, %50
br i1 %51, label %29, label %52
52: ; preds = %29, %22
%53 = call i32 @fclose(i32* %6)
ret i32 0
}