#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ s_addr;
};
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct ip_mreq {
  TYPE_2__ imr_interface;
  TYPE_1__ imr_multiaddr;
};

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_ADD_MEMBERSHIP;
int /*<<< orphan*/ byte_copy(int /*<<< orphan*/ *, int, char const *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct ip_mreq *,
               int);
int socket_mcjoin4(int s, const char ip[4], const char _interface[4]) {
  struct ip_mreq opt;
  byte_copy(&opt.imr_multiaddr.s_addr, 4, ip);
  byte_copy(&opt.imr_interface.s_addr, 4, _interface);
  return (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &opt, sizeof opt));
}


x86 assembly (clang, -O0):
<socket_mcjoin4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rdx
mov    $0x4,%esi
call   1040 <byte_copy@plt>
lea    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x4,%esi
call   1040 <byte_copy@plt>
mov    -0x4(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_mcjoin4>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%rdx
mov    %edi,%ebp
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1040 <byte_copy@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
call   1040 <byte_copy@plt>
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %r14,%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
define i32 @socket_mcjoin4(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.ip_mreq
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %7, i32 0, i32 1
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%10 = load i8*, i8** %5
%11 = call i32 @byte_copy(i32* %9, i32 4, i8* %10)
%12 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %7, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 0
%14 = load i8*, i8** %6
%15 = call i32 @byte_copy(i32* %13, i32 4, i8* %14)
%16 = load i32, i32* %4
%17 = load i32, i32* @IPPROTO_IP
%18 = load i32, i32* @IP_ADD_MEMBERSHIP
%19 = call i32 @setsockopt(i32 %16, i32 %17, i32 %18, %struct.ip_mreq* %7, i32 8)
ret i32 %19
}

LLVM IR (-O2):
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
define i32 @socket_mcjoin4(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.ip_mreq
%5 = bitcast %struct.ip_mreq* %4 to i8*
%6 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %4, i64 0, i32 1, i32 0
%7 = call i32 @byte_copy(i32* %6, i32 4, i8* %1)
%8 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %4, i64 0, i32 0, i32 0
%9 = call i32 @byte_copy(i32* %8, i32 4, i8* %2)
%10 = load i32, i32* @IPPROTO_IP
%11 = load i32, i32* @IP_ADD_MEMBERSHIP
%12 = call i32 @setsockopt(i32 %0, i32 %10, i32 %11, %struct.ip_mreq* %4, i32 8)
ret i32 %12
}