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

/* Variables and functions */
int CEC_MSG_CDC_HEC_REPORT_STATE;
int CEC_MSG_CDC_MESSAGE;
void cec_msg_cdc_hec_report_state(struct cec_msg *msg, __u16 target_phys_addr,
                                  __u8 hec_func_state, __u8 host_func_state,
                                  __u8 enc_func_state, __u8 cdc_errcode,
                                  __u8 has_field, __u16 hec_field) {
  msg->len = has_field ? 10 : 8;
  msg->msg[0] |= 0xf;
  msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  msg->msg[4] = CEC_MSG_CDC_HEC_REPORT_STATE;
  msg->msg[5] = target_phys_addr >> 8;
  msg->msg[6] = target_phys_addr & 0xff;
  msg->msg[7] = (hec_func_state << 6) | (host_func_state << 4) |
                (enc_func_state << 2) | cdc_errcode;
  if (has_field) {
    msg->msg[8] = hec_field >> 8;
    msg->msg[9] = hec_field & 0xff;
  }
}


x86 assembly (clang, -O0):
<cec_msg_cdc_hec_report_state>:
push   %rbp
mov    %rsp,%rbp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    0x10(%rbp),%edx
mov    $0x8,%ecx
mov    $0xa,%eax
cmp    $0x0,%edx
cmovne %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%ecx
or     $0xf,%ecx
mov    %ecx,(%rax)
mov    0x2e8a(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x4(%rax)
mov    0x2e86(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x10(%rax)
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x14(%rax)
mov    -0xc(%rbp),%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x18(%rax)
mov    -0x10(%rbp),%ecx
shl    $0x6,%ecx
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%eax
shl    $0x2,%eax
or     %eax,%ecx
or     -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x1c(%rax)
cmpl   $0x0,0x10(%rbp)
je     11e7 <cec_msg_cdc_hec_report_state+0xe7>
mov    0x18(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x20(%rax)
mov    0x18(%rbp),%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x24(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_msg_cdc_hec_report_state>:
mov    0x8(%rsp),%r10d
xor    %eax,%eax
test   %r10d,%r10d
setne  %al
add    %eax,%eax
add    $0x8,%eax
mov    %eax,(%rdi)
mov    0x8(%rdi),%rdi
orl    $0xf,(%rdi)
movzbl %sil,%eax
sar    $0x8,%esi
shl    $0x6,%edx
shl    $0x4,%ecx
or     %edx,%ecx
shl    $0x2,%r8d
or     %r9d,%r8d
or     %ecx,%r8d
mov    0x2e9d(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rdi)
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x10(%rdi)
mov    %esi,0x14(%rdi)
mov    %eax,0x18(%rdi)
mov    %r8d,0x1c(%rdi)
test   %r10d,%r10d
je     116b <cec_msg_cdc_hec_report_state+0x6b>
mov    0x10(%rsp),%eax
movzbl %al,%ecx
sar    $0x8,%eax
mov    %eax,0x20(%rdi)
mov    %ecx,0x24(%rdi)
ret

LLVM IR (-O0):
%struct.cec_msg = type { i32, i32* }
@CEC_MSG_CDC_MESSAGE = global i32 0
@CEC_MSG_CDC_HEC_REPORT_STATE = global i32 0
define void @cec_msg_cdc_hec_report_state(%struct.cec_msg* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca %struct.cec_msg*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store %struct.cec_msg* %0, %struct.cec_msg** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%17 = load i32, i32* %15
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 10, i32 8
%21 = load %struct.cec_msg*, %struct.cec_msg** %9
%22 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load %struct.cec_msg*, %struct.cec_msg** %9
%24 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %23, i32 0, i32 1
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = or i32 %27, 15
store i32 %28, i32* %26
%29 = load i32, i32* @CEC_MSG_CDC_MESSAGE
%30 = load %struct.cec_msg*, %struct.cec_msg** %9
%31 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %30, i32 0, i32 1
%32 = load i32*, i32** %31
%33 = getelementptr inbounds i32, i32* %32, i64 1
store i32 %29, i32* %33
%34 = load i32, i32* @CEC_MSG_CDC_HEC_REPORT_STATE
%35 = load %struct.cec_msg*, %struct.cec_msg** %9
%36 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %35, i32 0, i32 1
%37 = load i32*, i32** %36
%38 = getelementptr inbounds i32, i32* %37, i64 4
store i32 %34, i32* %38
%39 = load i32, i32* %10
%40 = ashr i32 %39, 8
%41 = load %struct.cec_msg*, %struct.cec_msg** %9
%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
store i32 %40, i32* %44
%45 = load i32, i32* %10
%46 = and i32 %45, 255
%47 = load %struct.cec_msg*, %struct.cec_msg** %9
%48 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %47, i32 0, i32 1
%49 = load i32*, i32** %48
%50 = getelementptr inbounds i32, i32* %49, i64 6
store i32 %46, i32* %50
%51 = load i32, i32* %11
%52 = shl i32 %51, 6
%53 = load i32, i32* %12
%54 = shl i32 %53, 4
%55 = or i32 %52, %54
%56 = load i32, i32* %13
%57 = shl i32 %56, 2
%58 = or i32 %55, %57
%59 = load i32, i32* %14
%60 = or i32 %58, %59
%61 = load %struct.cec_msg*, %struct.cec_msg** %9
%62 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %61, i32 0, i32 1
%63 = load i32*, i32** %62
%64 = getelementptr inbounds i32, i32* %63, i64 7
store i32 %60, i32* %64
%65 = load i32, i32* %15
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %80
67: ; preds = %8
%68 = load i32, i32* %16
%69 = ashr i32 %68, 8
%70 = load %struct.cec_msg*, %struct.cec_msg** %9
%71 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %70, i32 0, i32 1
%72 = load i32*, i32** %71
%73 = getelementptr inbounds i32, i32* %72, i64 8
store i32 %69, i32* %73
%74 = load i32, i32* %16
%75 = and i32 %74, 255
%76 = load %struct.cec_msg*, %struct.cec_msg** %9
%77 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %76, i32 0, i32 1
%78 = load i32*, i32** %77
%79 = getelementptr inbounds i32, i32* %78, i64 9
store i32 %75, i32* %79
br label %80
80: ; preds = %67, %8
ret void
}

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32* }
@CEC_MSG_CDC_MESSAGE = global i32 0
@CEC_MSG_CDC_HEC_REPORT_STATE = global i32 0
define void @cec_msg_cdc_hec_report_state(%struct.cec_msg* nocapture %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = icmp eq i32 %6, 0
%10 = select i1 %9, i32 8, i32 10
%11 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 1
%13 = load i32*, i32** %12
%14 = load i32, i32* %13
%15 = or i32 %14, 15
store i32 %15, i32* %13
%16 = load i32, i32* @CEC_MSG_CDC_MESSAGE
%17 = getelementptr inbounds i32, i32* %13, i64 1
store i32 %16, i32* %17
%18 = load i32, i32* @CEC_MSG_CDC_HEC_REPORT_STATE
%19 = getelementptr inbounds i32, i32* %13, i64 4
store i32 %18, i32* %19
%20 = ashr i32 %1, 8
%21 = getelementptr inbounds i32, i32* %13, i64 5
store i32 %20, i32* %21
%22 = and i32 %1, 255
%23 = getelementptr inbounds i32, i32* %13, i64 6
store i32 %22, i32* %23
%24 = shl i32 %2, 6
%25 = shl i32 %3, 4
%26 = or i32 %25, %24
%27 = shl i32 %4, 2
%28 = or i32 %26, %27
%29 = or i32 %28, %5
%30 = getelementptr inbounds i32, i32* %13, i64 7
store i32 %29, i32* %30
br i1 %9, label %36, label %31
31: ; preds = %8
%32 = ashr i32 %7, 8
%33 = getelementptr inbounds i32, i32* %13, i64 8
store i32 %32, i32* %33
%34 = and i32 %7, 255
%35 = getelementptr inbounds i32, i32* %13, i64 9
store i32 %34, i32* %35
br label %36
36: ; preds = %31, %8
ret void
}