#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 */
struct cec_msg {
  int len;
  int /*<<< orphan*/ *msg;
};
typedef int __u8;

/* Variables and functions */
int /*<<< orphan*/ CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN;
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int const *, int);
void cec_msg_vendor_remote_button_down(struct cec_msg *msg, __u8 size,
                                       const __u8 *rc_code) {
  if (size > 14) {
    size = 14;
  }
  msg->len = 2 + size;
  msg->msg[1] = CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN;
  memcpy(msg->msg + 2, rc_code, size);
}


x86 assembly (clang, -O0):
<cec_msg_vendor_remote_button_down>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0xe,-0xc(%rbp)
jle    1134 <cec_msg_vendor_remote_button_down+0x24>
movl   $0xe,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2ea1(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
add    $0x8,%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_msg_vendor_remote_button_down>:
cmp    $0xe,%esi
mov    $0xe,%eax
cmovl  %esi,%eax
lea    0x2(%rax),%ecx
mov    %ecx,(%rdi)
mov    0x2ec1(%rip),%rcx
mov    (%rcx),%ecx
mov    0x8(%rdi),%rdi
mov    %ecx,0x4(%rdi)
add    $0x8,%rdi
mov    %rdx,%rsi
mov    %eax,%edx
jmp    1030 <memcpy@plt>

LLVM IR (-O0):
%struct.cec_msg = type { i32, i32* }
@CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN = global i32 0
define void @cec_msg_vendor_remote_button_down(%struct.cec_msg* %0, i32 %1, i32* %2) {
%4 = alloca %struct.cec_msg*
%5 = alloca i32
%6 = alloca i32*
store %struct.cec_msg* %0, %struct.cec_msg** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32, i32* %5
%8 = icmp sgt i32 %7, 14
br i1 %8, label %9, label %10
9: ; preds = %3
store i32 14, i32* %5
br label %10
10: ; preds = %9, %3
%11 = load i32, i32* %5
%12 = add nsw i32 2, %11
%13 = load %struct.cec_msg*, %struct.cec_msg** %4
%14 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = load i32, i32* @CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN
%16 = load %struct.cec_msg*, %struct.cec_msg** %4
%17 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %16, i32 0, i32 1
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32 %15, i32* %19
%20 = load %struct.cec_msg*, %struct.cec_msg** %4
%21 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %20, i32 0, i32 1
%22 = load i32*, i32** %21
%23 = getelementptr inbounds i32, i32* %22, i64 2
%24 = load i32*, i32** %6
%25 = load i32, i32* %5
%26 = call i32 @memcpy(i32* %23, i32* %24, i32 %25)
ret void
}

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32* }
@CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN = global i32 0
define void @cec_msg_vendor_remote_button_down(%struct.cec_msg* nocapture %0, i32 %1, i32* %2) {
%4 = icmp slt i32 %1, 14
%5 = select i1 %4, i32 %1, i32 14
%6 = add nsw i32 %5, 2
%7 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
store i32 %6, i32* %7
%8 = load i32, i32* @CEC_MSG_VENDOR_REMOTE_BUTTON_DOWN
%9 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 1
%10 = load i32*, i32** %9
%11 = getelementptr inbounds i32, i32* %10, i64 1
store i32 %8, i32* %11
%12 = getelementptr inbounds i32, i32* %10, i64 2
%13 = tail call i32 @memcpy(i32* %12, i32* %2, i32 %5)
ret void
}