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

/* Variables and functions */
void cec_ops_report_short_audio_descriptor(const struct cec_msg *msg,
                                           __u8 *num_descriptors,
                                           __u32 *descriptors) {
  unsigned int i;
  *num_descriptors = (msg->len - 2) / 3;
  if (*num_descriptors > 4) {
    *num_descriptors = 4;
  }
  for (i = 0; i < *num_descriptors; i++)
    descriptors[i] = (msg->msg[2 + i * 3] << 16) | (msg->msg[3 + i * 3] << 8) |
                     msg->msg[4 + i * 3];
}


x86 assembly (clang, -O0):
<cec_ops_report_short_audio_descriptor>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
sub    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x4,(%rax)
jle    1140 <cec_ops_report_short_audio_descriptor+0x40>
mov    -0x10(%rbp),%rax
movl   $0x4,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jae    11b2 <cec_ops_report_short_audio_descriptor+0xb2>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%edx
shl    $0x10,%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x3,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%eax
shl    $0x8,%eax
or     %eax,%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    $0x4,%ecx
mov    %ecx,%ecx
or     (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1147 <cec_ops_report_short_audio_descriptor+0x47>
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_ops_report_short_audio_descriptor>:
mov    (%rdi),%ecx
mov    $0x4,%eax
cmp    $0x10,%ecx
jg     1126 <cec_ops_report_short_audio_descriptor+0x26>
add    $0xfffffffe,%ecx
movslq %ecx,%rax
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,(%rsi)
test   %eax,%eax
je     1170 <cec_ops_report_short_audio_descriptor+0x70>
mov    0x8(%rdi),%r8
mov    $0x4,%ecx
xor    %r10d,%r10d
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rcx),%eax
mov    (%r8,%rax,4),%r9d
shl    $0x10,%r9d
lea    -0x1(%rcx),%eax
mov    (%r8,%rax,4),%eax
shl    $0x8,%eax
or     %r9d,%eax
mov    %ecx,%edi
or     (%r8,%rdi,4),%eax
mov    %eax,(%rdx,%r10,4)
add    $0x1,%r10
mov    (%rsi),%eax
add    $0x3,%ecx
cmp    %rax,%r10
jb     1140 <cec_ops_report_short_audio_descriptor+0x40>
ret

LLVM IR (-O0):
%struct.cec_msg = type { i32, i32* }
define void @cec_ops_report_short_audio_descriptor(%struct.cec_msg* %0, i32* %1, i32* %2) {
%4 = alloca %struct.cec_msg*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
store %struct.cec_msg* %0, %struct.cec_msg** %4
store i32* %1, i32** %5
store i32* %2, i32** %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 = sub nsw i32 %10, 2
%12 = sdiv i32 %11, 3
%13 = load i32*, i32** %5
store i32 %12, i32* %13
%14 = load i32*, i32** %5
%15 = load i32, i32* %14
%16 = icmp sgt i32 %15, 4
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32*, i32** %5
store i32 4, i32* %18
br label %19
19: ; preds = %17, %3
store i32 0, i32* %7
br label %20
20: ; preds = %61, %19
%21 = load i32, i32* %7
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = icmp ult i32 %21, %23
br i1 %24, label %25, label %64
25: ; preds = %20
%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 = load i32, i32* %7
%30 = mul i32 %29, 3
%31 = add i32 2, %30
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %28, i64 %32
%34 = load i32, i32* %33
%35 = shl i32 %34, 16
%36 = load %struct.cec_msg*, %struct.cec_msg** %4
%37 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %36, i32 0, i32 1
%38 = load i32*, i32** %37
%39 = load i32, i32* %7
%40 = mul i32 %39, 3
%41 = add i32 3, %40
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %38, i64 %42
%44 = load i32, i32* %43
%45 = shl i32 %44, 8
%46 = or i32 %35, %45
%47 = load %struct.cec_msg*, %struct.cec_msg** %4
%48 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %47, i32 0, i32 1
%49 = load i32*, i32** %48
%50 = load i32, i32* %7
%51 = mul i32 %50, 3
%52 = add i32 4, %51
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %49, i64 %53
%55 = load i32, i32* %54
%56 = or i32 %46, %55
%57 = load i32*, i32** %6
%58 = load i32, i32* %7
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
store i32 %56, i32* %60
br label %61
61: ; preds = %25
%62 = load i32, i32* %7
%63 = add i32 %62, 1
store i32 %63, i32* %7
br label %20
64: ; preds = %20
ret void
}

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32* }
define void @cec_ops_report_short_audio_descriptor(%struct.cec_msg* nocapture %0, i32* nocapture %1, i32* nocapture writeonly %2) {
%4 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = add nsw i32 %5, -2
%7 = sdiv i32 %6, 3
%8 = icmp sgt i32 %5, 16
%9 = select i1 %8, i32 4, i32 %7
store i32 %9, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %39, label %11
11: ; preds = %3
%12 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 1
%13 = load i32*, i32** %12
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %35, %14 ]
%16 = trunc i64 %15 to i32
%17 = mul i32 %16, 3
%18 = add i32 %17, 2
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %13, i64 %19
%21 = load i32, i32* %20
%22 = shl i32 %21, 16
%23 = add i32 %17, 3
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %13, i64 %24
%26 = load i32, i32* %25
%27 = shl i32 %26, 8
%28 = or i32 %27, %22
%29 = add i32 %17, 4
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %13, i64 %30
%32 = load i32, i32* %31
%33 = or i32 %28, %32
%34 = getelementptr inbounds i32, i32* %2, i64 %15
store i32 %33, i32* %34
%35 = add nuw nsw i64 %15, 1
%36 = load i32, i32* %1
%37 = zext i32 %36 to i64
%38 = icmp ult i64 %35, %37
br i1 %38, label %14, label %39
39: ; preds = %14, %3
ret void
}