#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct group_req {
  int gr_interface;
  int /*<<< orphan*/ gr_group;
};
typedef int /*<<< orphan*/ req;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ MCAST_JOIN_GROUP;
int /*<<< orphan*/ SOL_IP;
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct group_req *,
               int);
int join_group(int fd, int ifindex, struct in_addr group_addr) {
  struct group_req req;
  struct sockaddr_in *group_sa = (struct sockaddr_in *)&req.gr_group;
  memset(group_sa, 0, sizeof(*group_sa));
  group_sa->sin_family = AF_INET;
  group_sa->sin_addr = group_addr;
  group_sa->sin_port = htons(0);
  req.gr_interface = ifindex;
  return setsockopt(fd, SOL_IP, MCAST_JOIN_GROUP, &req, sizeof(req));
}


x86 assembly (clang, -O0):
<join_group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edx,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
lea    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %ecx,0x4(%rax)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_group>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %ebx,0x10(%rsp)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    %ebp,0x8(%rsp)
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %r14d,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.group_req = type { i32, i32 }
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
@AF_INET = global i32 0
@SOL_IP = global i32 0
@MCAST_JOIN_GROUP = global i32 0
define i32 @join_group(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.in_addr
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.group_req
%8 = alloca %struct.sockaddr_in*
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
store i32 %2, i32* %9
store i32 %0, i32* %5
store i32 %1, i32* %6
%10 = getelementptr inbounds %struct.group_req, %struct.group_req* %7, i32 0, i32 1
%11 = bitcast i32* %10 to %struct.sockaddr_in*
store %struct.sockaddr_in* %11, %struct.sockaddr_in** %8
%12 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%13 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 2
store i32 %14, i32* %16
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
%19 = bitcast %struct.in_addr* %18 to i8*
%20 = bitcast %struct.in_addr* %4 to i8*
%21 = call i32 @htons(i32 0)
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* %6
%25 = getelementptr inbounds %struct.group_req, %struct.group_req* %7, i32 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* %5
%27 = load i32, i32* @SOL_IP
%28 = load i32, i32* @MCAST_JOIN_GROUP
%29 = call i32 @setsockopt(i32 %26, i32 %27, i32 %28, %struct.group_req* %7, i32 8)
ret i32 %29
}

LLVM IR (-O2):
%struct.group_req = type { i32, i32 }
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@SOL_IP = global i32 0
@MCAST_JOIN_GROUP = global i32 0
define i32 @join_group(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.group_req
%5 = bitcast %struct.group_req* %4 to i8*
%6 = getelementptr inbounds %struct.group_req, %struct.group_req* %4, i64 0, i32 1
%7 = bitcast i32* %6 to %struct.sockaddr_in*
%8 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds i32, i32* %6, i64 2
store i32 %9, i32* %10
%11 = getelementptr inbounds i32, i32* %6, i64 1
store i32 %2, i32* %11
%12 = call i32 @htons(i32 0)
store i32 %12, i32* %6
%13 = getelementptr inbounds %struct.group_req, %struct.group_req* %4, i64 0, i32 0
store i32 %1, i32* %13
%14 = load i32, i32* @SOL_IP
%15 = load i32, i32* @MCAST_JOIN_GROUP
%16 = call i32 @setsockopt(i32 %0, i32 %14, i32 %15, %struct.group_req* %4, i32 8)
ret i32 %16
}