#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 *msg;
};
typedef int __u8;
typedef int __u32;

/* Variables and functions */
int CEC_MSG_VENDOR_COMMAND_WITH_ID;
int /*<<< orphan*/ memcpy(int *, int const *, int);
void cec_msg_vendor_command_with_id(struct cec_msg *msg, __u32 vendor_id,
                                    __u8 size, const __u8 *vendor_cmd) {
  if (size > 11)
    size = 11;
  msg->len = 5 + size;
  msg->msg[1] = CEC_MSG_VENDOR_COMMAND_WITH_ID;
  msg->msg[2] = vendor_id >> 16;
  msg->msg[3] = (vendor_id >> 8) & 0xff;
  msg->msg[4] = vendor_id & 0xff;
  memcpy(msg->msg + 5, vendor_cmd, size);
}


x86 assembly (clang, -O0):
<cec_msg_vendor_command_with_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0xb,-0x10(%rbp)
jle    1137 <cec_msg_vendor_command_with_id+0x27>
movl   $0xb,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
add    $0x5,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2eae(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x10,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x8(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0xc(%rax)
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
add    $0x14,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_msg_vendor_command_with_id>:
push   %rbx
mov    %esi,%eax
cmp    $0xb,%edx
mov    $0xb,%esi
cmovge %esi,%edx
lea    0x5(%rdx),%esi
mov    %esi,(%rdi)
mov    0x2ece(%rip),%rsi
mov    (%rsi),%esi
mov    0x8(%rdi),%rdi
mov    %esi,0x4(%rdi)
movzbl %ah,%ebx
movzbl %al,%esi
sar    $0x10,%eax
mov    %eax,0x8(%rdi)
mov    %ebx,0xc(%rdi)
mov    %esi,0x10(%rdi)
add    $0x14,%rdi
mov    %rcx,%rsi
pop    %rbx
jmp    1030 <memcpy@plt>

LLVM IR (-O0):
%struct.cec_msg = type { i32, i32* }
@CEC_MSG_VENDOR_COMMAND_WITH_ID = global i32 0
define void @cec_msg_vendor_command_with_id(%struct.cec_msg* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca %struct.cec_msg*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store %struct.cec_msg* %0, %struct.cec_msg** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%9 = load i32, i32* %7
%10 = icmp sgt i32 %9, 11
br i1 %10, label %11, label %12
11: ; preds = %4
store i32 11, i32* %7
br label %12
12: ; preds = %11, %4
%13 = load i32, i32* %7
%14 = add nsw i32 5, %13
%15 = load %struct.cec_msg*, %struct.cec_msg** %5
%16 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* @CEC_MSG_VENDOR_COMMAND_WITH_ID
%18 = load %struct.cec_msg*, %struct.cec_msg** %5
%19 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %18, i32 0, i32 1
%20 = load i32*, i32** %19
%21 = getelementptr inbounds i32, i32* %20, i64 1
store i32 %17, i32* %21
%22 = load i32, i32* %6
%23 = ashr i32 %22, 16
%24 = load %struct.cec_msg*, %struct.cec_msg** %5
%25 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %24, i32 0, i32 1
%26 = load i32*, i32** %25
%27 = getelementptr inbounds i32, i32* %26, i64 2
store i32 %23, i32* %27
%28 = load i32, i32* %6
%29 = ashr i32 %28, 8
%30 = and i32 %29, 255
%31 = load %struct.cec_msg*, %struct.cec_msg** %5
%32 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %31, i32 0, i32 1
%33 = load i32*, i32** %32
%34 = getelementptr inbounds i32, i32* %33, i64 3
store i32 %30, i32* %34
%35 = load i32, i32* %6
%36 = and i32 %35, 255
%37 = load %struct.cec_msg*, %struct.cec_msg** %5
%38 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %37, i32 0, i32 1
%39 = load i32*, i32** %38
%40 = getelementptr inbounds i32, i32* %39, i64 4
store i32 %36, i32* %40
%41 = load %struct.cec_msg*, %struct.cec_msg** %5
%42 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %41, i32 0, i32 1
%43 = load i32*, i32** %42
%44 = getelementptr inbounds i32, i32* %43, i64 5
%45 = load i32*, i32** %8
%46 = load i32, i32* %7
%47 = call i32 @memcpy(i32* %44, i32* %45, i32 %46)
ret void
}

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32* }
@CEC_MSG_VENDOR_COMMAND_WITH_ID = global i32 0
define void @cec_msg_vendor_command_with_id(%struct.cec_msg* nocapture %0, i32 %1, i32 %2, i32* %3) {
%5 = icmp slt i32 %2, 11
%6 = select i1 %5, i32 %2, i32 11
%7 = add nsw i32 %6, 5
%8 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @CEC_MSG_VENDOR_COMMAND_WITH_ID
%10 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 1
%11 = load i32*, i32** %10
%12 = getelementptr inbounds i32, i32* %11, i64 1
store i32 %9, i32* %12
%13 = ashr i32 %1, 16
%14 = getelementptr inbounds i32, i32* %11, i64 2
store i32 %13, i32* %14
%15 = lshr i32 %1, 8
%16 = and i32 %15, 255
%17 = getelementptr inbounds i32, i32* %11, i64 3
store i32 %16, i32* %17
%18 = and i32 %1, 255
%19 = getelementptr inbounds i32, i32* %11, i64 4
store i32 %18, i32* %19
%20 = getelementptr inbounds i32, i32* %11, i64 5
%21 = tail call i32 @memcpy(i32* %20, i32* %3, i32 %6)
ret void
}