#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;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ send_addr;
typedef int /*<<< orphan*/ optval;
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);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void *htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int);
int /*<<< orphan*/ udp_send(int, struct sockaddr_in *, int);
int main(int argc, char **argv) {
  int ret;
  int sockfd;
  int optval = 1;
  struct sockaddr_in send_addr;
  struct sockaddr_in listen_addr;
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    printf("create socket error: %s(errno: %d)\n", strerror(errno), errno);
    exit(0);
  }
  ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
  if (ret < 0) {
    perror("setsockopt reuseaddr error");
    return -1;
  }
  ret = setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval));
  if (ret < 0) {
    perror("setsockopt error");
    return -1;
  }
  memset(&listen_addr, 0, sizeof(listen_addr));
  listen_addr.sin_family = AF_INET;
  listen_addr.sin_port = htons(12345);
  listen_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  ret = bind(sockfd, (struct sockaddr *)&listen_addr, sizeof(listen_addr));
  if (ret < 0) {
    perror("bind error");
    return -1;
  }
  memset(&send_addr, 0, sizeof(send_addr));
  send_addr.sin_family = AF_INET;
  send_addr.sin_port = htons(8888);
  send_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
  udp_send(sockfd, &send_addr, sizeof(send_addr));
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1230 <main+0x70>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
lea    0xddc(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1279 <main+0xb9>
lea    0xdbc(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1394 <main+0x1d4>
mov    -0x18(%rbp),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12c2 <main+0x102>
lea    0xd8e(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1394 <main+0x1d4>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %rax,-0x48(%rbp)
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x18,%edx
call   1090 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1336 <main+0x176>
lea    0xd2b(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1394 <main+0x1d4>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2c93(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    0x2c67(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   10b0 <udp_send@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%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    0x2e07(%rip),%r15
mov    (%r15),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12c1 <main+0x101>
mov    %eax,%ebp
mov    0x2deb(%rip),%rbx
mov    (%rbx),%esi
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jns    122a <main+0x6a>
lea    0xdff(%rip),%rdi
jmp    12ac <main+0xec>
mov    (%rbx),%esi
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jns    1254 <main+0x94>
lea    0xded(%rip),%rdi
jmp    12ac <main+0xec>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   1090 <bind@plt>
test   %eax,%eax
jns    12e7 <main+0x127>
lea    0xda4(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ce8(%rip),%rbx
mov    (%rbx),%edi
call   10d0 <strerror@plt>
mov    (%rbx),%edx
lea    0xd28(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x30(%rsp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %rax,0x28(%rsp)
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,0x20(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   10b0 <udp_send@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

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

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