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

/* Variables and functions */
int /*<<< orphan*/ blend_case1(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int);
int /*<<< orphan*/ blend_case2(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ blend_case3(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int /*<<< orphan*/ *, int);
int /*<<< orphan*/ blend_case5(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int /*<<< orphan*/ *, int);
int /*<<< orphan*/ blend_case6(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ blend_case7(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int, int);
void composite_line_yuv_sse2_simple(uint8_t *dest, uint8_t *src, int width,
                                    uint8_t *src_a, uint8_t *dest_a,
                                    int weight) {
  weight >>= 8;
  int cond = ((dest_a != NULL) ? 4 : 0) + ((src_a != NULL) ? 2 : 0) +
             ((weight != 256) ? 1 : 0);
  switch (cond) {
  case 0:
    memcpy(dest, src, 2 * width);
    break;
  case 1:
    blend_case1(dest, src, width, weight);
    break;
  case 2:
    blend_case2(dest, src, width, src_a);
    break;
  case 3:
    blend_case3(dest, src, width, src_a, weight);
    break;
  case 4:
    memcpy(dest, src, 2 * width);
    memset(dest_a, 0xFF, width);
    break;
  case 5:
    blend_case5(dest, src, width, dest_a, weight);
    break;
  case 6:
    blend_case6(dest, src, width, src_a, dest_a);
    break;
  case 7:
    blend_case7(dest, src, width, src_a, dest_a, weight);
    break;
  };
}


x86 assembly (clang, -O0):
<composite_line_yuv_sse2_simple>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%eax
mov    -0x20(%rbp),%rcx
test   %rcx,%rcx
setne  %cl
movzbl %cl,%edx
add    %edx,%edx
mov    %eax,%ecx
mov    %edx,%eax
lea    (%rax,%rcx,4),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x100,%ecx
setne  %cl
movzbl %cl,%ecx
or     %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x7,%rax
ja     12e9 <composite_line_yuv_sse2_simple+0x169>
mov    -0x38(%rbp),%rax
lea    0xe05(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
call   1080 <memcpy@plt>
jmp    12e9 <composite_line_yuv_sse2_simple+0x169>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1040 <blend_case1@plt>
jmp    12e9 <composite_line_yuv_sse2_simple+0x169>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1090 <blend_case2@plt>
jmp    12e9 <composite_line_yuv_sse2_simple+0x169>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1070 <blend_case3@plt>
jmp    12e9 <composite_line_yuv_sse2_simple+0x169>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
call   1080 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0xff,%esi
call   1030 <memset@plt>
jmp    12e9 <composite_line_yuv_sse2_simple+0x169>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1060 <blend_case5@plt>
jmp    12e9 <composite_line_yuv_sse2_simple+0x169>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   10a0 <blend_case6@plt>
jmp    12e9 <composite_line_yuv_sse2_simple+0x169>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1050 <blend_case7@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<composite_line_yuv_sse2_simple>:
push   %r14
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %edx,%r14d
xor    %eax,%eax
test   %r8,%r8
setne  %al
xor    %edx,%edx
test   %rcx,%rcx
setne  %dl
sar    $0x8,%r9d
add    %edx,%edx
lea    (%rdx,%rax,4),%eax
xor    %edx,%edx
cmp    $0x100,%r9d
setne  %dl
or     %eax,%edx
lea    0xe48(%rip),%rax
movslq (%rax,%rdx,4),%rdx
add    %rax,%rdx
jmp    *%rdx
add    %r14d,%r14d
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <memcpy@plt>
mov    %r14d,%edx
mov    %r9d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <blend_case1@plt>
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <blend_case2@plt>
mov    %r14d,%edx
mov    %r9d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <blend_case3@plt>
lea    (%r14,%r14,1),%edx
call   1080 <memcpy@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <memset@plt>
mov    %r14d,%edx
mov    %rbx,%rcx
mov    %r9d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <blend_case5@plt>
mov    %r14d,%edx
mov    %rbx,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <blend_case6@plt>
mov    %r14d,%edx
mov    %rbx,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <blend_case7@plt>

LLVM IR (-O0):
define void @composite_line_yuv_sse2_simple(i32* %0, i32* %1, i32 %2, i32* %3, i32* %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 %5, i32* %12
%14 = load i32, i32* %12
%15 = ashr i32 %14, 8
store i32 %15, i32* %12
%16 = load i32*, i32** %11
%17 = icmp ne i32* %16, null
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 4, i32 0
%20 = load i32*, i32** %10
%21 = icmp ne i32* %20, null
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 2, i32 0
%24 = add nsw i32 %19, %23
%25 = load i32, i32* %12
%26 = icmp ne i32 %25, 256
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1, i32 0
%29 = add nsw i32 %24, %28
store i32 %29, i32* %13
%30 = load i32, i32* %13
switch i32 %30, label %87 [
i32 0, label %31
i32 1, label %37
i32 2, label %43
i32 3, label %49
i32 4, label %56
i32 5, label %65
i32 6, label %72
i32 7, label %79
]
31: ; preds = %6
%32 = load i32*, i32** %7
%33 = load i32*, i32** %8
%34 = load i32, i32* %9
%35 = mul nsw i32 2, %34
%36 = call i32 @memcpy(i32* %32, i32* %33, i32 %35)
br label %87
37: ; preds = %6
%38 = load i32*, i32** %7
%39 = load i32*, i32** %8
%40 = load i32, i32* %9
%41 = load i32, i32* %12
%42 = call i32 @blend_case1(i32* %38, i32* %39, i32 %40, i32 %41)
br label %87
43: ; preds = %6
%44 = load i32*, i32** %7
%45 = load i32*, i32** %8
%46 = load i32, i32* %9
%47 = load i32*, i32** %10
%48 = call i32 @blend_case2(i32* %44, i32* %45, i32 %46, i32* %47)
br label %87
49: ; preds = %6
%50 = load i32*, i32** %7
%51 = load i32*, i32** %8
%52 = load i32, i32* %9
%53 = load i32*, i32** %10
%54 = load i32, i32* %12
%55 = call i32 @blend_case3(i32* %50, i32* %51, i32 %52, i32* %53, i32 %54)
br label %87
56: ; preds = %6
%57 = load i32*, i32** %7
%58 = load i32*, i32** %8
%59 = load i32, i32* %9
%60 = mul nsw i32 2, %59
%61 = call i32 @memcpy(i32* %57, i32* %58, i32 %60)
%62 = load i32*, i32** %11
%63 = load i32, i32* %9
%64 = call i32 @memset(i32* %62, i32 255, i32 %63)
br label %87
65: ; preds = %6
%66 = load i32*, i32** %7
%67 = load i32*, i32** %8
%68 = load i32, i32* %9
%69 = load i32*, i32** %11
%70 = load i32, i32* %12
%71 = call i32 @blend_case5(i32* %66, i32* %67, i32 %68, i32* %69, i32 %70)
br label %87
72: ; preds = %6
%73 = load i32*, i32** %7
%74 = load i32*, i32** %8
%75 = load i32, i32* %9
%76 = load i32*, i32** %10
%77 = load i32*, i32** %11
%78 = call i32 @blend_case6(i32* %73, i32* %74, i32 %75, i32* %76, i32* %77)
br label %87
79: ; preds = %6
%80 = load i32*, i32** %7
%81 = load i32*, i32** %8
%82 = load i32, i32* %9
%83 = load i32*, i32** %10
%84 = load i32*, i32** %11
%85 = load i32, i32* %12
%86 = call i32 @blend_case7(i32* %80, i32* %81, i32 %82, i32* %83, i32* %84, i32 %85)
br label %87
87: ; preds = %6, %79, %72, %65, %56, %49, %43, %37, %31
ret void
}

LLVM IR (-O2):
define void @composite_line_yuv_sse2_simple(i32* %0, i32* %1, i32 %2, i32* %3, i32* %4, i32 %5) {
%7 = ashr i32 %5, 8
%8 = icmp eq i32* %4, null
%9 = select i1 %8, i32 0, i32 4
%10 = icmp eq i32* %3, null
%11 = select i1 %10, i32 0, i32 2
%12 = or i32 %9, %11
%13 = icmp ne i32 %7, 256
%14 = zext i1 %13 to i32
%15 = or i32 %12, %14
switch i32 %15, label %35 [
i32 0, label %16
i32 1, label %19
i32 2, label %21
i32 3, label %23
i32 4, label %25
i32 5, label %29
i32 6, label %31
i32 7, label %33
]
16: ; preds = %6
%17 = shl nsw i32 %2, 1
%18 = tail call i32 @memcpy(i32* %0, i32* %1, i32 %17)
br label %36
19: ; preds = %6
%20 = tail call i32 @blend_case1(i32* %0, i32* %1, i32 %2, i32 %7)
br label %36
21: ; preds = %6
%22 = tail call i32 @blend_case2(i32* %0, i32* %1, i32 %2, i32* %3)
br label %36
23: ; preds = %6
%24 = tail call i32 @blend_case3(i32* %0, i32* %1, i32 %2, i32* %3, i32 %7)
br label %36
25: ; preds = %6
%26 = shl nsw i32 %2, 1
%27 = tail call i32 @memcpy(i32* %0, i32* %1, i32 %26)
%28 = tail call i32 @memset(i32* %4, i32 255, i32 %2)
br label %36
29: ; preds = %6
%30 = tail call i32 @blend_case5(i32* %0, i32* %1, i32 %2, i32* %4, i32 %7)
br label %36
31: ; preds = %6
%32 = tail call i32 @blend_case6(i32* %0, i32* %1, i32 %2, i32* %3, i32* %4)
br label %36
33: ; preds = %6
%34 = tail call i32 @blend_case7(i32* %0, i32* %1, i32 %2, i32* %3, i32* %4, i32 %7)
br label %36
35: ; preds = %6
unreachable
36: ; preds = %33, %31, %29, %25, %23, %21, %19, %16
ret void
}