#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 */
struct font_info {
  int dummy;
};

/* Variables and functions */
unsigned char get_color(char, char, int, struct font_info *);
scalar_t__ is_bottom(unsigned char);
scalar_t__ is_top(unsigned char);
void rasterize_thumb_character(unsigned char ch, int x, int y, char *framebuf,
                               int width, char fgindex, char bgindex,
                               struct font_info *fi) {
  unsigned char color = 0;
  switch (ch) {
  case 0xb0:
    color = get_color(fgindex, bgindex, 3, fi);
    break;
  case 0xb1:
    color = get_color(fgindex, bgindex, 2, fi);
    break;
  case 0xb2:
    color = get_color(fgindex, bgindex, 1, fi);
    break;
  case 0:
  case 255:
  case ' ':
    color = get_color(fgindex, bgindex, 4, fi);
    break;
  default:
    color = get_color(fgindex, bgindex, 0, fi);
    break;
  }
  if (is_top(ch))
    framebuf[(y * 2) * width + x] = color;
  else
    framebuf[(y * 2) * width + x] = bgindex;
  if (is_bottom(ch))
    framebuf[(y * 2 + 1) * width + x] = color;
  else
    framebuf[(y * 2 + 1) * width + x] = bgindex;
}


x86 assembly (clang, -O0):
<rasterize_thumb_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r9b,%al
mov    0x18(%rbp),%r9
mov    0x10(%rbp),%r9b
mov    %dil,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
movb   $0x0,-0x1e(%rbp)
movzbl -0x1(%rbp),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     1239 <rasterize_thumb_character+0x109>
jmp    1170 <rasterize_thumb_character+0x40>
mov    -0x24(%rbp),%eax
sub    $0x20,%eax
je     1239 <rasterize_thumb_character+0x109>
jmp    1181 <rasterize_thumb_character+0x51>
mov    -0x24(%rbp),%eax
sub    $0xb0,%eax
je     11cd <rasterize_thumb_character+0x9d>
jmp    1194 <rasterize_thumb_character+0x64>
mov    -0x24(%rbp),%eax
sub    $0xb1,%eax
je     11f1 <rasterize_thumb_character+0xc1>
jmp    11a7 <rasterize_thumb_character+0x77>
mov    -0x24(%rbp),%eax
sub    $0xb2,%eax
je     1215 <rasterize_thumb_character+0xe5>
jmp    11ba <rasterize_thumb_character+0x8a>
mov    -0x24(%rbp),%eax
sub    $0xff,%eax
je     1239 <rasterize_thumb_character+0x109>
jmp    125d <rasterize_thumb_character+0x12d>
mov    -0x1d(%rbp),%sil
mov    0x10(%rbp),%al
mov    0x18(%rbp),%rcx
mov    $0x3,%edx
movsbl %sil,%edi
movsbl %al,%esi
call   1040 <get_color@plt>
mov    %al,-0x1e(%rbp)
jmp    1279 <rasterize_thumb_character+0x149>
mov    -0x1d(%rbp),%sil
mov    0x10(%rbp),%al
mov    0x18(%rbp),%rcx
mov    $0x2,%edx
movsbl %sil,%edi
movsbl %al,%esi
call   1040 <get_color@plt>
mov    %al,-0x1e(%rbp)
jmp    1279 <rasterize_thumb_character+0x149>
mov    -0x1d(%rbp),%sil
mov    0x10(%rbp),%al
mov    0x18(%rbp),%rcx
mov    $0x1,%edx
movsbl %sil,%edi
movsbl %al,%esi
call   1040 <get_color@plt>
mov    %al,-0x1e(%rbp)
jmp    1279 <rasterize_thumb_character+0x149>
mov    -0x1d(%rbp),%sil
mov    0x10(%rbp),%al
mov    0x18(%rbp),%rcx
mov    $0x4,%edx
movsbl %sil,%edi
movsbl %al,%esi
call   1040 <get_color@plt>
mov    %al,-0x1e(%rbp)
jmp    1279 <rasterize_thumb_character+0x149>
mov    -0x1d(%rbp),%sil
mov    0x10(%rbp),%al
mov    0x18(%rbp),%rcx
xor    %edx,%edx
movsbl %sil,%edi
movsbl %al,%esi
call   1040 <get_color@plt>
mov    %al,-0x1e(%rbp)
movzbl -0x1(%rbp),%edi
call   1030 <is_top@plt>
cmp    $0x0,%rax
je     12ab <rasterize_thumb_character+0x17b>
mov    -0x1e(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
imul   -0x1c(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    12c5 <rasterize_thumb_character+0x195>
mov    0x10(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
imul   -0x1c(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movzbl -0x1(%rbp),%edi
call   1050 <is_bottom@plt>
cmp    $0x0,%rax
je     12fa <rasterize_thumb_character+0x1ca>
mov    -0x1e(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
imul   -0x1c(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1317 <rasterize_thumb_character+0x1e7>
mov    0x10(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
imul   -0x1c(%rbp),%ecx
add    -0x8(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rasterize_thumb_character>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,0x4(%rsp)
mov    %rcx,0x10(%rsp)
mov    %edx,%r12d
mov    %esi,(%rsp)
mov    %edi,%ebx
mov    0x58(%rsp),%rcx
mov    0x50(%rsp),%al
cmp    $0xfe,%bl
jg     1174 <rasterize_thumb_character+0x44>
cmp    $0xb0,%bl
je     1196 <rasterize_thumb_character+0x66>
cmp    $0xb1,%bl
je     119d <rasterize_thumb_character+0x6d>
cmp    $0xb2,%bl
jne    11a4 <rasterize_thumb_character+0x74>
mov    $0x1,%edx
jmp    11a6 <rasterize_thumb_character+0x76>
lea    0x1(%rbx),%edx
cmp    $0x21,%dl
ja     11a4 <rasterize_thumb_character+0x74>
movzbl %dl,%edx
movabs $0x200000003,%rsi
bt     %rdx,%rsi
jae    11a4 <rasterize_thumb_character+0x74>
mov    $0x4,%edx
jmp    11a6 <rasterize_thumb_character+0x76>
mov    $0x3,%edx
jmp    11a6 <rasterize_thumb_character+0x76>
mov    $0x2,%edx
jmp    11a6 <rasterize_thumb_character+0x76>
xor    %edx,%edx
movsbl %r9b,%edi
movsbl %al,%ebp
mov    %ebp,%esi
call   1040 <get_color@plt>
mov    %eax,%r14d
movzbl %bl,%r15d
mov    %r15d,%edi
call   1030 <is_top@plt>
test   %rax,%rax
movzbl %r14b,%ebx
movzbl %bpl,%r14d
mov    %ebx,%eax
cmove  %r14d,%eax
lea    (%r12,%r12,1),%ecx
mov    %r12,0x8(%rsp)
mov    0x4(%rsp),%r12d
imul   %r12d,%ecx
mov    (%rsp),%r13d
add    %r13d,%ecx
movslq %ecx,%rcx
mov    0x10(%rsp),%rbp
mov    %al,0x0(%rbp,%rcx,1)
mov    %r15d,%edi
call   1050 <is_bottom@plt>
test   %rax,%rax
cmove  %r14d,%ebx
mov    0x8(%rsp),%rax
add    %eax,%eax
add    $0x1,%eax
imul   %r12d,%eax
add    %r13d,%eax
cltq
mov    %bl,0x0(%rbp,%rax,1)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.font_info = type { i32 }
define void @rasterize_thumb_character(i8 zeroext %0, i32 %1, i32 %2, i8* %3, i32 %4, i8 signext %5, i8 signext %6, %struct.font_info* %7) {
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8
%15 = alloca i8
%16 = alloca %struct.font_info*
%17 = alloca i8
store i8 %0, i8* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i8* %3, i8** %12
store i32 %4, i32* %13
store i8 %5, i8* %14
store i8 %6, i8* %15
store %struct.font_info* %7, %struct.font_info** %16
store i8 0, i8* %17
%18 = load i8, i8* %9
%19 = zext i8 %18 to i32
switch i32 %19, label %40 [
i32 176, label %20
i32 177, label %25
i32 178, label %30
i32 0, label %35
i32 255, label %35
i32 32, label %35
]
20: ; preds = %8
%21 = load i8, i8* %14
%22 = load i8, i8* %15
%23 = load %struct.font_info*, %struct.font_info** %16
%24 = call zeroext i8 @get_color(i8 signext %21, i8 signext %22, i32 3, %struct.font_info* %23)
store i8 %24, i8* %17
br label %45
25: ; preds = %8
%26 = load i8, i8* %14
%27 = load i8, i8* %15
%28 = load %struct.font_info*, %struct.font_info** %16
%29 = call zeroext i8 @get_color(i8 signext %26, i8 signext %27, i32 2, %struct.font_info* %28)
store i8 %29, i8* %17
br label %45
30: ; preds = %8
%31 = load i8, i8* %14
%32 = load i8, i8* %15
%33 = load %struct.font_info*, %struct.font_info** %16
%34 = call zeroext i8 @get_color(i8 signext %31, i8 signext %32, i32 1, %struct.font_info* %33)
store i8 %34, i8* %17
br label %45
35: ; preds = %8, %8, %8
%36 = load i8, i8* %14
%37 = load i8, i8* %15
%38 = load %struct.font_info*, %struct.font_info** %16
%39 = call zeroext i8 @get_color(i8 signext %36, i8 signext %37, i32 4, %struct.font_info* %38)
store i8 %39, i8* %17
br label %45
40: ; preds = %8
%41 = load i8, i8* %14
%42 = load i8, i8* %15
%43 = load %struct.font_info*, %struct.font_info** %16
%44 = call zeroext i8 @get_color(i8 signext %41, i8 signext %42, i32 0, %struct.font_info* %43)
store i8 %44, i8* %17
br label %45
45: ; preds = %40, %35, %30, %25, %20
%46 = load i8, i8* %9
%47 = call i64 @is_top(i8 zeroext %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %60
49: ; preds = %45
%50 = load i8, i8* %17
%51 = load i8*, i8** %12
%52 = load i32, i32* %11
%53 = mul nsw i32 %52, 2
%54 = load i32, i32* %13
%55 = mul nsw i32 %53, %54
%56 = load i32, i32* %10
%57 = add nsw i32 %55, %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %51, i64 %58
store i8 %50, i8* %59
br label %71
60: ; preds = %45
%61 = load i8, i8* %15
%62 = load i8*, i8** %12
%63 = load i32, i32* %11
%64 = mul nsw i32 %63, 2
%65 = load i32, i32* %13
%66 = mul nsw i32 %64, %65
%67 = load i32, i32* %10
%68 = add nsw i32 %66, %67
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %62, i64 %69
store i8 %61, i8* %70
br label %71
71: ; preds = %60, %49
%72 = load i8, i8* %9
%73 = call i64 @is_bottom(i8 zeroext %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %87
75: ; preds = %71
%76 = load i8, i8* %17
%77 = load i8*, i8** %12
%78 = load i32, i32* %11
%79 = mul nsw i32 %78, 2
%80 = add nsw i32 %79, 1
%81 = load i32, i32* %13
%82 = mul nsw i32 %80, %81
%83 = load i32, i32* %10
%84 = add nsw i32 %82, %83
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %77, i64 %85
store i8 %76, i8* %86
br label %99
87: ; preds = %71
%88 = load i8, i8* %15
%89 = load i8*, i8** %12
%90 = load i32, i32* %11
%91 = mul nsw i32 %90, 2
%92 = add nsw i32 %91, 1
%93 = load i32, i32* %13
%94 = mul nsw i32 %92, %93
%95 = load i32, i32* %10
%96 = add nsw i32 %94, %95
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %89, i64 %97
store i8 %88, i8* %98
br label %99
99: ; preds = %87, %75
ret void
}

LLVM IR (-O2):
%struct.font_info = type { i32 }
define void @rasterize_thumb_character(i8 zeroext %0, i32 %1, i32 %2, i8* nocapture writeonly %3, i32 %4, i8 signext %5, i8 signext %6, %struct.font_info* %7) {
switch i8 %0, label %12 [
i8 -80, label %13
i8 -79, label %9
i8 -78, label %10
i8 0, label %11
i8 -1, label %11
i8 32, label %11
]
9: ; preds = %8
br label %13
10: ; preds = %8
br label %13
11: ; preds = %8, %8, %8
br label %13
12: ; preds = %8
br label %13
13: ; preds = %8, %12, %11, %10, %9
%14 = phi i32 [ 0, %12 ], [ 4, %11 ], [ 1, %10 ], [ 2, %9 ], [ 3, %8 ]
%15 = tail call zeroext i8 @get_color(i8 signext %5, i8 signext %6, i32 %14, %struct.font_info* %7)
%16 = tail call i64 @is_top(i8 zeroext %0)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i8 %6, i8 %15
%19 = shl nsw i32 %2, 1
%20 = mul nsw i32 %19, %4
%21 = add nsw i32 %20, %1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %3, i64 %22
store i8 %18, i8* %23
%24 = tail call i64 @is_bottom(i8 zeroext %0)
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i8 %6, i8 %15
%27 = shl nsw i32 %2, 1
%28 = or i32 %27, 1
%29 = mul nsw i32 %28, %4
%30 = add nsw i32 %29, %1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %3, i64 %31
store i8 %26, i8* %32
ret void
}