#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;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ reuse;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int socketfd = 0;
  int reuse = 0;
  int recv = 0;
  char buf[256] = {0};
  char msg[256] = {0};
  struct sockaddr_in server, client;
  int sock_len = sizeof(struct sockaddr);
  bzero(&server, sizeof(server));
  server.sin_family = PF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(1994);
  socketfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (socketfd < 0) {
    perror("create socket error ... ");
    return -1;
  }
  setsockopt(socketfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
  if (bind(socketfd, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("bind error ...");
    return -1;
  }
  printf("udp server start [%d][0.0.0.0][%d] -------> \n", socketfd, 1994);
  while ((recvfrom(socketfd, msg, sizeof(256 - 1), 0,
                   (struct sockaddr *)&client, &sock_len)) > 0) {
    printf("read [%s:%d] mag-->%s\n", inet_ntoa(client.sin_addr),
           ntohs(client.sin_port), msg);
    int send = sendto(socketfd, msg, strlen(msg), 0, (struct sockaddr *)&client,
                      sock_len);
    if (send > 0) {
      printf("send success ......\n");
    } else {
      perror("send error ...\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
movl   $0x4,-0x244(%rbp)
lea    -0x230(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x228(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x22c(%rbp)
mov    $0x7ca,%edi
call   1060 <htons@plt>
mov    %eax,-0x230(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12ab <main+0xdb>
lea    0xd66(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    140e <main+0x23e>
mov    -0x14(%rbp),%edi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
mov    0x2cfa(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    1305 <main+0x135>
lea    0xd25(%rip),%rdi
call   10d0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    140e <main+0x23e>
mov    -0x14(%rbp),%esi
lea    0xd19(%rip),%rdi
mov    $0x7ca,%edx
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
lea    -0x240(%rbp),%r8
mov    $0x4,%edx
xor    %ecx,%ecx
lea    -0x244(%rbp),%r9
call   10a0 <recvfrom@plt>
cmp    $0x0,%rax
jle    1407 <main+0x237>
mov    -0x23c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x260(%rbp)
mov    -0x240(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0x260(%rbp),%rsi
mov    %eax,%edx
lea    -0x220(%rbp),%rcx
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x254(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x250(%rbp)
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x254(%rbp),%edi
mov    -0x250(%rbp),%rsi
mov    %eax,%edx
lea    -0x240(%rbp),%r8
mov    -0x244(%rbp),%r9d
xor    %ecx,%ecx
call   1090 <sendto@plt>
mov    %eax,-0x248(%rbp)
cmpl   $0x0,-0x248(%rbp)
jle    13f1 <main+0x221>
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1402 <main+0x232>
lea    0xc8a(%rip),%rdi
call   10d0 <perror@plt>
jmp    1407 <main+0x237>
jmp    131b <main+0x14b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
movl   $0x0,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movl   $0x4,0x8(%rsp)
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x7ca,%edi
call   1070 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     13ec <main+0x21c>
mov    %eax,%r12d
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
mov    0x2ce8(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
js     13f5 <main+0x225>
lea    0xd21(%rip),%rdi
xor    %r14d,%r14d
mov    %r12d,%esi
mov    $0x7ca,%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x30(%rsp),%rsi
lea    0x20(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %r12d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
test   %rax,%rax
jle    13d7 <main+0x207>
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r15
lea    0x8(%rsp),%r13
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x24(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x20(%rsp),%edi
call   10b0 <ntohs@plt>
lea    0xcda(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    0x8(%rsp),%r9d
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1090 <sendto@plt>
test   %eax,%eax
jle    1409 <main+0x239>
lea    0xcc8(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r13,%r9
call   10a0 <recvfrom@plt>
test   %rax,%rax
jg     1360 <main+0x190>
mov    %r14d,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc0d(%rip),%rdi
jmp    13fc <main+0x22c>
lea    0xc1d(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%r14d
jmp    13d7 <main+0x207>
lea    0xc5d(%rip),%rdi
call   10d0 <perror@plt>
xor    %r14d,%r14d
jmp    13d7 <main+0x207>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [25 x i8] c"create socket error ... \00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [15 x i8] c"bind error ...\00"
@.str.2 = [46 x i8] c"udp server start [%d][0.0.0.0][%d] -------> \0A\00"
@.str.3 = [23 x i8] c"read [%s:%d] mag-->%s\0A\00"
@.str.4 = [21 x i8] c"send success ......\0A\00"
@.str.5 = [16 x i8] c"send error ...\0A\00"
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 [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%15 = bitcast [256 x i8]* %9 to i8*
%16 = bitcast [256 x i8]* %10 to i8*
store i32 4, i32* %13
%17 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%18 = load i32, i32* @PF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = call i32 @htons(i32 1994)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_DGRAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %2
%31 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %77
32: ; preds = %2
%33 = load i32, i32* %6
%34 = load i32, i32* @SOL_SOCKET
%35 = load i32, i32* @SO_REUSEADDR
%36 = call i32 @setsockopt(i32 %33, i32 %34, i32 %35, i32* %7, i32 4)
%37 = load i32, i32* %6
%38 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%39 = call i64 @bind(i32 %37, %struct.sockaddr* %38, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %77
43: ; preds = %32
%44 = load i32, i32* %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 1994)
br label %46
46: ; preds = %75, %43
%47 = load i32, i32* %6
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%49 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%50 = call i64 @recvfrom(i32 %47, i8* %48, i32 4, i32 0, %struct.sockaddr* %49, i32* %13)
%51 = icmp sgt i64 %50, 0
br i1 %51, label %52, label %76
52: ; preds = %46
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i8* @inet_ntoa(i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @ntohs(i32 %58)
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %56, i32 %59, i8* %60)
%62 = load i32, i32* %6
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%65 = call i32 @strlen(i8* %64)
%66 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%67 = load i32, i32* %13
%68 = call i32 @sendto(i32 %62, i8* %63, i32 %65, i32 0, %struct.sockaddr* %66, i32 %67)
store i32 %68, i32* %14
%69 = load i32, i32* %14
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %52
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %75
73: ; preds = %52
%74 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %76
75: ; preds = %71
br label %46
76: ; preds = %73, %46
store i32 0, i32* %3
br label %77
77: ; preds = %76, %41, %30
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [25 x i8] c"create socket error ... \00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [15 x i8] c"bind error ...\00"
@.str.2 = [46 x i8] c"udp server start [%d][0.0.0.0][%d] -------> \0A\00"
@.str.3 = [23 x i8] c"read [%s:%d] mag-->%s\0A\00"
@.str.5 = [16 x i8] c"send error ...\0A\00"
@str = [20 x i8] c"send success ......\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = bitcast %struct.sockaddr_in* %6 to i8*
%12 = bitcast i32* %7 to i8*
store i32 4, i32* %7
%13 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%14 = load i32, i32* @PF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 1994)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = tail call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %59
26: ; preds = %2
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_REUSEADDR
%29 = call i32 @setsockopt(i32 %22, i32 %27, i32 %28, i32* %3, i32 4)
%30 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%31 = call i64 @bind(i32 %22, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %59
35: ; preds = %26
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 1994)
%37 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%38 = call i64 @recvfrom(i32 %22, i8* %9, i32 4, i32 0, %struct.sockaddr* %37, i32* %7)
%39 = icmp sgt i64 %38, 0
br i1 %39, label %40, label %59
40: ; preds = %35
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
br label %43
43: ; preds = %40, %55
%44 = load i32, i32* %41
%45 = call i8* @inet_ntoa(i32 %44)
%46 = load i32, i32* %42
%47 = call i32 @ntohs(i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %45, i32 %47, i8* %9)
%49 = call i32 @strlen(i8* %9)
%50 = load i32, i32* %7
%51 = call i32 @sendto(i32 %22, i8* %9, i32 %49, i32 0, %struct.sockaddr* %37, i32 %50)
%52 = icmp sgt i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %43
%54 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %59
55: ; preds = %43
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%57 = call i64 @recvfrom(i32 %22, i8* %9, i32 4, i32 0, %struct.sockaddr* %37, i32* %7)
%58 = icmp sgt i64 %57, 0
br i1 %58, label %43, label %59
59: ; preds = %55, %35, %53, %33, %24
%60 = phi i32 [ -1, %24 ], [ -1, %33 ], [ 0, %53 ], [ 0, %35 ], [ 0, %55 ]
ret i32 %60
}