#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 sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};

/* Variables and functions */
scalar_t__ IN6_IS_ADDR_MULTICAST(int /*<<< orphan*/ *);
unsigned int num_inet6_mcaddrs(const struct sockaddr_in6 *sa_list,
                               const int sa_list_len) {
  int sa_num;
  unsigned int num_mcaddrs = 0;
  const struct sockaddr_in6 *sa;
  for (sa_num = 0; sa_num < sa_list_len; sa_num++) {
    sa = &sa_list[sa_num];
    if (IN6_IS_ADDR_MULTICAST(&sa->sin6_addr)) {
      num_mcaddrs++;
    }
  }
  return num_mcaddrs;
}


x86 assembly (clang, -O0):
<num_inet6_mcaddrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117b <num_inet6_mcaddrs+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <IN6_IS_ADDR_MULTICAST@plt>
cmp    $0x0,%rax
je     1168 <num_inet6_mcaddrs+0x58>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <num_inet6_mcaddrs+0x5d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <num_inet6_mcaddrs+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_inet6_mcaddrs>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    113c <num_inet6_mcaddrs+0x2c>
mov    %rdi,%rbx
mov    %esi,%ebp
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <IN6_IS_ADDR_MULTICAST@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r14d
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    1120 <num_inet6_mcaddrs+0x10>
jmp    113f <num_inet6_mcaddrs+0x2f>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
define i32 @num_inet6_mcaddrs(%struct.sockaddr_in6* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in6*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_in6*
store %struct.sockaddr_in6* %0, %struct.sockaddr_in6** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %13, i64 %15
store %struct.sockaddr_in6* %16, %struct.sockaddr_in6** %7
%17 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%18 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %17, i32 0, i32 0
%19 = call i64 @IN6_IS_ADDR_MULTICAST(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32, i32* %6
%23 = add i32 %22, 1
store i32 %23, i32* %6
br label %24
24: ; preds = %21, %12
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %8
28: ; preds = %8
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
define i32 @num_inet6_mcaddrs(%struct.sockaddr_in6* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %14, %6 ]
%8 = phi i32 [ 0, %4 ], [ %13, %6 ]
%9 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %0, i64 %7, i32 0
%10 = tail call i64 @IN6_IS_ADDR_MULTICAST(i32* %9)
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i32
%13 = add i32 %8, %12
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %16, label %6
16: ; preds = %6, %2
%17 = phi i32 [ 0, %2 ], [ %13, %6 ]
ret i32 %17
}