#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;
  int /*<<< orphan*/ reply;
};
typedef int __u16;

/* Variables and functions */
int /*<<< orphan*/ CEC_MSG_SET_SYSTEM_AUDIO_MODE;
int CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST;
void cec_msg_system_audio_mode_request(struct cec_msg *msg, int reply,
                                       __u16 phys_addr) {
  msg->len = phys_addr == 0xffff ? 2 : 4;
  msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST;
  msg->msg[2] = phys_addr >> 8;
  msg->msg[3] = phys_addr & 0xff;
  msg->reply = reply ? CEC_MSG_SET_SYSTEM_AUDIO_MODE : 0;
}


x86 assembly (clang, -O0):
<cec_msg_system_audio_mode_request>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    $0x4,%ecx
mov    $0x2,%eax
cmp    $0xffff,%edx
cmove  %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2eaf(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%ecx
sar    $0x8,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %ecx,0xc(%rax)
cmpl   $0x0,-0xc(%rbp)
je     117e <cec_msg_system_audio_mode_request+0x7e>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <cec_msg_system_audio_mode_request+0x88>
xor    %eax,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <cec_msg_system_audio_mode_request+0x88>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_msg_system_audio_mode_request>:
xor    %eax,%eax
cmp    $0xffff,%edx
setne  %al
lea    0x2(%rax,%rax,1),%eax
mov    %eax,(%rdi)
mov    0x2ec8(%rip),%rax
mov    (%rax),%eax
mov    0x8(%rdi),%rcx
mov    %eax,0x4(%rcx)
movzbl %dl,%eax
sar    $0x8,%edx
mov    %edx,0x8(%rcx)
mov    %eax,0xc(%rcx)
test   %esi,%esi
je     113a <cec_msg_system_audio_mode_request+0x3a>
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
mov    %esi,0x10(%rdi)
ret

LLVM IR (-O0):
%struct.cec_msg = type { i32, i32*, i32 }
@CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST = global i32 0
@CEC_MSG_SET_SYSTEM_AUDIO_MODE = global i32 0
define void @cec_msg_system_audio_mode_request(%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* %6
%8 = icmp eq i32 %7, 65535
%9 = zext i1 %8 to i64
%10 = select i1 %8, i32 2, i32 4
%11 = load %struct.cec_msg*, %struct.cec_msg** %4
%12 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load i32, i32* @CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST
%14 = load %struct.cec_msg*, %struct.cec_msg** %4
%15 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %14, i32 0, i32 1
%16 = load i32*, i32** %15
%17 = getelementptr inbounds i32, i32* %16, i64 1
store i32 %13, i32* %17
%18 = load i32, i32* %6
%19 = ashr i32 %18, 8
%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
store i32 %19, i32* %23
%24 = load i32, i32* %6
%25 = and i32 %24, 255
%26 = load %struct.cec_msg*, %struct.cec_msg** %4
%27 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %26, i32 0, i32 1
%28 = load i32*, i32** %27
%29 = getelementptr inbounds i32, i32* %28, i64 3
store i32 %25, i32* %29
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %3
%33 = load i32, i32* @CEC_MSG_SET_SYSTEM_AUDIO_MODE
br label %35
34: ; preds = %3
br label %35
35: ; preds = %34, %32
%36 = phi i32 [ %33, %32 ], [ 0, %34 ]
%37 = load %struct.cec_msg*, %struct.cec_msg** %4
%38 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %37, i32 0, i32 2
store i32 %36, i32* %38
ret void
}

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32*, i32 }
@CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST = global i32 0
@CEC_MSG_SET_SYSTEM_AUDIO_MODE = global i32 0
define void @cec_msg_system_audio_mode_request(%struct.cec_msg* nocapture %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 65535
%5 = select i1 %4, i32 2, i32 4
%6 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
store i32 %5, i32* %6
%7 = load i32, i32* @CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST
%8 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 1
%9 = load i32*, i32** %8
%10 = getelementptr inbounds i32, i32* %9, i64 1
store i32 %7, i32* %10
%11 = ashr i32 %2, 8
%12 = getelementptr inbounds i32, i32* %9, i64 2
store i32 %11, i32* %12
%13 = and i32 %2, 255
%14 = getelementptr inbounds i32, i32* %9, i64 3
store i32 %13, i32* %14
%15 = icmp eq i32 %1, 0
%16 = load i32, i32* @CEC_MSG_SET_SYSTEM_AUDIO_MODE
%17 = select i1 %15, i32 0, i32 %16
%18 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 2
store i32 %17, i32* %18
ret void
}