#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 */
int /*<<< orphan*/ weed_memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ weed_memset(unsigned char *, int, int);
void fill_line(int fontwidth, unsigned char *src, unsigned char *dst,
               unsigned char *fillval, unsigned short fontrow, int type) {
  register int i;
  for (i = fontwidth - 1; i >= 0; i--) {
    switch (type) {
    case 0:
      if (fontrow & (1 << i))
        weed_memcpy(dst, src, 3);
      else
        weed_memset(dst, 0, 3);
      src += 3;
      break;
    case 1:
      if (fontrow & (1 << i))
        weed_memset(dst, 255, 3);
      else
        weed_memset(dst, 0, 3);
      break;
    case 2:
    case 3:
      if (fontrow & (1 << i))
        weed_memcpy(dst, fillval, 3);
      else
        weed_memset(dst, 0, 3);
      break;
    }
    dst += 3;
  }
}


x86 assembly (clang, -O0):
<fill_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8w,%ax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %ax,-0x22(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     128a <fill_line+0x16a>
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
test   %eax,%eax
je     118e <fill_line+0x6e>
jmp    1169 <fill_line+0x49>
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
je     11e1 <fill_line+0xc1>
jmp    117a <fill_line+0x5a>
mov    -0x30(%rbp),%eax
add    $0xfffffffe,%eax
sub    $0x2,%eax
jb     1229 <fill_line+0x109>
jmp    1270 <fill_line+0x150>
movzwl -0x22(%rbp),%eax
mov    -0x2c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11c0 <fill_line+0xa0>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3,%edx
call   1030 <weed_memcpy@plt>
jmp    11d0 <fill_line+0xb0>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <weed_memset@plt>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    1270 <fill_line+0x150>
movzwl -0x22(%rbp),%eax
mov    -0x2c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1214 <fill_line+0xf4>
mov    -0x18(%rbp),%rdi
mov    $0xff,%esi
mov    $0x3,%edx
call   1040 <weed_memset@plt>
jmp    1224 <fill_line+0x104>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <weed_memset@plt>
jmp    1270 <fill_line+0x150>
movzwl -0x22(%rbp),%eax
mov    -0x2c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     125b <fill_line+0x13b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x3,%edx
call   1030 <weed_memcpy@plt>
jmp    126b <fill_line+0x14b>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <weed_memset@plt>
jmp    1270 <fill_line+0x150>
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    114c <fill_line+0x2c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
test   %edi,%edi
jle    11e3 <fill_line+0xc3>
mov    %r9d,%r15d
mov    %rdx,%r13
mov    %rsi,%r12
mov    %edi,%ebx
movzwl %r8w,%ebp
add    $0x1,%ebx
lea    -0x2(%r15),%r14d
jmp    1172 <fill_line+0x52>
nop
bt     %eax,%ebp
jae    11c0 <fill_line+0xa0>
mov    %r13,%rdi
mov    (%rsp),%rsi
mov    $0x3,%edx
call   1030 <weed_memcpy@plt>
add    $0x3,%r13
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jbe    11e3 <fill_line+0xc3>
lea    -0x2(%rbx),%eax
cmp    $0x2,%r14d
jb     1150 <fill_line+0x30>
cmp    $0x1,%r15d
je     11b0 <fill_line+0x90>
test   %r15d,%r15d
jne    1166 <fill_line+0x46>
mov    %r13,%rdi
bt     %eax,%ebp
jae    11d1 <fill_line+0xb1>
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <weed_memcpy@plt>
add    $0x3,%r12
jmp    1166 <fill_line+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
bt     %eax,%ebp
jae    11c0 <fill_line+0xa0>
mov    %r13,%rdi
mov    $0xff,%esi
jmp    11c5 <fill_line+0xa5>
nop
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <weed_memset@plt>
jmp    1166 <fill_line+0x46>
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <weed_memset@plt>
add    $0x3,%r12
jmp    1166 <fill_line+0x46>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fill_line(i32 %0, i8* %1, i8* %2, i8* %3, i16 zeroext %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i16
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i16 %4, i16* %11
store i32 %5, i32* %12
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %13
br label %16
16: ; preds = %70, %6
%17 = load i32, i32* %13
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %73
19: ; preds = %16
%20 = load i32, i32* %12
switch i32 %20, label %67 [
i32 0, label %21
i32 1, label %38
i32 2, label %52
i32 3, label %52
]
21: ; preds = %19
%22 = load i16, i16* %11
%23 = zext i16 %22 to i32
%24 = load i32, i32* %13
%25 = shl i32 1, %24
%26 = and i32 %23, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = load i8*, i8** %9
%30 = load i8*, i8** %8
%31 = call i32 @weed_memcpy(i8* %29, i8* %30, i32 3)
br label %35
32: ; preds = %21
%33 = load i8*, i8** %9
%34 = call i32 @weed_memset(i8* %33, i32 0, i32 3)
br label %35
35: ; preds = %32, %28
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i64 3
store i8* %37, i8** %8
br label %67
38: ; preds = %19
%39 = load i16, i16* %11
%40 = zext i16 %39 to i32
%41 = load i32, i32* %13
%42 = shl i32 1, %41
%43 = and i32 %40, %42
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load i8*, i8** %9
%47 = call i32 @weed_memset(i8* %46, i32 255, i32 3)
br label %51
48: ; preds = %38
%49 = load i8*, i8** %9
%50 = call i32 @weed_memset(i8* %49, i32 0, i32 3)
br label %51
51: ; preds = %48, %45
br label %67
52: ; preds = %19, %19
%53 = load i16, i16* %11
%54 = zext i16 %53 to i32
%55 = load i32, i32* %13
%56 = shl i32 1, %55
%57 = and i32 %54, %56
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %52
%60 = load i8*, i8** %9
%61 = load i8*, i8** %10
%62 = call i32 @weed_memcpy(i8* %60, i8* %61, i32 3)
br label %66
63: ; preds = %52
%64 = load i8*, i8** %9
%65 = call i32 @weed_memset(i8* %64, i32 0, i32 3)
br label %66
66: ; preds = %63, %59
br label %67
67: ; preds = %19, %66, %51, %35
%68 = load i8*, i8** %9
%69 = getelementptr inbounds i8, i8* %68, i64 3
store i8* %69, i8** %9
br label %70
70: ; preds = %67
%71 = load i32, i32* %13
%72 = add nsw i32 %71, -1
store i32 %72, i32* %13
br label %16
73: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @fill_line(i32 %0, i8* %1, i8* %2, i8* %3, i16 zeroext %4, i32 %5) {
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %45
8: ; preds = %6
%9 = zext i16 %4 to i32
br label %10
10: ; preds = %8, %41
%11 = phi i32 [ %0, %8 ], [ %14, %41 ]
%12 = phi i8* [ %1, %8 ], [ %42, %41 ]
%13 = phi i8* [ %2, %8 ], [ %43, %41 ]
%14 = add nsw i32 %11, -1
switch i32 %5, label %41 [
i32 0, label %15
i32 1, label %25
i32 2, label %33
i32 3, label %33
]
15: ; preds = %10
%16 = shl nuw i32 1, %14
%17 = and i32 %16, %9
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @weed_memcpy(i8* %13, i8* %12, i32 3)
br label %23
21: ; preds = %15
%22 = tail call i32 @weed_memset(i8* %13, i32 0, i32 3)
br label %23
23: ; preds = %21, %19
%24 = getelementptr inbounds i8, i8* %12, i64 3
br label %41
25: ; preds = %10
%26 = shl nuw i32 1, %14
%27 = and i32 %26, %9
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = tail call i32 @weed_memset(i8* %13, i32 255, i32 3)
br label %41
31: ; preds = %25
%32 = tail call i32 @weed_memset(i8* %13, i32 0, i32 3)
br label %41
33: ; preds = %10, %10
%34 = shl nuw i32 1, %14
%35 = and i32 %34, %9
%36 = icmp eq i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = tail call i32 @weed_memcpy(i8* %13, i8* %3, i32 3)
br label %41
39: ; preds = %33
%40 = tail call i32 @weed_memset(i8* %13, i32 0, i32 3)
br label %41
41: ; preds = %37, %39, %29, %31, %10, %23
%42 = phi i8* [ %12, %10 ], [ %12, %37 ], [ %12, %39 ], [ %12, %29 ], [ %12, %31 ], [ %24, %23 ]
%43 = getelementptr inbounds i8, i8* %13, i64 3
%44 = icmp ugt i32 %11, 1
br i1 %44, label %10, label %45
45: ; preds = %41, %6
ret void
}