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

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ *, unsigned int);
void cec_ops_set_osd_string(const struct cec_msg *msg, __u8 *disp_ctl,
                            char *osd) {
  unsigned int len = msg->len > 3 ? msg->len - 3 : 0;
  *disp_ctl = msg->msg[2];
  if (len > 13)
    len = 13;
  memcpy(osd, msg->msg + 3, len);
  osd[len] = '\0';
}


x86 assembly (clang, -O0):
<cec_ops_set_osd_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x3,(%rax)
jle    1142 <cec_ops_set_osd_string+0x32>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    $0x3,%eax
mov    %eax,-0x20(%rbp)
jmp    114c <cec_ops_set_osd_string+0x3c>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    114c <cec_ops_set_osd_string+0x3c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0xd,-0x1c(%rbp)
jbe    1174 <cec_ops_set_osd_string+0x64>
movl   $0xd,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
add    $0xc,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_ops_set_osd_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    (%rdi),%eax
lea    -0x3(%rax),%ecx
xor    %edx,%edx
cmp    $0x4,%eax
cmovge %ecx,%edx
mov    0x8(%rdi),%rax
mov    0x8(%rax),%ecx
mov    %ecx,(%rsi)
cmp    $0xd,%edx
mov    $0xd,%ebx
cmovb  %edx,%ebx
add    $0xc,%rax
mov    %r14,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.cec_msg = type { i32, i32* }
define void @cec_ops_set_osd_string(%struct.cec_msg* %0, i32* %1, i8* %2) {
%4 = alloca %struct.cec_msg*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store %struct.cec_msg* %0, %struct.cec_msg** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%8 = load %struct.cec_msg*, %struct.cec_msg** %4
%9 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = icmp sgt i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load %struct.cec_msg*, %struct.cec_msg** %4
%14 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %15, 3
br label %18
17: ; preds = %3
br label %18
18: ; preds = %17, %12
%19 = phi i32 [ %16, %12 ], [ 0, %17 ]
store i32 %19, i32* %7
%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* %23
%25 = load i32*, i32** %5
store i32 %24, i32* %25
%26 = load i32, i32* %7
%27 = icmp ugt i32 %26, 13
br i1 %27, label %28, label %29
28: ; preds = %18
store i32 13, i32* %7
br label %29
29: ; preds = %28, %18
%30 = load i8*, i8** %6
%31 = load %struct.cec_msg*, %struct.cec_msg** %4
%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
%35 = load i32, i32* %7
%36 = call i32 @memcpy(i8* %30, i32* %34, i32 %35)
%37 = load i8*, i8** %6
%38 = load i32, i32* %7
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
ret void
}

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32* }
define void @cec_ops_set_osd_string(%struct.cec_msg* nocapture %0, i32* nocapture writeonly %1, i8* %2) {
%4 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp sgt i32 %5, 3
%7 = add nsw i32 %5, -3
%8 = select i1 %6, i32 %7, i32 0
%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 2
%12 = load i32, i32* %11
store i32 %12, i32* %1
%13 = icmp ult i32 %8, 13
%14 = select i1 %13, i32 %8, i32 13
%15 = getelementptr inbounds i32, i32* %10, i64 3
%16 = tail call i32 @memcpy(i8* %2, i32* %15, i32 %14)
%17 = zext i32 %14 to i64
%18 = getelementptr inbounds i8, i8* %2, i64 %17
store i8 0, i8* %18
ret void
}