#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*/ mmx_grayscale_rgb16_inplace(unsigned short *, int);
int /*<<< orphan*/ mmx_grayscale_rgb16_opacity_inplace(unsigned short *,
                                                       unsigned char, int);
int /*<<< orphan*/ printf(char *);
void mmx_grayscale_rgb16(unsigned short *src, unsigned char opacity, int width,
                         unsigned short *output) {
  if (src == output) {
    if (opacity != 0xFF)
      mmx_grayscale_rgb16_opacity_inplace(src, opacity, width);
    else
      mmx_grayscale_rgb16_inplace(src, width);
  } else {
    printf("mmx: Non-inplace grayscale not implemented\n");
  }
}


x86 assembly (clang, -O0):
<mmx_grayscale_rgb16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    118e <mmx_grayscale_rgb16+0x5e>
movzbl -0x9(%rbp),%eax
cmp    $0xff,%eax
je     117d <mmx_grayscale_rgb16+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x9(%rbp),%al
mov    -0x10(%rbp),%edx
movzbl %al,%esi
call   1030 <mmx_grayscale_rgb16_opacity_inplace@plt>
jmp    1189 <mmx_grayscale_rgb16+0x59>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1050 <mmx_grayscale_rgb16_inplace@plt>
jmp    119a <mmx_grayscale_rgb16+0x6a>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmx_grayscale_rgb16>:
cmp    %rcx,%rdi
je     1141 <mmx_grayscale_rgb16+0x11>
lea    0xec4(%rip),%rdi
jmp    1030 <puts@plt>
cmp    $0xff,%sil
je     1150 <mmx_grayscale_rgb16+0x20>
movzbl %sil,%esi
jmp    1040 <mmx_grayscale_rgb16_opacity_inplace@plt>
mov    %edx,%esi
jmp    1050 <mmx_grayscale_rgb16_inplace@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"mmx: Non-inplace grayscale not implemented\0A\00"
define void @mmx_grayscale_rgb16(i16* %0, i8 zeroext %1, i32 %2, i16* %3) {
%5 = alloca i16*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i16*
store i16* %0, i16** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
store i16* %3, i16** %8
%9 = load i16*, i16** %5
%10 = load i16*, i16** %8
%11 = icmp eq i16* %9, %10
br i1 %11, label %12, label %26
12: ; preds = %4
%13 = load i8, i8* %6
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %14, 255
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i16*, i16** %5
%18 = load i8, i8* %6
%19 = load i32, i32* %7
%20 = call i32 @mmx_grayscale_rgb16_opacity_inplace(i16* %17, i8 zeroext %18, i32 %19)
br label %25
21: ; preds = %12
%22 = load i16*, i16** %5
%23 = load i32, i32* %7
%24 = call i32 @mmx_grayscale_rgb16_inplace(i16* %22, i32 %23)
br label %25
25: ; preds = %21, %16
br label %28
26: ; preds = %4
%27 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %25
ret void
}

LLVM IR (-O2):
@str = [43 x i8] c"mmx: Non-inplace grayscale not implemented\00"
define void @mmx_grayscale_rgb16(i16* %0, i8 zeroext %1, i32 %2, i16* readnone %3) {
%5 = icmp eq i16* %0, %3
br i1 %5, label %6, label %12
6: ; preds = %4
%7 = icmp eq i8 %1, -1
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 @mmx_grayscale_rgb16_opacity_inplace(i16* %0, i8 zeroext %1, i32 %2)
br label %14
10: ; preds = %6
%11 = tail call i32 @mmx_grayscale_rgb16_inplace(i16* %0, i32 %2)
br label %14
12: ; preds = %4
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %8, %10, %12
ret void
}