#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_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  void *s_addr;
};
typedef int /*<<< orphan*/ mc_if;
typedef int /*<<< orphan*/ loopchar;
typedef void *in_addr_t;
typedef int /*<<< orphan*/ bcast;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_IF;
int /*<<< orphan*/ IP_MULTICAST_LOOP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int OpenAndConfSSDPNotifySocket(in_addr_t addr) {
  int s;
  unsigned char loopchar = 0;
  int bcast = 1;
  struct in_addr mc_if;
  struct sockaddr_in sockname;
  if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
    {};
    return -1;
  }
  mc_if.s_addr = addr;
  if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loopchar,
                 sizeof(loopchar)) < 0) {
    {};
    close(s);
    return -1;
  }
  if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, (char *)&mc_if,
                 sizeof(mc_if)) < 0) {
    {};
    close(s);
    return -1;
  }
  if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &bcast, sizeof(bcast)) < 0) {
    {};
    close(s);
    return -1;
  }
  memset(&sockname, 0, sizeof(struct sockaddr_in));
  sockname.sin_family = AF_INET;
  sockname.sin_addr.s_addr = addr;
  if (bind(s, (struct sockaddr *)&sockname, sizeof(struct sockaddr_in)) < 0) {
    {};
    close(s);
    return -1;
  }
  return s;
}


x86 assembly (clang, -O0):
<OpenAndConfSSDPNotifySocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x0,-0x15(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1198 <OpenAndConfSSDPNotifySocket+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <OpenAndConfSSDPNotifySocket+0x175>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
lea    -0x15(%rbp),%rcx
mov    $0x1,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    11e4 <OpenAndConfSSDPNotifySocket+0x94>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <OpenAndConfSSDPNotifySocket+0x175>
mov    -0x14(%rbp),%edi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x8,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1228 <OpenAndConfSSDPNotifySocket+0xd8>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <OpenAndConfSSDPNotifySocket+0x175>
mov    -0x14(%rbp),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    126c <OpenAndConfSSDPNotifySocket+0x11c>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <OpenAndConfSSDPNotifySocket+0x175>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    12bf <OpenAndConfSSDPNotifySocket+0x16f>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c5 <OpenAndConfSSDPNotifySocket+0x175>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenAndConfSSDPNotifySocket>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
movb   $0x0,0x3(%rsp)
movl   $0x1,0x4(%rsp)
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    $0xffffffff,%r12d
test   %eax,%eax
js     125e <OpenAndConfSSDPNotifySocket+0x10e>
mov    %eax,%ebp
mov    %r14,0x8(%rsp)
mov    0x2e2f(%rip),%rbx
mov    (%rbx),%esi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
lea    0x3(%rsp),%rcx
mov    $0x1,%r8d
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1257 <OpenAndConfSSDPNotifySocket+0x107>
mov    (%rbx),%esi
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x8,%r8d
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1257 <OpenAndConfSSDPNotifySocket+0x107>
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    0x2dbb(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1257 <OpenAndConfSSDPNotifySocket+0x107>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %r14,0x10(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1060 <bind@plt>
test   %rax,%rax
js     1257 <OpenAndConfSSDPNotifySocket+0x107>
mov    %ebp,%r12d
jmp    125e <OpenAndConfSSDPNotifySocket+0x10e>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r12d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i8* }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@IP_MULTICAST_IF = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@AF_INET = global i32 0
define i32 @OpenAndConfSSDPNotifySocket(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca %struct.in_addr
%8 = alloca %struct.sockaddr_in
store i8* %0, i8** %3
store i8 0, i8* %5
store i32 1, i32* %6
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %60
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
store i8* %15, i8** %16
%17 = load i32, i32* %4
%18 = load i32, i32* @IPPROTO_IP
%19 = load i32, i32* @IP_MULTICAST_LOOP
%20 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %17, i32 %18, i32 %19, i8* %5, i64 1)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
store i32 -1, i32* %2
br label %60
25: ; preds = %14
%26 = load i32, i32* %4
%27 = load i32, i32* @IPPROTO_IP
%28 = load i32, i32* @IP_MULTICAST_IF
%29 = bitcast %struct.in_addr* %7 to i8*
%30 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %26, i32 %27, i32 %28, i8* %29, i64 8)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %4
%34 = call i32 @close(i32 %33)
store i32 -1, i32* %2
br label %60
35: ; preds = %25
%36 = load i32, i32* %4
%37 = load i32, i32* @SOL_SOCKET
%38 = load i32, i32* @SO_BROADCAST
%39 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %36, i32 %37, i32 %38, i32* %6, i64 4)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i32, i32* %4
%43 = call i32 @close(i32 %42)
store i32 -1, i32* %2
br label %60
44: ; preds = %35
%45 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 16)
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %46, i32* %47
%48 = load i8*, i8** %3
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 0
store i8* %48, i8** %50
%51 = load i32, i32* %4
%52 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%53 = call i64 @bind(i32 %51, %struct.sockaddr* %52, i32 16)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %44
%56 = load i32, i32* %4
%57 = call i32 @close(i32 %56)
store i32 -1, i32* %2
br label %60
58: ; preds = %44
%59 = load i32, i32* %4
store i32 %59, i32* %2
br label %60
60: ; preds = %58, %55, %41, %32, %22, %13
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
%struct.in_addr = type { i8* }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@IP_MULTICAST_IF = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@AF_INET = global i32 0
define i32 @OpenAndConfSSDPNotifySocket(i8* %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca %struct.in_addr
%5 = alloca %struct.sockaddr_in
store i8 0, i8* %2
%6 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%7 = bitcast %struct.in_addr* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %39, label %13
13: ; preds = %1
%14 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
store i8* %0, i8** %14
%15 = load i32, i32* @IPPROTO_IP
%16 = load i32, i32* @IP_MULTICAST_LOOP
%17 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %11, i32 %15, i32 %16, i8* %2, i64 1)
%18 = icmp slt i64 %17, 0
br i1 %18, label %37, label %19
19: ; preds = %13
%20 = load i32, i32* @IPPROTO_IP
%21 = load i32, i32* @IP_MULTICAST_IF
%22 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %11, i32 %20, i32 %21, %struct.in_addr* %4, i64 8)
%23 = icmp slt i64 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %19
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_BROADCAST
%27 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %11, i32 %25, i32 %26, i32* %3, i64 4)
%28 = icmp slt i64 %27, 0
br i1 %28, label %37, label %29
29: ; preds = %24
%30 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 16)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i8* %0, i8** %33
%34 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%35 = call i64 @bind(i32 %11, %struct.sockaddr* %34, i32 16)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %29, %24, %19, %13
%38 = call i32 @close(i32 %11)
br label %39
39: ; preds = %37, %29, %1
%40 = phi i32 [ -1, %1 ], [ %11, %29 ], [ -1, %37 ]
ret i32 %40
}