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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_IF;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ inet_addr(char const *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct in_addr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int multicast_speak(const char *interface) {
  int socket_descriptor;
  struct in_addr interface_addr;
  socket_descriptor = socket(AF_INET, SOCK_DGRAM, 0);
  if (socket_descriptor < 0) {
    return 0;
  }
  interface_addr.s_addr = inet_addr(interface);
  if (setsockopt(socket_descriptor, IPPROTO_IP, IP_MULTICAST_IF,
                 &interface_addr, sizeof(interface_addr)) < 0) {
    close(socket_descriptor);
    return 0;
  }
  return socket_descriptor;
}


x86 assembly (clang, -O0):
<multicast_speak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117e <multicast_speak+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <multicast_speak+0x92>
mov    -0x10(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    11cc <multicast_speak+0x8c>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <multicast_speak+0x92>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multicast_speak>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11ae <multicast_speak+0x6e>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     11a7 <multicast_speak+0x67>
mov    %ebp,%r14d
jmp    11ae <multicast_speak+0x6e>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@IP_MULTICAST_IF = global i32 0
define i32 @multicast_speak(i8* %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %1
%9 = tail call i32 @inet_addr(i8* %0)
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @IPPROTO_IP
%12 = load i32, i32* @IP_MULTICAST_IF
%13 = call i64 @setsockopt(i32 %6, i32 %11, i32 %12, %struct.in_addr* %2, i32 4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @close(i32 %6)
br label %17
17: ; preds = %8, %1, %15
%18 = phi i32 [ 0, %15 ], [ 0, %1 ], [ %6, %8 ]
ret i32 %18
}