#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*/ LOG_ERR;
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 /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
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) {
    syslog(LOG_ERR, "socket(udp_notify): %m");
    return -1;
  }
  mc_if.s_addr = addr;
  if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&loopchar,
                 sizeof(loopchar)) < 0) {
    syslog(LOG_ERR, "setsockopt(udp_notify, IP_MULTICAST_LOOP): %m");
    close(s);
    return -1;
  }
  if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, (char *)&mc_if,
                 sizeof(mc_if)) < 0) {
    syslog(LOG_ERR, "setsockopt(udp_notify, IP_MULTICAST_IF): %m");
    close(s);
    return -1;
  }
  if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &bcast, sizeof(bcast)) < 0) {
    syslog(LOG_ERR, "setsockopt(udp_notify, SO_BROADCAST): %m");
    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) {
    syslog(LOG_ERR, "bind(udp_notify): %m");
    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    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11bd <OpenAndConfSSDPNotifySocket+0x5d>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1060 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <OpenAndConfSSDPNotifySocket+0x1de>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
lea    -0x15(%rbp),%rcx
mov    $0x1,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    121e <OpenAndConfSSDPNotifySocket+0xbe>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1060 <syslog@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <OpenAndConfSSDPNotifySocket+0x1de>
mov    -0x14(%rbp),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x8,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    1277 <OpenAndConfSSDPNotifySocket+0x117>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
call   1060 <syslog@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <OpenAndConfSSDPNotifySocket+0x1de>
mov    -0x14(%rbp),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
mov    $0x0,%al
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12d0 <OpenAndConfSSDPNotifySocket+0x170>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
call   1060 <syslog@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <OpenAndConfSSDPNotifySocket+0x1de>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2cf1(%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   1070 <bind@plt>
cmp    $0x0,%rax
jge    1338 <OpenAndConfSSDPNotifySocket+0x1d8>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
call   1060 <syslog@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <OpenAndConfSSDPNotifySocket+0x1de>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenAndConfSSDPNotifySocket>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
movb   $0x0,0x3(%rsp)
movl   $0x1,0x4(%rsp)
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     1275 <OpenAndConfSSDPNotifySocket+0x115>
mov    %eax,%ebx
mov    %r14,0x8(%rsp)
mov    0x2e28(%rip),%r15
mov    (%r15),%esi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
lea    0x3(%rsp),%rcx
mov    $0x1,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
test   %rax,%rax
js     128c <OpenAndConfSSDPNotifySocket+0x12c>
mov    (%r15),%esi
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    $0x8,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
test   %rax,%rax
js     129e <OpenAndConfSSDPNotifySocket+0x13e>
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <setsockopt@plt>
test   %rax,%rax
js     12b0 <OpenAndConfSSDPNotifySocket+0x150>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %r14,0x10(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1070 <bind@plt>
test   %rax,%rax
jns    12d1 <OpenAndConfSSDPNotifySocket+0x171>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
jmp    12c0 <OpenAndConfSSDPNotifySocket+0x160>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
call   1060 <syslog@plt>
jmp    12cc <OpenAndConfSSDPNotifySocket+0x16c>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
jmp    12c0 <OpenAndConfSSDPNotifySocket+0x160>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
jmp    12c0 <OpenAndConfSSDPNotifySocket+0x160>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
call   1060 <syslog@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
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
@LOG_ERR = global i32 0
@.str = [23 x i8] c"socket(udp_notify): %m\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@.str.1 = [46 x i8] c"setsockopt(udp_notify, IP_MULTICAST_LOOP): %m\00"
@IP_MULTICAST_IF = global i32 0
@.str.2 = [44 x i8] c"setsockopt(udp_notify, IP_MULTICAST_IF): %m\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [41 x i8] c"setsockopt(udp_notify, SO_BROADCAST): %m\00"
@AF_INET = global i32 0
@.str.4 = [21 x i8] c"bind(udp_notify): %m\00"
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 %16
13: ; preds = %1
%14 = load i32, i32* @LOG_ERR
%15 = call i32 @syslog(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %70
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
store i8* %17, i8** %18
%19 = load i32, i32* %4
%20 = load i32, i32* @IPPROTO_IP
%21 = load i32, i32* @IP_MULTICAST_LOOP
%22 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %19, i32 %20, i32 %21, i8* %5, i64 1)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i32, i32* @LOG_ERR
%26 = call i32 @syslog(i32 %25, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %4
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %2
br label %70
29: ; preds = %16
%30 = load i32, i32* %4
%31 = load i32, i32* @IPPROTO_IP
%32 = load i32, i32* @IP_MULTICAST_IF
%33 = bitcast %struct.in_addr* %7 to i8*
%34 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %30, i32 %31, i32 %32, i8* %33, i64 8)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = load i32, i32* @LOG_ERR
%38 = call i32 @syslog(i32 %37, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %4
%40 = call i32 @close(i32 %39)
store i32 -1, i32* %2
br label %70
41: ; preds = %29
%42 = load i32, i32* %4
%43 = load i32, i32* @SOL_SOCKET
%44 = load i32, i32* @SO_BROADCAST
%45 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %42, i32 %43, i32 %44, i32* %6, i64 4)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %41
%48 = load i32, i32* @LOG_ERR
%49 = call i32 @syslog(i32 %48, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* %4
%51 = call i32 @close(i32 %50)
store i32 -1, i32* %2
br label %70
52: ; preds = %41
%53 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 16)
%54 = load i32, i32* @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %54, i32* %55
%56 = load i8*, i8** %3
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
store i8* %56, i8** %58
%59 = load i32, i32* %4
%60 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%61 = call i64 @bind(i32 %59, %struct.sockaddr* %60, i32 16)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %68
63: ; preds = %52
%64 = load i32, i32* @LOG_ERR
%65 = call i32 @syslog(i32 %64, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* %4
%67 = call i32 @close(i32 %66)
store i32 -1, i32* %2
br label %70
68: ; preds = %52
%69 = load i32, i32* %4
store i32 %69, i32* %2
br label %70
70: ; preds = %68, %63, %47, %36, %24, %13
%71 = load i32, i32* %2
ret i32 %71
}

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
@LOG_ERR = global i32 0
@.str = [23 x i8] c"socket(udp_notify): %m\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@.str.1 = [46 x i8] c"setsockopt(udp_notify, IP_MULTICAST_LOOP): %m\00"
@IP_MULTICAST_IF = global i32 0
@.str.2 = [44 x i8] c"setsockopt(udp_notify, IP_MULTICAST_IF): %m\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [41 x i8] c"setsockopt(udp_notify, SO_BROADCAST): %m\00"
@AF_INET = global i32 0
@.str.4 = [21 x i8] c"bind(udp_notify): %m\00"
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 %13, label %16
13: ; preds = %1
%14 = load i32, i32* @LOG_ERR
%15 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %56
16: ; preds = %1
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
store i8* %0, i8** %17
%18 = load i32, i32* @IPPROTO_IP
%19 = load i32, i32* @IP_MULTICAST_LOOP
%20 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %11, i32 %18, i32 %19, i8* %2, i64 1)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @LOG_ERR
%24 = call i32 @syslog(i32 %23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @close(i32 %11)
br label %56
26: ; preds = %16
%27 = load i32, i32* @IPPROTO_IP
%28 = load i32, i32* @IP_MULTICAST_IF
%29 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %11, i32 %27, i32 %28, %struct.in_addr* %4, i64 8)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* @LOG_ERR
%33 = call i32 @syslog(i32 %32, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @close(i32 %11)
br label %56
35: ; preds = %26
%36 = load i32, i32* @SOL_SOCKET
%37 = load i32, i32* @SO_BROADCAST
%38 = call i64 (i32, i32, i32, ...) @setsockopt(i32 %11, i32 %36, i32 %37, i32* %3, i64 4)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = load i32, i32* @LOG_ERR
%42 = call i32 @syslog(i32 %41, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @close(i32 %11)
br label %56
44: ; preds = %35
%45 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 16)
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i8* %0, i8** %48
%49 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%50 = call i64 @bind(i32 %11, %struct.sockaddr* %49, i32 16)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %44
%53 = load i32, i32* @LOG_ERR
%54 = call i32 @syslog(i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%55 = call i32 @close(i32 %11)
br label %56
56: ; preds = %44, %52, %40, %31, %22, %13
%57 = phi i32 [ -1, %13 ], [ -1, %22 ], [ -1, %31 ], [ -1, %40 ], [ -1, %52 ], [ %11, %44 ]
ret i32 %57
}