#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;
};

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_IF;
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int multicast_set_ip_iface(int sockfd, struct in_addr *LocalIface) {
  int ret = 0;
  ret = setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_IF, (char *)LocalIface,
                   sizeof(struct in_addr));
  if (ret < 0)
    perror("setting local interface");
  return ret;
}


x86 assembly (clang, -O0):
<multicast_set_ip_iface>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1173 <multicast_set_ip_iface+0x53>
lea    0xe92(%rip),%rdi
call   1040 <perror@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multicast_set_ip_iface>:
push   %rbx
mov    %rsi,%rcx
mov    0x2ebd(%rip),%rax
mov    (%rax),%esi
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ebx
test   %eax,%eax
js     114b <multicast_set_ip_iface+0x2b>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xeae(%rip),%rdi
call   1040 <perror@plt>
jmp    1147 <multicast_set_ip_iface+0x27>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@IPPROTO_IP = global i32 0
@IP_MULTICAST_IF = global i32 0
@.str = [24 x i8] c"setting local interface\00"
define i32 @multicast_set_ip_iface(i32 %0, %struct.in_addr* %1) {
%3 = alloca i32
%4 = alloca %struct.in_addr*
%5 = alloca i32
store i32 %0, i32* %3
store %struct.in_addr* %1, %struct.in_addr** %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* @IPPROTO_IP
%8 = load i32, i32* @IP_MULTICAST_IF
%9 = load %struct.in_addr*, %struct.in_addr** %4
%10 = bitcast %struct.in_addr* %9 to i8*
%11 = call i32 @setsockopt(i32 %6, i32 %7, i32 %8, i8* %10, i32 4)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* %5
ret i32 %17
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@IPPROTO_IP = global i32 0
@IP_MULTICAST_IF = global i32 0
@.str = [24 x i8] c"setting local interface\00"
define i32 @multicast_set_ip_iface(i32 %0, %struct.in_addr* %1) {
%3 = load i32, i32* @IPPROTO_IP
%4 = load i32, i32* @IP_MULTICAST_IF
%5 = bitcast %struct.in_addr* %1 to i8*
%6 = tail call i32 @setsockopt(i32 %0, i32 %3, i32 %4, i8* %5, i32 4)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
ret i32 %6
}