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

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ _IONBF;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
void *htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main() {
  setvbuf(stdout, NULL, _IONBF, 0);
  fflush(stdout);
  struct sockaddr_in addrto;
  bzero(&addrto, sizeof(struct sockaddr_in));
  addrto.sin_family = AF_INET;
  addrto.sin_addr.s_addr = htonl(INADDR_ANY);
  addrto.sin_port = htons(6000);
  struct sockaddr_in from;
  bzero(&from, sizeof(struct sockaddr_in));
  from.sin_family = AF_INET;
  from.sin_addr.s_addr = htonl(INADDR_ANY);
  from.sin_port = htons(6000);
  int sock = -1;
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    printf("socket error\n");
    return -1;
  }
  const int opt = 1;
  int nb = 0;
  nb = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&opt, sizeof(opt));
  if (nb == -1) {
    printf("set socket error....\n");
    return -1;
  }
  if (bind(sock, (struct sockaddr *)&(addrto), sizeof(struct sockaddr_in)) ==
      -1) {
    printf("bind error\n");
    return -1;
  }
  int len = sizeof(struct sockaddr_in);
  char smsg[100] = {0};
  while (1) {
    int ret = recvfrom(sock, smsg, 100, 0, (struct sockaddr *)&from,
                       (socklen_t *)&len);
    if (ret <= 0) {
      printf("read error....\n");
    } else {
      printf("%s\t", smsg);
      sendto(sock, smsg, 100, 0, (struct sockaddr *)&from, len);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   10b0 <setvbuf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    -0x20(%rbp),%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1770,%edi
call   1040 <htons@plt>
mov    %rax,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %rax,-0x30(%rbp)
mov    $0x1770,%edi
call   1040 <htons@plt>
mov    %rax,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
mov    0x2d5d(%rip),%rax
mov    (%rax),%rdi
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    12bc <main+0xfc>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13df <main+0x21f>
movl   $0x1,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x3c(%rbp),%edi
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
mov    0x2ce3(%rip),%rax
mov    (%rax),%edx
lea    -0x40(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1315 <main+0x155>
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13df <main+0x21f>
mov    -0x3c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1349 <main+0x189>
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13df <main+0x21f>
movl   $0x18,-0x48(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1070 <memset@plt>
mov    -0x3c(%rbp),%edi
lea    -0xb0(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x48(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jg     13a7 <main+0x1e7>
lea    0xc95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13da <main+0x21a>
lea    -0xb0(%rbp),%rsi
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%edi
lea    -0xb0(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    -0x48(%rbp),%r9d
mov    $0x64,%edx
xor    %ecx,%ecx
call   1080 <sendto@plt>
jmp    1363 <main+0x1a3>
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    0x2dd8(%rip),%rbx
mov    (%rbx),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10b0 <setvbuf@plt>
mov    (%rbx),%edi
call   1090 <fflush@plt>
lea    0x28(%rsp),%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    0x2dd7(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x38(%rsp)
mov    0x2dc0(%rip),%rbp
mov    0x0(%rbp),%edi
call   1070 <htonl@plt>
mov    %rax,0x30(%rsp)
mov    $0x1770,%edi
call   1050 <htons@plt>
mov    %rax,0x28(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x18,%esi
call   10d0 <bzero@plt>
mov    (%rbx),%rax
mov    %rax,0x20(%rsp)
mov    0x0(%rbp),%edi
call   1070 <htonl@plt>
mov    %rax,0x18(%rsp)
mov    $0x1770,%edi
call   1050 <htons@plt>
mov    %rax,0x10(%rsp)
mov    (%rbx),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     137b <main+0x1bb>
mov    %eax,%ebp
movl   $0x1,0xc(%rsp)
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1384 <main+0x1c4>
lea    0x28(%rsp),%rsi
mov    %ebp,%edi
mov    $0x18,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     138d <main+0x1cd>
movl   $0x18,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movl   $0x0,0xa0(%rsp)
lea    0x40(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0xce0(%rip),%r12
lea    0xcd5(%rip),%r13
jmp    1356 <main+0x196>
nopl   (%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1080 <sendto@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   10a0 <recvfrom@plt>
test   %eax,%eax
jg     1330 <main+0x170>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1356 <main+0x196>
lea    0xcb1(%rip),%rdi
jmp    1394 <main+0x1d4>
lea    0xc93(%rip),%rdi
jmp    1394 <main+0x1d4>
lea    0xc7f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@stdout = global i32 0
@_IONBF = global i32 0
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [14 x i8] c"socket error\0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [22 x i8] c"set socket error....\0A\00"
@.str.2 = [12 x i8] c"bind error\0A\00"
@.str.3 = [16 x i8] c"read error....\0A\00"
@.str.4 = [4 x i8] c"%s\09\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @stdout
%11 = load i32, i32* @_IONBF
%12 = call i32 @setvbuf(i32 %10, i32* null, i32 %11, i32 0)
%13 = load i32, i32* @stdout
%14 = call i32 @fflush(i32 %13)
%15 = call i32 @bzero(%struct.sockaddr_in* %2, i32 24)
%16 = load i8*, i8** @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i8* %16, i8** %17
%18 = load i32, i32* @INADDR_ANY
%19 = call i8* @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i8* %19, i8** %21
%22 = call i8* @htons(i32 6000)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i8* %22, i8** %23
%24 = call i32 @bzero(%struct.sockaddr_in* %3, i32 24)
%25 = load i8*, i8** @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i8* %25, i8** %26
%27 = load i32, i32* @INADDR_ANY
%28 = call i8* @htonl(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i8* %28, i8** %30
%31 = call i8* @htons(i32 6000)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i8* %31, i8** %32
store i32 -1, i32* %4
%33 = load i8*, i8** @AF_INET
%34 = load i32, i32* @SOCK_DGRAM
%35 = call i32 @socket(i8* %33, i32 %34, i32 0)
store i32 %35, i32* %4
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %76
39: ; preds = %0
store i32 1, i32* %5
store i32 0, i32* %6
%40 = load i32, i32* %4
%41 = load i32, i32* @SOL_SOCKET
%42 = load i32, i32* @SO_BROADCAST
%43 = bitcast i32* %5 to i8*
%44 = call i32 @setsockopt(i32 %40, i32 %41, i32 %42, i8* %43, i32 4)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %76
49: ; preds = %39
%50 = load i32, i32* %4
%51 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%52 = call i32 @bind(i32 %50, %struct.sockaddr* %51, i32 24)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %76
56: ; preds = %49
store i32 24, i32* %7
%57 = bitcast [100 x i8]* %8 to i8*
br label %58
58: ; preds = %56, %75
%59 = load i32, i32* %4
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%61 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%62 = call i32 @recvfrom(i32 %59, i8* %60, i32 100, i32 0, %struct.sockaddr* %61, i32* %7)
store i32 %62, i32* %9
%63 = load i32, i32* %9
%64 = icmp sle i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %58
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %75
67: ; preds = %58
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %68)
%70 = load i32, i32* %4
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%72 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%73 = load i32, i32* %7
%74 = call i32 @sendto(i32 %70, i8* %71, i32 100, i32 0, %struct.sockaddr* %72, i32 %73)
br label %75
75: ; preds = %67, %65
br label %58
76: ; preds = %54, %47, %37
%77 = load i32, i32* %1
ret i32 %77
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@stdout = global i32 0
@_IONBF = global i32 0
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.4 = [4 x i8] c"%s\09\00"
@str = [15 x i8] c"read error....\00"
@str.5 = [11 x i8] c"bind error\00"
@str.6 = [21 x i8] c"set socket error....\00"
@str.7 = [13 x i8] c"socket error\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = load i32, i32* @stdout
%7 = load i32, i32* @_IONBF
%8 = tail call i32 @setvbuf(i32 %6, i32* null, i32 %7, i32 0)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
%11 = bitcast %struct.sockaddr_in* %1 to i8*
%12 = call i32 @bzero(%struct.sockaddr_in* %1, i32 24)
%13 = load i8*, i8** @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %13, i8** %14
%15 = load i32, i32* @INADDR_ANY
%16 = tail call i8* @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i8* %16, i8** %17
%18 = tail call i8* @htons(i32 6000)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i8* %18, i8** %19
%20 = bitcast %struct.sockaddr_in* %2 to i8*
%21 = call i32 @bzero(%struct.sockaddr_in* %2, i32 24)
%22 = load i8*, i8** @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i8* %22, i8** %23
%24 = load i32, i32* @INADDR_ANY
%25 = tail call i8* @htonl(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i8* %25, i8** %26
%27 = tail call i8* @htons(i32 6000)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i8* %27, i8** %28
%29 = load i8*, i8** @AF_INET
%30 = load i32, i32* @SOCK_DGRAM
%31 = tail call i32 @socket(i8* %29, i32 %30, i32 0)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %0
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %62
35: ; preds = %0
%36 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%37 = load i32, i32* @SOL_SOCKET
%38 = load i32, i32* @SO_BROADCAST
%39 = call i32 @setsockopt(i32 %31, i32 %37, i32 %38, i8* %36, i32 4)
%40 = icmp eq i32 %39, -1
br i1 %40, label %59, label %41
41: ; preds = %35
%42 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%43 = call i32 @bind(i32 %31, %struct.sockaddr* %42, i32 24)
%44 = icmp eq i32 %43, -1
br i1 %44, label %59, label %45
45: ; preds = %41
%46 = bitcast i32* %4 to i8*
store i32 24, i32* %4
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%48 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %49
49: ; preds = %58, %45
%50 = call i32 @recvfrom(i32 %31, i8* %47, i32 100, i32 0, %struct.sockaddr* %48, i32* %4)
%51 = icmp slt i32 %50, 1
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %58
54: ; preds = %49
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%56 = load i32, i32* %4
%57 = call i32 @sendto(i32 %31, i8* %47, i32 100, i32 0, %struct.sockaddr* %48, i32 %56)
br label %58
58: ; preds = %54, %52
br label %49
59: ; preds = %41, %35
%60 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0), %35 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0), %41 ]
%61 = call i32 @puts(i8* dereferenceable(1) %60)
br label %62
62: ; preds = %59, %33
ret i32 -1
}