#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};

/* Variables and functions */
scalar_t__ IN_MULTICAST(int /*<<< orphan*/);
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
unsigned int num_inet_mcaddrs(const struct sockaddr_in *sa_list,
                              const int sa_list_len) {
  int sa_num;
  unsigned int num_mcaddrs = 0;
  const struct sockaddr_in *sa;
  for (sa_num = 0; sa_num < sa_list_len; sa_num++) {
    sa = &sa_list[sa_num];
    if (IN_MULTICAST(ntohl(sa->sin_addr.s_addr))) {
      num_mcaddrs++;
    }
  }
  return num_mcaddrs;
}


x86 assembly (clang, -O0):
<num_inet_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    1194 <num_inet_mcaddrs+0x74>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohl@plt>
mov    %eax,%edi
call   1030 <IN_MULTICAST@plt>
cmp    $0x0,%rax
je     1181 <num_inet_mcaddrs+0x61>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <num_inet_mcaddrs+0x66>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <num_inet_mcaddrs+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_inet_mcaddrs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1162 <num_inet_mcaddrs+0x42>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbx,4),%edi
call   1040 <ntohl@plt>
mov    %eax,%edi
call   1030 <IN_MULTICAST@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <num_inet_mcaddrs+0x20>
jmp    1164 <num_inet_mcaddrs+0x44>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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