#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 *msg;
};
typedef int __u8;

/* Variables and functions */
int const CEC_OP_FEAT_EXT;
void cec_ops_report_features(const struct cec_msg *msg, __u8 *cec_version,
                             __u8 *all_device_types, const __u8 **rc_profile,
                             const __u8 **dev_features) {
  const __u8 *p = &msg->msg[4];
  *cec_version = msg->msg[2];
  *all_device_types = msg->msg[3];
  *rc_profile = p;
  *dev_features = NULL;
  while (p < &msg->msg[14] && (*p & CEC_OP_FEAT_EXT))
    p++;
  if (!(*p & CEC_OP_FEAT_EXT)) {
    *dev_features = p + 1;
    while (p < &msg->msg[15] && (*p & CEC_OP_FEAT_EXT))
      p++;
  }
  if (*p & CEC_OP_FEAT_EXT)
    *rc_profile = *dev_features = NULL;
}


x86 assembly (clang, -O0):
<cec_ops_report_features>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x10,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0xc(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
add    $0x38,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x31(%rbp)
jae    1192 <cec_ops_report_features+0x92>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    0x2e61(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11a2 <cec_ops_report_features+0xa2>
jmp    11b3 <cec_ops_report_features+0xb3>
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    115d <cec_ops_report_features+0x5d>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    0x2e28(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1235 <cec_ops_report_features+0x135>
mov    -0x30(%rbp),%rcx
add    $0x4,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
add    $0x3c,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x32(%rbp)
jae    120f <cec_ops_report_features+0x10f>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    0x2de4(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    121f <cec_ops_report_features+0x11f>
jmp    1230 <cec_ops_report_features+0x130>
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    11da <cec_ops_report_features+0xda>
jmp    1235 <cec_ops_report_features+0x135>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    0x2da6(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1263 <cec_ops_report_features+0x163>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<cec_ops_report_features>:
mov    (%rdi),%rax
lea    0x10(%rax),%r9
mov    0x8(%rax),%edi
mov    %edi,(%rsi)
mov    0xc(%rax),%esi
mov    %esi,(%rdx)
mov    %r9,(%rcx)
add    $0x14,%rax
mov    %rax,(%r8)
ret

LLVM IR (-O0):
%struct.cec_msg = type { i32* }
@CEC_OP_FEAT_EXT = constant i32 0
define void @cec_ops_report_features(%struct.cec_msg* %0, i32* %1, i32* %2, i32** %3, i32** %4) {
%6 = alloca %struct.cec_msg*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32**
%10 = alloca i32**
%11 = alloca i32*
store %struct.cec_msg* %0, %struct.cec_msg** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32** %3, i32*** %9
store i32** %4, i32*** %10
%12 = load %struct.cec_msg*, %struct.cec_msg** %6
%13 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %12, i32 0, i32 0
%14 = load i32*, i32** %13
%15 = getelementptr inbounds i32, i32* %14, i64 4
store i32* %15, i32** %11
%16 = load %struct.cec_msg*, %struct.cec_msg** %6
%17 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %16, i32 0, i32 0
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 2
%20 = load i32, i32* %19
%21 = load i32*, i32** %7
store i32 %20, i32* %21
%22 = load %struct.cec_msg*, %struct.cec_msg** %6
%23 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %22, i32 0, i32 0
%24 = load i32*, i32** %23
%25 = getelementptr inbounds i32, i32* %24, i64 3
%26 = load i32, i32* %25
%27 = load i32*, i32** %8
store i32 %26, i32* %27
%28 = load i32*, i32** %11
%29 = load i32**, i32*** %9
store i32* %28, i32** %29
%30 = load i32**, i32*** %10
store i32* null, i32** %30
br label %31
31: ; preds = %46, %5
%32 = load i32*, i32** %11
%33 = load %struct.cec_msg*, %struct.cec_msg** %6
%34 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %33, i32 0, i32 0
%35 = load i32*, i32** %34
%36 = getelementptr inbounds i32, i32* %35, i64 14
%37 = icmp ult i32* %32, %36
br i1 %37, label %38, label %44
38: ; preds = %31
%39 = load i32*, i32** %11
%40 = load i32, i32* %39
%41 = load i32, i32* @CEC_OP_FEAT_EXT
%42 = and i32 %40, %41
%43 = icmp ne i32 %42, 0
br label %44
44: ; preds = %38, %31
%45 = phi i1 [ false, %31 ], [ %43, %38 ]
br i1 %45, label %46, label %49
46: ; preds = %44
%47 = load i32*, i32** %11
%48 = getelementptr inbounds i32, i32* %47, i32 1
store i32* %48, i32** %11
br label %31
49: ; preds = %44
%50 = load i32*, i32** %11
%51 = load i32, i32* %50
%52 = load i32, i32* @CEC_OP_FEAT_EXT
%53 = and i32 %51, %52
%54 = icmp ne i32 %53, 0
br i1 %54, label %78, label %55
55: ; preds = %49
%56 = load i32*, i32** %11
%57 = getelementptr inbounds i32, i32* %56, i64 1
%58 = load i32**, i32*** %10
store i32* %57, i32** %58
br label %59
59: ; preds = %74, %55
%60 = load i32*, i32** %11
%61 = load %struct.cec_msg*, %struct.cec_msg** %6
%62 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %61, i32 0, i32 0
%63 = load i32*, i32** %62
%64 = getelementptr inbounds i32, i32* %63, i64 15
%65 = icmp ult i32* %60, %64
br i1 %65, label %66, label %72
66: ; preds = %59
%67 = load i32*, i32** %11
%68 = load i32, i32* %67
%69 = load i32, i32* @CEC_OP_FEAT_EXT
%70 = and i32 %68, %69
%71 = icmp ne i32 %70, 0
br label %72
72: ; preds = %66, %59
%73 = phi i1 [ false, %59 ], [ %71, %66 ]
br i1 %73, label %74, label %77
74: ; preds = %72
%75 = load i32*, i32** %11
%76 = getelementptr inbounds i32, i32* %75, i32 1
store i32* %76, i32** %11
br label %59
77: ; preds = %72
br label %78
78: ; preds = %77, %49
%79 = load i32*, i32** %11
%80 = load i32, i32* %79
%81 = load i32, i32* @CEC_OP_FEAT_EXT
%82 = and i32 %80, %81
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %78
%85 = load i32**, i32*** %10
store i32* null, i32** %85
%86 = load i32**, i32*** %9
store i32* null, i32** %86
br label %87
87: ; preds = %84, %78
ret void
}

LLVM IR (-O2):
%struct.cec_msg = type { i32* }
@CEC_OP_FEAT_EXT = constant i32 0
define void @cec_ops_report_features(%struct.cec_msg* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32** nocapture writeonly %3, i32** nocapture writeonly %4) {
%6 = getelementptr inbounds %struct.cec_msg, %struct.cec_msg* %0, i64 0, i32 0
%7 = load i32*, i32** %6
%8 = getelementptr inbounds i32, i32* %7, i64 4
%9 = getelementptr inbounds i32, i32* %7, i64 2
%10 = load i32, i32* %9
store i32 %10, i32* %1
%11 = getelementptr inbounds i32, i32* %7, i64 3
%12 = load i32, i32* %11
store i32 %12, i32* %2
store i32* %8, i32** %3
%13 = getelementptr inbounds i32, i32* %7, i64 5
store i32* %13, i32** %4
ret void
}