#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 */
typedef int /*<<< orphan*/ yes;
typedef int uint32_t;
struct TYPE_2__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ send_addr;
typedef int /*<<< orphan*/ listen_addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ INADDR_BROADCAST;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
void *htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ udp_recv(int, struct sockaddr_in *, int);
int main() {
  int ret;
  int listen_fd;
  uint32_t yes = 1;
  struct sockaddr_in send_addr;
  struct sockaddr_in listen_addr;
  listen_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (listen_fd == -1) {
    perror("create socket error");
    return -1;
  }
  ret = setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
  if (ret < 0) {
    perror("setsockopt reuseaddr error");
    return -1;
  }
  ret = setsockopt(listen_fd, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes));
  if (ret < 0) {
    perror("setsockopt so_broadcast error\n");
    return -1;
  }
  memset(&listen_addr, 0, sizeof(listen_addr));
  listen_addr.sin_family = AF_INET;
  listen_addr.sin_port = htons(8888);
  listen_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  ret = bind(listen_fd, (struct sockaddr *)&listen_addr, sizeof(listen_addr));
  if (ret == -1) {
    perror("bind addr error");
    return -1;
  }
  memset(&send_addr, 0, sizeof(send_addr));
  send_addr.sin_family = AF_INET;
  send_addr.sin_port = htons(12345);
  send_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
  udp_recv(listen_fd, &send_addr, sizeof(send_addr));
  close(listen_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11e5 <main+0x55>
lea    0xe2c(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1349 <main+0x1b9>
mov    -0xc(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    122e <main+0x9e>
lea    0xdf7(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1349 <main+0x1b9>
mov    -0xc(%rbp),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1277 <main+0xe7>
lea    0xdc9(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1349 <main+0x1b9>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12eb <main+0x15b>
lea    0xd74(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1349 <main+0x1b9>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2cde(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %rax,-0x20(%rbp)
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1090 <udp_recv@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movl   $0x1,0x4(%rsp)
mov    0x2e37(%rip),%r15
mov    (%r15),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     12c5 <main+0x135>
mov    %eax,%ebx
mov    0x2e1a(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     12ce <main+0x13e>
mov    0x0(%rbp),%esi
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     12d7 <main+0x147>
lea    0x8(%rsp),%rbp
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %rax,0x8(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     12e0 <main+0x150>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x30(%rsp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %rax,0x28(%rsp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %rax,0x20(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1090 <udp_recv@plt>
mov    %ebx,%edi
call   1070 <close@plt>
jmp    12f2 <main+0x162>
lea    0xd34(%rip),%rdi
jmp    12e7 <main+0x157>
lea    0xd3f(%rip),%rdi
jmp    12e7 <main+0x157>
lea    0xd51(%rip),%rdi
jmp    12e7 <main+0x157>
lea    0xd67(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [20 x i8] c"create socket error\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [27 x i8] c"setsockopt reuseaddr error\00"
@SO_BROADCAST = global i32 0
@.str.2 = [31 x i8] c"setsockopt so_broadcast error\0A\00"
@INADDR_ANY = global i32 0
@.str.3 = [16 x i8] c"bind addr error\00"
@INADDR_BROADCAST = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
store i32 0, i32* %1
store i32 1, i32* %4
%7 = load i8*, i8** @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i8* %7, i32 %8, i32 0)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %63
14: ; preds = %0
%15 = load i32, i32* %3
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_REUSEADDR
%18 = call i32 @setsockopt(i32 %15, i32 %16, i32 %17, i32* %4, i32 4)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %63
23: ; preds = %14
%24 = load i32, i32* %3
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_BROADCAST
%27 = call i32 @setsockopt(i32 %24, i32 %25, i32 %26, i32* %4, i32 4)
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %63
32: ; preds = %23
%33 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 24)
%34 = load i8*, i8** @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %34, i8** %35
%36 = call i8* @htons(i32 8888)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i8* %36, i8** %37
%38 = load i32, i32* @INADDR_ANY
%39 = call i8* @htonl(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%41 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %40, i32 0, i32 0
store i8* %39, i8** %41
%42 = load i32, i32* %3
%43 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%44 = call i32 @bind(i32 %42, %struct.sockaddr* %43, i32 24)
store i32 %44, i32* %2
%45 = load i32, i32* %2
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %32
%48 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %63
49: ; preds = %32
%50 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 24)
%51 = load i8*, i8** @AF_INET
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i8* %51, i8** %52
%53 = call i8* @htons(i32 12345)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i8* %53, i8** %54
%55 = load i32, i32* @INADDR_BROADCAST
%56 = call i8* @htonl(i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, 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* %3
%60 = call i32 @udp_recv(i32 %59, %struct.sockaddr_in* %5, i32 24)
%61 = load i32, i32* %3
%62 = call i32 @close(i32 %61)
store i32 0, i32* %1
br label %63
63: ; preds = %49, %47, %30, %21, %12
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str = [20 x i8] c"create socket error\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [27 x i8] c"setsockopt reuseaddr error\00"
@SO_BROADCAST = global i32 0
@.str.2 = [31 x i8] c"setsockopt so_broadcast error\0A\00"
@INADDR_ANY = global i32 0
@.str.3 = [16 x i8] c"bind addr error\00"
@INADDR_BROADCAST = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = load i8*, i8** @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i8* %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %52
13: ; preds = %0
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_REUSEADDR
%16 = call i32 @setsockopt(i32 %9, i32 %14, i32 %15, i32* %1, i32 4)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %52
20: ; preds = %13
%21 = load i32, i32* @SOL_SOCKET
%22 = load i32, i32* @SO_BROADCAST
%23 = call i32 @setsockopt(i32 %9, i32 %21, i32 %22, i32* %1, i32 4)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %52
27: ; preds = %20
%28 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 24)
%29 = load i8*, i8** @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %29, i8** %30
%31 = call i8* @htons(i32 8888)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i8* %31, i8** %32
%33 = load i32, i32* @INADDR_ANY
%34 = call i8* @htonl(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i8* %34, i8** %35
%36 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%37 = call i32 @bind(i32 %9, %struct.sockaddr* %36, i32 24)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %27
%40 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %52
41: ; preds = %27
%42 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 24)
%43 = load i8*, i8** @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i8* %43, i8** %44
%45 = call i8* @htons(i32 12345)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i8* %45, i8** %46
%47 = load i32, i32* @INADDR_BROADCAST
%48 = call i8* @htonl(i32 %47)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i8* %48, i8** %49
%50 = call i32 @udp_recv(i32 %9, %struct.sockaddr_in* %2, i32 24)
%51 = call i32 @close(i32 %9)
br label %52
52: ; preds = %41, %39, %25, %18, %11
%53 = phi i32 [ -1, %11 ], [ -1, %18 ], [ -1, %25 ], [ -1, %39 ], [ 0, %41 ]
ret i32 %53
}