#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  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 /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int port = 1995;
  int s = 0;
  int reuse = 0;
  int recv = 0;
  char buf[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(port);
  s = socket(AF_INET, SOCK_DGRAM, 0);
  if (s < 0) {
    perror("create socket error ... ");
    return -1;
  }
  setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
  if (bind(s, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("bind error ...");
    return -1;
  }
  printf("server recvfrom........................................\n");
  while (1) {
    memset(buf, 0, 256);
    recv = recvfrom(s, buf, 256, 0, (struct sockaddr *)&client, &sock_len);
    if (recv < 0) {
      perror("recvfrom error ... \n");
      break;
    } else {
      printf("receive msg from %s(port=%d) len %d: %s\n",
             inet_ntoa(client.sin_addr), port, recv, buf);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x7cb,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movl   $0x4,-0x144(%rbp)
lea    -0x130(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x128(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x130(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x12c(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    126d <main+0xcd>
lea    0xda4(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135f <main+0x1bf>
mov    -0x18(%rbp),%edi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
mov    0x2d38(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x18(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    12c7 <main+0x127>
lea    0xd63(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    135f <main+0x1bf>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x120(%rbp),%rsi
lea    -0x140(%rbp),%r8
mov    $0x100,%edx
xor    %ecx,%ecx
lea    -0x144(%rbp),%r9
call   1080 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    132a <main+0x18a>
lea    0xd41(%rip),%rdi
call   10a0 <perror@plt>
jmp    1358 <main+0x1b8>
mov    -0x140(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    -0x120(%rbp),%r8
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12d5 <main+0x135>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%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   10c0 <bzero@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x7cb,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    12a2 <main+0xf2>
lea    0xd60(%rip),%rdi
jmp    12e5 <main+0x135>
mov    %eax,%ebx
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
mov    0x2d04(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jns    12f4 <main+0x144>
lea    0xd34(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
jmp    13ac <main+0x1fc>
lea    0xd6b(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    0x20(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1090 <recvfrom@plt>
test   %eax,%eax
js     139e <main+0x1ee>
mov    %eax,%r14d
lea    0xd00(%rip),%r15
lea    0x30(%rsp),%rbp
lea    0x20(%rsp),%r12
lea    0x8(%rsp),%r13
nopl   0x0(%rax)
mov    0x20(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r15,%rdi
mov    %rax,%rsi
mov    $0x7cb,%edx
mov    %r14d,%ecx
mov    %rbp,%r8
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r13,%r9
call   1090 <recvfrom@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1350 <main+0x1a0>
lea    0xc83(%rip),%rdi
call   10b0 <perror@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, 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.3 = [21 x i8] c"recvfrom error ... \0A\00"
@.str.4 = [41 x i8] c"receive msg from %s(port=%d) len %d: %s\0A\00"
@str = [56 x i8] c"server recvfrom........................................\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 0, i32 0
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 1995)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
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 %53
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 %53
35: ; preds = %26
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%37 = call i32 @memset(i8* %9, i32 0, i32 256)
%38 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%39 = call i32 @recvfrom(i32 %22, i8* %9, i32 256, i32 0, %struct.sockaddr* %38, i32* %7)
%40 = icmp slt i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %35
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
br label %45
43: ; preds = %45, %35
%44 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %53
45: ; preds = %41, %45
%46 = phi i32 [ %39, %41 ], [ %51, %45 ]
%47 = load i32, i32* %42
%48 = call i8* @inet_ntoa(i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %48, i32 1995, i32 %46, i8* %9)
%50 = call i32 @memset(i8* %9, i32 0, i32 256)
%51 = call i32 @recvfrom(i32 %22, i8* %9, i32 256, i32 0, %struct.sockaddr* %38, i32* %7)
%52 = icmp slt i32 %51, 0
br i1 %52, label %43, label %45
53: ; preds = %43, %33, %24
%54 = phi i32 [ -1, %24 ], [ -1, %33 ], [ 0, %43 ]
ret i32 %54
}