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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ IP_MULTICAST_TTL;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ logperror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int support_multicast() {
  int sock;
  u_char ttl = 1;
  sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (sock < 0) {
    logperror("support_multicast: socket");
    return (0);
  }
  if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl,
                 sizeof(ttl)) < 0) {
    (void)close(sock);
    return (0);
  }
  (void)close(sock);
  return (1);
}


x86 assembly (clang, -O0):
<support_multicast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0xc(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1194 <support_multicast+0x54>
lea    0xe7d(%rip),%rdi
call   1030 <logperror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <support_multicast+0xa5>
mov    -0x8(%rbp),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    11d6 <support_multicast+0x96>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <support_multicast+0xa5>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<support_multicast>:
push   %rbp
push   %rbx
push   %rax
movl   $0x1,0x4(%rsp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11a8 <support_multicast+0x68>
mov    %eax,%ebp
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1050 <close@plt>
shr    $0x3f,%rbx
xor    $0x1,%ebx
jmp    11b6 <support_multicast+0x76>
lea    0xe51(%rip),%rdi
call   1030 <logperror@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [26 x i8] c"support_multicast: socket\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
define i32 @support_multicast() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 1, i32* %3
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = load i32, i32* @IPPROTO_UDP
%7 = call i32 @socket(i32 %4, i32 %5, i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @logperror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %25
12: ; preds = %0
%13 = load i32, i32* %2
%14 = load i32, i32* @IPPROTO_IP
%15 = load i32, i32* @IP_MULTICAST_TTL
%16 = bitcast i32* %3 to i8*
%17 = call i64 @setsockopt(i32 %13, i32 %14, i32 %15, i8* %16, i32 4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
store i32 0, i32* %1
br label %25
22: ; preds = %12
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
store i32 1, i32* %1
br label %25
25: ; preds = %22, %19, %10
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [26 x i8] c"support_multicast: socket\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
define i32 @support_multicast() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = load i32, i32* @IPPROTO_UDP
%6 = tail call i32 @socket(i32 %3, i32 %4, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @logperror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %18
10: ; preds = %0
%11 = load i32, i32* @IPPROTO_IP
%12 = load i32, i32* @IP_MULTICAST_TTL
%13 = call i64 @setsockopt(i32 %6, i32 %11, i32 %12, i8* %2, i32 4)
%14 = call i32 @close(i32 %6)
%15 = lshr i64 %13, 63
%16 = trunc i64 %15 to i32
%17 = xor i32 %16, 1
br label %18
18: ; preds = %10, %8
%19 = phi i32 [ 0, %8 ], [ %17, %10 ]
ret i32 %19
}