#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;
};
typedef int /*<<< orphan*/ in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_ADD_MEMBERSHIP;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int AddMulticastMembership(int s, in_addr_t ifaddr) {
  struct ip_mreq imr;
  imr.imr_multiaddr.s_addr = inet_addr(("239.255.255.250"));
  imr.imr_interface.s_addr = ifaddr;
  if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr,
                 sizeof(struct ip_mreq)) < 0) {
    syslog(LOG_ERR, "setsockopt(udp, IP_ADD_MEMBERSHIP): %m");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<AddMulticastMembership>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xebb(%rip),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    11a2 <AddMulticastMembership+0x72>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1050 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <AddMulticastMembership+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AddMulticastMembership>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xec2(%rip),%rdi
call   1040 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %ebx,(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %ebp,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    1190 <AddMulticastMembership+0x60>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1050 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
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 }
@.str = [16 x i8] c"239.255.255.250\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [39 x i8] c"setsockopt(udp, IP_ADD_MEMBERSHIP): %m\00"
define i32 @AddMulticastMembership(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.ip_mreq
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %6, i32 0, i32 1
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
store i32 %7, i32* %9
%10 = load i32, i32* %5
%11 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %6, i32 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load i32, i32* %4
%14 = load i32, i32* @IPPROTO_IP
%15 = load i32, i32* @IP_ADD_MEMBERSHIP
%16 = bitcast %struct.ip_mreq* %6 to i8*
%17 = call i64 @setsockopt(i32 %13, i32 %14, i32 %15, i8* %16, i32 8)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @LOG_ERR
%21 = call i32 @syslog(i32 %20, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %23
22: ; preds = %2
store i32 0, i32* %3
br label %23
23: ; preds = %22, %19
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.ip_mreq = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
@.str = [16 x i8] c"239.255.255.250\00"
@IPPROTO_IP = global i32 0
@IP_ADD_MEMBERSHIP = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [39 x i8] c"setsockopt(udp, IP_ADD_MEMBERSHIP): %m\00"
define i32 @AddMulticastMembership(i32 %0, i32 %1) {
%3 = alloca %struct.ip_mreq
%4 = bitcast %struct.ip_mreq* %3 to i8*
%5 = tail call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %3, i64 0, i32 1, i32 0
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %3, i64 0, i32 0, i32 0
store i32 %1, i32* %7
%8 = load i32, i32* @IPPROTO_IP
%9 = load i32, i32* @IP_ADD_MEMBERSHIP
%10 = call i64 @setsockopt(i32 %0, i32 %8, i32 %9, i8* %4, i32 8)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @LOG_ERR
%14 = call i32 @syslog(i32 %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %2, %12
%16 = phi i32 [ -1, %12 ], [ 0, %2 ]
ret i32 %16
}