#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;
};

/* Variables and functions */
int /*<<< orphan*/ CEC_MSG_SET_OSD_NAME;
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char const *, unsigned int);
unsigned int strlen(char const *);
void cec_msg_set_osd_name(struct cec_msg *msg, const char *name) {
  unsigned int len = strlen(name);
  if (len > 14)
    len = 14;
  msg->len = 2 + len;
  msg->msg[1] = CEC_MSG_SET_OSD_NAME;
  memcpy(msg->msg + 2, name, len);
}


x86 assembly (clang, -O0):
<cec_msg_set_osd_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xe,-0x14(%rbp)
jbe    114d <cec_msg_set_osd_name+0x2d>
movl   $0xe,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e88(%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    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_msg_set_osd_name>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0xe,%eax
mov    $0xe,%edx
cmovb  %eax,%edx
lea    0x2(%rdx),%eax
mov    %eax,(%rbx)
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    0x8(%rbx),%rdi
mov    %eax,0x4(%rdi)
add    $0x8,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <memcpy@plt>

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

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32* }
@CEC_MSG_SET_OSD_NAME = global i32 0
define void @cec_msg_set_osd_name(%struct.cec_msg* nocapture %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp ult i32 %3, 14
%5 = select i1 %4, i32 %3, i32 14
%6 = add nuw 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_SET_OSD_NAME
%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, i8* %1, i32 %5)
ret void
}