#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__ {
  void *s_addr;
};
struct TYPE_3__ {
  void *s_addr;
};
struct ip_mreq {
  TYPE_2__ imr_interface;
  TYPE_1__ imr_multiaddr;
};
typedef int /*<<< orphan*/ group;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_ADD_MEMBERSHIP;
void *inet_addr(char const *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int multicast_join_group(int socket_descriptor, const char *address,
                         const char *interface) {
  struct ip_mreq group;
  group.imr_multiaddr.s_addr = inet_addr(address);
  group.imr_interface.s_addr = inet_addr(interface);
  if (setsockopt(socket_descriptor, IPPROTO_IP, IP_ADD_MEMBERSHIP,
                 (char *)&group, sizeof(group)) < 0) {
    return 0;
  }
  return socket_descriptor;
}


x86 assembly (clang, -O0):
<multicast_join_group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1187 <multicast_join_group+0x67>
movl   $0x0,-0x4(%rbp)
jmp    118d <multicast_join_group+0x6d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multicast_join_group>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <inet_addr@plt>
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
call   1040 <inet_addr@plt>
mov    %rax,0x8(%rsp)
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmovns %ebp,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i8* }
%struct.TYPE_3__ = type { i8* }
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
define i32 @multicast_join_group(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.ip_mreq
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = call i8* @inet_addr(i8* %9)
%11 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %8, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
store i8* %10, i8** %12
%13 = load i8*, i8** %7
%14 = call i8* @inet_addr(i8* %13)
%15 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %8, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
store i8* %14, i8** %16
%17 = load i32, i32* %5
%18 = load i32, i32* @IPPROTO_IP
%19 = load i32, i32* @IP_ADD_MEMBERSHIP
%20 = bitcast %struct.ip_mreq* %8 to i8*
%21 = call i64 @setsockopt(i32 %17, i32 %18, i32 %19, i8* %20, i32 16)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %3
store i32 0, i32* %4
br label %26
24: ; preds = %3
%25 = load i32, i32* %5
store i32 %25, i32* %4
br label %26
26: ; preds = %24, %23
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i8* }
%struct.TYPE_3__ = type { i8* }
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
define i32 @multicast_join_group(i32 %0, i8* %1, i8* %2) {
%4 = alloca %struct.ip_mreq
%5 = bitcast %struct.ip_mreq* %4 to i8*
%6 = tail call i8* @inet_addr(i8* %1)
%7 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %4, i64 0, i32 1, i32 0
store i8* %6, i8** %7
%8 = tail call i8* @inet_addr(i8* %2)
%9 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %4, i64 0, i32 0, i32 0
store i8* %8, i8** %9
%10 = load i32, i32* @IPPROTO_IP
%11 = load i32, i32* @IP_ADD_MEMBERSHIP
%12 = call i64 @setsockopt(i32 %0, i32 %10, i32 %11, i8* %5, i32 16)
%13 = icmp slt i64 %12, 0
%14 = select i1 %13, i32 0, i32 %0
ret i32 %14
}