#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 */
unsigned short blend(unsigned short, unsigned char);
void draw_glyph_line(unsigned char *src_alpha, unsigned short color,
                     unsigned short *dst, int len) {
  int i;
  for (i = 0; i < len; i++) {
    unsigned char alpha = src_alpha[i];
    if (alpha) {
      if (alpha == 255)
        dst[i] = color;
      else
        dst[i] = blend(dst[i], 255 - alpha) + blend(color, alpha);
    }
  }
}


x86 assembly (clang, -O0):
<draw_glyph_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e3 <draw_glyph_line+0xd3>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
cmpb   $0x0,-0x21(%rbp)
je     11d0 <draw_glyph_line+0xc0>
movzbl -0x21(%rbp),%eax
cmp    $0xff,%eax
jne    1179 <draw_glyph_line+0x69>
mov    -0xa(%rbp),%dx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    11cb <draw_glyph_line+0xbb>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,2),%cx
movzbl -0x21(%rbp),%edx
mov    $0xff,%eax
sub    %edx,%eax
movzwl %cx,%edi
movzbl %al,%esi
call   1030 <blend@plt>
movzwl %ax,%eax
mov    %eax,-0x28(%rbp)
mov    -0xa(%rbp),%ax
movzwl %ax,%edi
movzbl -0x21(%rbp),%esi
call   1030 <blend@plt>
mov    %ax,%cx
mov    -0x28(%rbp),%eax
movzwl %cx,%ecx
add    %ecx,%eax
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    11d0 <draw_glyph_line+0xc0>
jmp    11d5 <draw_glyph_line+0xc5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1131 <draw_glyph_line+0x21>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_glyph_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,(%rsp)
test   %ecx,%ecx
jle    1187 <draw_glyph_line+0x77>
mov    %rdx,%r12
mov    %rdi,%r13
mov    %ecx,%ebp
xor    %r14d,%r14d
movzwl (%rsp),%eax
mov    %eax,0x4(%rsp)
jmp    1171 <draw_glyph_line+0x61>
nopw   0x0(%rax,%rax,1)
movzwl (%r12,%r14,2),%edi
mov    %r15d,%eax
not    %al
movzbl %al,%esi
call   1030 <blend@plt>
mov    %eax,%ebx
movzbl %r15b,%esi
mov    0x4(%rsp),%edi
call   1030 <blend@plt>
add    %ebx,%eax
mov    %ax,(%r12,%r14,2)
add    $0x1,%r14
cmp    %r14,%rbp
je     1187 <draw_glyph_line+0x77>
movzbl 0x0(%r13,%r14,1),%r15d
test   %r15b,%r15b
je     1168 <draw_glyph_line+0x58>
cmp    $0xff,%r15b
jne    1140 <draw_glyph_line+0x30>
mov    (%rsp),%eax
jmp    1163 <draw_glyph_line+0x53>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @draw_glyph_line(i8* %0, i16 zeroext %1, i16* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i16*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i8* %0, i8** %5
store i16 %1, i16* %6
store i16* %2, i16** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %57, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %60
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %10
%21 = load i8, i8* %10
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %56
23: ; preds = %15
%24 = load i8, i8* %10
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 255
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i16, i16* %6
%29 = load i16*, i16** %7
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i16, i16* %29, i64 %31
store i16 %28, i16* %32
br label %55
33: ; preds = %23
%34 = load i16*, i16** %7
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i16, i16* %34, i64 %36
%38 = load i16, i16* %37
%39 = load i8, i8* %10
%40 = zext i8 %39 to i32
%41 = sub nsw i32 255, %40
%42 = trunc i32 %41 to i8
%43 = call zeroext i16 @blend(i16 zeroext %38, i8 zeroext %42)
%44 = zext i16 %43 to i32
%45 = load i16, i16* %6
%46 = load i8, i8* %10
%47 = call zeroext i16 @blend(i16 zeroext %45, i8 zeroext %46)
%48 = zext i16 %47 to i32
%49 = add nsw i32 %44, %48
%50 = trunc i32 %49 to i16
%51 = load i16*, i16** %7
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i16, i16* %51, i64 %53
store i16 %50, i16* %54
br label %55
55: ; preds = %33, %27
br label %56
56: ; preds = %55, %15
br label %57
57: ; preds = %56
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %11
60: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @draw_glyph_line(i8* nocapture %0, i16 zeroext %1, i16* nocapture %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %24
6: ; preds = %4
%7 = zext i32 %3 to i64
br label %8
8: ; preds = %6, %21
%9 = phi i64 [ 0, %6 ], [ %22, %21 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %14 [
i8 0, label %21
i8 -1, label %12
]
12: ; preds = %8
%13 = getelementptr inbounds i16, i16* %2, i64 %9
store i16 %1, i16* %13
br label %21
14: ; preds = %8
%15 = getelementptr inbounds i16, i16* %2, i64 %9
%16 = load i16, i16* %15
%17 = xor i8 %11, -1
%18 = tail call zeroext i16 @blend(i16 zeroext %16, i8 zeroext %17)
%19 = tail call zeroext i16 @blend(i16 zeroext %1, i8 zeroext %11)
%20 = add i16 %19, %18
store i16 %20, i16* %15
br label %21
21: ; preds = %8, %12, %14
%22 = add nuw nsw i64 %9, 1
%23 = icmp eq i64 %22, %7
br i1 %23, label %24, label %8
24: ; preds = %21, %4
ret void
}