#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int SO_BROADCAST;
int SO_REUSEADDR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int main() {
  char msg[128] = "I am broadCast message from server!";
  int brdcFd;
  if ((brdcFd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
    printf("socket fail\n");
    return -1;
  }
  int optval = 1;
  setsockopt(brdcFd, SOL_SOCKET, SO_BROADCAST | SO_REUSEADDR, &optval,
             sizeof(int));
  struct sockaddr_in theirAddr;
  memset(&theirAddr, 0, sizeof(struct sockaddr_in));
  theirAddr.sin_family = AF_INET;
  theirAddr.sin_addr.s_addr = inet_addr("255.255.255.255");
  theirAddr.sin_port = htons(4001);
  int sendBytes;
  if ((sendBytes =
           sendto(brdcFd, msg, strlen(msg), 0, (struct sockaddr *)&theirAddr,
                  sizeof(struct sockaddr))) == -1) {
    printf("sendto fail, errno=%d\n", errno);
    return -1;
  }
  printf("msg=%s, msgLen=%d, sendBytes=%d\n", msg, strlen(msg), sendBytes);
  close(brdcFd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe40(%rip),%rsi
mov    $0x80,%edx
call   10b0 <memcpy@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x94(%rbp)
cmp    $0xffffffff,%eax
jne    120c <main+0x6c>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1351 <main+0x1b1>
movl   $0x1,-0x98(%rbp)
mov    -0x94(%rbp),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
mov    0x2d7b(%rip),%rax
or     (%rax),%edx
lea    -0x98(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0xa8(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa0(%rbp)
lea    0xe1b(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0xa4(%rbp)
mov    $0xfa1,%edi
call   1050 <htons@plt>
mov    %eax,-0xa8(%rbp)
mov    -0x94(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
lea    -0xa8(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
mov    %eax,-0xac(%rbp)
cmp    $0xffffffff,%eax
jne    1308 <main+0x168>
mov    0x2cd4(%rip),%rax
mov    (%rax),%esi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1351 <main+0x1b1>
lea    -0x90(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
mov    -0xac(%rbp),%ecx
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x94(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe62(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe46(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe2a(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe0e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xdf2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     1304 <main+0x164>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    0x2d81(%rip),%rax
mov    0x2d5a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0xde9(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0xfa1,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x4,%r9d
call   1090 <sendto@plt>
cmp    $0xffffffff,%eax
je     1312 <main+0x172>
mov    %eax,%ebp
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0xdba(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
jmp    132f <main+0x18f>
lea    0xdbd(%rip),%rdi
call   1030 <puts@plt>
jmp    1329 <main+0x189>
mov    0x2ca7(%rip),%rax
mov    (%rax),%esi
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.msg = [128 x i8] c"I am broadCast message from server!\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socket fail\0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@.str.1 = [16 x i8] c"255.255.255.255\00"
@.str.2 = [23 x i8] c"sendto fail, errno=%d\0A\00"
@errno = global i32 0
@.str.3 = [33 x i8] c"msg=%s, msgLen=%d, sendBytes=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [128 x i8]* %2 to i8*
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %47
14: ; preds = %0
store i32 1, i32* %4
%15 = load i32, i32* %3
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_BROADCAST
%18 = load i32, i32* @SO_REUSEADDR
%19 = or i32 %17, %18
%20 = call i32 @setsockopt(i32 %15, i32 %16, i32 %19, i32* %4, i32 4)
%21 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = call i32 @htons(i32 4001)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* %3
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%34 = call i32 @sendto(i32 %29, i8* %30, i32 %32, i32 0, %struct.sockaddr* %33, i32 4)
store i32 %34, i32* %6
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %14
%37 = load i32, i32* @errno
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %37)
store i32 -1, i32* %1
br label %47
39: ; preds = %14
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %40, i32 %42, i32 %43)
%45 = load i32, i32* %3
%46 = call i32 @close(i32 %45)
store i32 0, i32* %1
br label %47
47: ; preds = %39, %36, %12
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.msg = [128 x i8] c"I am broadCast message from server!\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@.str.1 = [16 x i8] c"255.255.255.255\00"
@.str.2 = [23 x i8] c"sendto fail, errno=%d\0A\00"
@errno = global i32 0
@.str.3 = [33 x i8] c"msg=%s, msgLen=%d, sendBytes=%d\0A\00"
@str = [12 x i8] c"socket fail\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %39
11: ; preds = %0
%12 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%13 = load i32, i32* @SOL_SOCKET
%14 = load i32, i32* @SO_BROADCAST
%15 = load i32, i32* @SO_REUSEADDR
%16 = or i32 %15, %14
%17 = call i32 @setsockopt(i32 %7, i32 %13, i32 %16, i32* %2, i32 4)
%18 = bitcast %struct.sockaddr_in* %3 to i8*
%19 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %22, i32* %23
%24 = call i32 @htons(i32 4001)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %24, i32* %25
%26 = call i32 @strlen(i8* %4)
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @sendto(i32 %7, i8* %4, i32 %26, i32 0, %struct.sockaddr* %27, i32 4)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %11
%31 = load i32, i32* @errno
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %37
33: ; preds = %11
%34 = call i32 @strlen(i8* %4)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %34, i32 %28)
%36 = call i32 @close(i32 %7)
br label %37
37: ; preds = %33, %30
%38 = phi i32 [ -1, %30 ], [ 0, %33 ]
br label %39
39: ; preds = %37, %9
%40 = phi i32 [ -1, %9 ], [ %38, %37 ]
ret i32 %40
}