#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_REPORT_CURRENT_LATENCY;
int CEC_MSG_REQUEST_CURRENT_LATENCY;
void cec_msg_request_current_latency(struct cec_msg *msg, int reply,
                                     __u16 phys_addr) {
  msg->len = 4;
  msg->msg[0] |= 0xf;
  msg->msg[1] = CEC_MSG_REQUEST_CURRENT_LATENCY;
  msg->msg[2] = phys_addr >> 8;
  msg->msg[3] = phys_addr & 0xff;
  msg->reply = reply ? CEC_MSG_REPORT_CURRENT_LATENCY : 0;
}


x86 assembly (clang, -O0):
<cec_msg_request_current_latency>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%ecx
or     $0xf,%ecx
mov    %ecx,(%rax)
mov    0x2eaa(%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     117b <cec_msg_request_current_latency+0x7b>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <cec_msg_request_current_latency+0x85>
xor    %eax,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <cec_msg_request_current_latency+0x85>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_msg_request_current_latency>:
movl   $0x4,(%rdi)
mov    0x8(%rdi),%rax
orl    $0xf,(%rax)
mov    0x2ec4(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rax)
movzbl %dl,%ecx
sar    $0x8,%edx
mov    %edx,0x8(%rax)
mov    %ecx,0xc(%rax)
test   %esi,%esi
je     1132 <cec_msg_request_current_latency+0x32>
mov    0x2eb8(%rip),%rax
mov    (%rax),%esi
mov    %esi,0x10(%rdi)
ret

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

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32*, i32 }
@CEC_MSG_REQUEST_CURRENT_LATENCY = global i32 0
@CEC_MSG_REPORT_CURRENT_LATENCY = global i32 0
define void @cec_msg_request_current_latency(%struct.cec_msg* nocapture %0, i32 %1, i32 %2) {
%4 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
store i32 4, i32* %4
%5 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 1
%6 = load i32*, i32** %5
%7 = load i32, i32* %6
%8 = or i32 %7, 15
store i32 %8, i32* %6
%9 = load i32, i32* @CEC_MSG_REQUEST_CURRENT_LATENCY
%10 = getelementptr inbounds i32, i32* %6, i64 1
store i32 %9, i32* %10
%11 = ashr i32 %2, 8
%12 = getelementptr inbounds i32, i32* %6, i64 2
store i32 %11, i32* %12
%13 = and i32 %2, 255
%14 = getelementptr inbounds i32, i32* %6, i64 3
store i32 %13, i32* %14
%15 = icmp eq i32 %1, 0
%16 = load i32, i32* @CEC_MSG_REPORT_CURRENT_LATENCY
%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
}