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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_LOOP;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int multicast_set_ip_reuse(int sockfd) {
  char reuse = '0';
  int ret = 0;
  ret = setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&reuse,
                   sizeof(reuse));
  if (ret < 0) {
    perror("setting IP_MULTICAST_LOOP");
    close(sockfd);
  }
  return ret;
}


x86 assembly (clang, -O0):
<multicast_set_ip_reuse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x30,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
lea    -0x5(%rbp),%rcx
mov    $0x1,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    118b <multicast_set_ip_reuse+0x5b>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multicast_set_ip_reuse>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x30,0x7(%rsp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
mov    0x2ea6(%rip),%rax
mov    (%rax),%edx
lea    0x7(%rsp),%rcx
mov    $0x1,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ebp
test   %eax,%eax
js     116b <multicast_set_ip_reuse+0x3b>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8e(%rip),%rdi
call   1050 <perror@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    1162 <multicast_set_ip_reuse+0x32>

LLVM IR (-O0):
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@.str = [26 x i8] c"setting IP_MULTICAST_LOOP\00"
define i32 @multicast_set_ip_reuse(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i32 %0, i32* %2
store i8 48, i8* %3
store i32 0, i32* %4
%5 = load i32, i32* %2
%6 = load i32, i32* @IPPROTO_IP
%7 = load i32, i32* @IP_MULTICAST_LOOP
%8 = call i32 @setsockopt(i32 %5, i32 %6, i32 %7, i8* %3, i32 1)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %2
%14 = call i32 @close(i32 %13)
br label %15
15: ; preds = %11, %1
%16 = load i32, i32* %4
ret i32 %16
}

LLVM IR (-O2):
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@.str = [26 x i8] c"setting IP_MULTICAST_LOOP\00"
define i32 @multicast_set_ip_reuse(i32 %0) {
%2 = alloca i8
store i8 48, i8* %2
%3 = load i32, i32* @IPPROTO_IP
%4 = load i32, i32* @IP_MULTICAST_LOOP
%5 = call i32 @setsockopt(i32 %0, i32 %3, i32 %4, i8* %2, i32 1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @close(i32 %0)
br label %10
10: ; preds = %7, %1
ret i32 %5
}