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

/* Variables and functions */
void cec_ops_request_short_audio_descriptor(const struct cec_msg *msg,
                                            __u8 *num_descriptors,
                                            __u8 *audio_format_id,
                                            __u8 *audio_format_code) {
  unsigned int i;
  *num_descriptors = msg->len - 2;
  if (*num_descriptors > 4) {
    *num_descriptors = 4;
  }
  for (i = 0; i < *num_descriptors; i++) {
    audio_format_id[i] = msg->msg[2 + i] >> 6;
    audio_format_code[i] = msg->msg[2 + i] & 0x3f;
  }
}


x86 assembly (clang, -O0):
<cec_ops_request_short_audio_descriptor>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0x2,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x4,(%rax)
jle    113a <cec_ops_request_short_audio_descriptor+0x3a>
mov    -0x10(%rbp),%rax
movl   $0x4,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jae    119e <cec_ops_request_short_audio_descriptor+0x9e>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x24(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%edx
sar    $0x6,%edx
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x24(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,4),%edx
and    $0x3f,%edx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <cec_ops_request_short_audio_descriptor+0x41>
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_ops_request_short_audio_descriptor>:
mov    (%rdi),%eax
lea    -0x2(%rax),%r8d
cmp    $0x7,%eax
mov    $0x4,%eax
cmovl  %r8d,%eax
mov    %eax,(%rsi)
test   %eax,%eax
je     1143 <cec_ops_request_short_audio_descriptor+0x43>
mov    0x8(%rdi),%r8
xor    %edi,%edi
xchg   %ax,%ax
lea    0x2(%rdi),%r9d
mov    (%r8,%r9,4),%eax
sar    $0x6,%eax
mov    %eax,(%rdx,%rdi,4)
mov    (%r8,%r9,4),%eax
and    $0x3f,%eax
mov    %eax,(%rcx,%rdi,4)
add    $0x1,%rdi
mov    (%rsi),%eax
cmp    %rax,%rdi
jb     1120 <cec_ops_request_short_audio_descriptor+0x20>
ret

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

LLVM IR (-O2):
%struct.cec_msg = type { i32, i32* }
define void @cec_ops_request_short_audio_descriptor(%struct.cec_msg* nocapture %0, i32* nocapture %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = add nsw i32 %6, -2
%8 = icmp sgt i32 %6, 6
%9 = select i1 %8, i32 4, i32 %7
store i32 %9, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %29, label %11
11: ; preds = %4
%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 ], [ %25, %14 ]
%16 = add nuw i64 %15, 2
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds i32, i32* %13, i64 %17
%19 = load i32, i32* %18
%20 = ashr i32 %19, 6
%21 = getelementptr inbounds i32, i32* %2, i64 %15
store i32 %20, i32* %21
%22 = load i32, i32* %18
%23 = and i32 %22, 63
%24 = getelementptr inbounds i32, i32* %3, i64 %15
store i32 %23, i32* %24
%25 = add nuw nsw i64 %15, 1
%26 = load i32, i32* %1
%27 = zext i32 %26 to i64
%28 = icmp ult i64 %25, %27
br i1 %28, label %14, label %29
29: ; preds = %14, %4
ret void
}