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

/* Variables and functions */
int /*<<< orphan*/ rgb16_to_yuv_scalar(int /*<<< orphan*/ *, void const *,
                                       int const, int const);
int /*<<< orphan*/ rgb8_to_yuv_scalar(int /*<<< orphan*/ *, void const *,
                                      int const, int const);
int color_rgb_to_yuv(int16_t *img_yuv, const void *img_rgb, const int height,
                     const int width, const int bit_channel) {
  if (bit_channel <= 8) {
    rgb8_to_yuv_scalar(img_yuv, img_rgb, height, width);
  } else if (bit_channel <= 16) {
    rgb16_to_yuv_scalar(img_yuv, img_rgb, height, width);
  }
  return 0;
}


x86 assembly (clang, -O0):
<color_rgb_to_yuv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jg     115c <color_rgb_to_yuv+0x3c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <rgb8_to_yuv_scalar@plt>
jmp    117e <color_rgb_to_yuv+0x5e>
cmpl   $0x10,-0x1c(%rbp)
jg     1179 <color_rgb_to_yuv+0x59>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <rgb16_to_yuv_scalar@plt>
jmp    117e <color_rgb_to_yuv+0x5e>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<color_rgb_to_yuv>:
push   %rax
cmp    $0x8,%r8d
jg     112e <color_rgb_to_yuv+0xe>
call   1040 <rgb8_to_yuv_scalar@plt>
jmp    1139 <color_rgb_to_yuv+0x19>
cmp    $0x10,%r8d
ja     1139 <color_rgb_to_yuv+0x19>
call   1030 <rgb16_to_yuv_scalar@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @color_rgb_to_yuv(i32* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%11 = load i32, i32* %10
%12 = icmp sle i32 %11, 8
br i1 %12, label %13, label %19
13: ; preds = %5
%14 = load i32*, i32** %6
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = call i32 @rgb8_to_yuv_scalar(i32* %14, i8* %15, i32 %16, i32 %17)
br label %29
19: ; preds = %5
%20 = load i32, i32* %10
%21 = icmp sle i32 %20, 16
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i32*, i32** %6
%24 = load i8*, i8** %7
%25 = load i32, i32* %8
%26 = load i32, i32* %9
%27 = call i32 @rgb16_to_yuv_scalar(i32* %23, i8* %24, i32 %25, i32 %26)
br label %28
28: ; preds = %22, %19
br label %29
29: ; preds = %28, %13
ret i32 0
}

LLVM IR (-O2):
define i32 @color_rgb_to_yuv(i32* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp slt i32 %4, 9
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @rgb8_to_yuv_scalar(i32* %0, i8* %1, i32 %2, i32 %3)
br label %13
9: ; preds = %5
%10 = icmp ult i32 %4, 17
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @rgb16_to_yuv_scalar(i32* %0, i8* %1, i32 %2, i32 %3)
br label %13
13: ; preds = %9, %11, %7
ret i32 0
}