#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__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ on;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_LOOP;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ log_message(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int create_recv_sock() {
  int sd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sd < 0) {
    log_message(LOG_ERR, "recv socket(): %m");
    return sd;
  }
  int r = -1;
  int on = 1;
  if ((r = setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) < 0) {
    log_message(LOG_ERR, "recv setsockopt(SO_REUSEADDR): %m");
    return r;
  }
  struct sockaddr_in serveraddr;
  memset(&serveraddr, 0, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_port = htons(5353);
  serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
  if ((r = bind(sd, (struct sockaddr *)&serveraddr, sizeof(serveraddr))) < 0) {
    log_message(LOG_ERR, "recv bind(): %m");
  }
  if ((r = setsockopt(sd, IPPROTO_IP, IP_MULTICAST_LOOP, &on, sizeof(on))) <
      0) {
    log_message(LOG_ERR, "recv setsockopt(IP_MULTICAST_LOOP): %m");
    return r;
  }
  return sd;
}


x86 assembly (clang, -O0):
<create_recv_sock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11be <create_recv_sock+0x4e>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1070 <log_message@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12de <create_recv_sock+0x16e>
movl   $0xffffffff,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    121c <create_recv_sock+0xac>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1070 <log_message@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12de <create_recv_sock+0x16e>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x14e9,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1288 <create_recv_sock+0x118>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
call   1070 <log_message@plt>
mov    -0x8(%rbp),%edi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
mov    0x2d55(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    12d8 <create_recv_sock+0x168>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
call   1070 <log_message@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12de <create_recv_sock+0x16e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_recv_sock>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e59(%rip),%r14
mov    (%r14),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     126f <create_recv_sock+0xff>
movl   $0x1,0xc(%rsp)
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     1286 <create_recv_sock+0x116>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x14e9,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %eax,%eax
jns    1233 <create_recv_sock+0xc3>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
call   1070 <log_message@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jns    129f <create_recv_sock+0x12f>
mov    %eax,%ebp
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
jmp    1298 <create_recv_sock+0x128>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xd81(%rip),%rsi
call   1070 <log_message@plt>
jmp    129f <create_recv_sock+0x12f>
mov    %eax,%ebp
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
call   1070 <log_message@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@LOG_ERR = global i32 0
@.str = [18 x i8] c"recv socket(): %m\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [34 x i8] c"recv setsockopt(SO_REUSEADDR): %m\00"
@INADDR_ANY = global i32 0
@.str.2 = [16 x i8] c"recv bind(): %m\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@.str.3 = [39 x i8] c"recv setsockopt(IP_MULTICAST_LOOP): %m\00"
define i32 @create_recv_sock() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%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* %2
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @LOG_ERR
%13 = call i32 @log_message(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %2
store i32 %14, i32* %1
br label %54
15: ; preds = %0
store i32 -1, i32* %3
store i32 1, i32* %4
%16 = load i32, i32* %2
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_REUSEADDR
%19 = call i32 @setsockopt(i32 %16, i32 %17, i32 %18, i32* %4, i32 4)
store i32 %19, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* @LOG_ERR
%23 = call i32 @log_message(i32 %22, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* %3
store i32 %24, i32* %1
br label %54
25: ; preds = %15
%26 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @htons(i32 5353)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %29, i32* %30
%31 = load i32, i32* @INADDR_ANY
%32 = call i32 @htonl(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
store i32 %32, i32* %34
%35 = load i32, i32* %2
%36 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%37 = call i32 @bind(i32 %35, %struct.sockaddr* %36, i32 12)
store i32 %37, i32* %3
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %25
%40 = load i32, i32* @LOG_ERR
%41 = call i32 @log_message(i32 %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %39, %25
%43 = load i32, i32* %2
%44 = load i32, i32* @IPPROTO_IP
%45 = load i32, i32* @IP_MULTICAST_LOOP
%46 = call i32 @setsockopt(i32 %43, i32 %44, i32 %45, i32* %4, i32 4)
store i32 %46, i32* %3
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %42
%49 = load i32, i32* @LOG_ERR
%50 = call i32 @log_message(i32 %49, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* %3
store i32 %51, i32* %1
br label %54
52: ; preds = %42
%53 = load i32, i32* %2
store i32 %53, i32* %1
br label %54
54: ; preds = %52, %48, %21, %11
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@LOG_ERR = global i32 0
@.str = [18 x i8] c"recv socket(): %m\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [34 x i8] c"recv setsockopt(SO_REUSEADDR): %m\00"
@INADDR_ANY = global i32 0
@.str.2 = [16 x i8] c"recv bind(): %m\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_LOOP = global i32 0
@.str.3 = [39 x i8] c"recv setsockopt(IP_MULTICAST_LOOP): %m\00"
define i32 @create_recv_sock() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @LOG_ERR
%9 = tail call i32 @log_message(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %47
10: ; preds = %0
%11 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_REUSEADDR
%14 = call i32 @setsockopt(i32 %5, i32 %12, i32 %13, i32* %1, i32 4)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* @LOG_ERR
%18 = call i32 @log_message(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %45
19: ; preds = %10
%20 = bitcast %struct.sockaddr_in* %2 to i8*
%21 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @htons(i32 5353)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = call i32 @htonl(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%30 = call i32 @bind(i32 %5, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %19
%33 = load i32, i32* @LOG_ERR
%34 = call i32 @log_message(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %32, %19
%36 = load i32, i32* @IPPROTO_IP
%37 = load i32, i32* @IP_MULTICAST_LOOP
%38 = call i32 @setsockopt(i32 %5, i32 %36, i32 %37, i32* %1, i32 4)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* @LOG_ERR
%42 = call i32 @log_message(i32 %41, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %35, %40
%44 = phi i32 [ %38, %40 ], [ %5, %35 ]
br label %45
45: ; preds = %43, %16
%46 = phi i32 [ %14, %16 ], [ %44, %43 ]
br label %47
47: ; preds = %45, %7
%48 = phi i32 [ %5, %7 ], [ %46, %45 ]
ret i32 %48
}