#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addr;
typedef int /*<<< orphan*/ ad_snd;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (fd == -1) {
    printf("socket : %m\n");
    exit(-1);
  }
  printf("create socket success.....\n");
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_port = htons(8686);
  inet_aton("192.168.137.3", &addr.sin_addr);
  int r = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
  if (r == -1) {
    printf("bind socket : %m");
    exit(-1);
  }
  printf("bind socket success.....\n");
  char buf[1024];
  struct sockaddr_in ad_snd;
  int len;
  while (1) {
    len = sizeof(ad_snd);
    r = recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&ad_snd, &len);
    if (r == -1) {
      printf("socket net faild.....\n");
      break;
    }
    if (r == 0) {
      printf("sender closed....\n");
      break;
    }
    if (r > 0) {
      buf[r] = '\0';
      printf("%s::%s\n", inet_ntoa(ad_snd.sin_addr), buf);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e0 <main+0x50>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x21ee,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rsi
lea    0xe17(%rip),%rdi
call   1070 <inet_aton@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    124d <main+0xbd>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xc,-0x434(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
lea    -0x430(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x434(%rbp),%r9
call   1080 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12a9 <main+0x119>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1304 <main+0x174>
cmpl   $0x0,-0x1c(%rbp)
jne    12c6 <main+0x136>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1304 <main+0x174>
cmpl   $0x0,-0x1c(%rbp)
jle    12ff <main+0x16f>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x430(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    -0x420(%rbp),%rdx
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    125b <main+0xcb>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x430,%rsp
mov    0x2e32(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     12ca <main+0x12a>
mov    %eax,%ebp
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x21ee,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe13(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <inet_aton@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
je     12d3 <main+0x133>
lea    0xe29(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xdeb(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0xc,0xc(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1090 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     12a5 <main+0x105>
test   %eax,%eax
je     129c <main+0xfc>
jle    1250 <main+0xb0>
mov    %eax,%eax
movb   $0x0,0x30(%rsp,%rax,1)
mov    0x20(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1250 <main+0xb0>
lea    0xdc5(%rip),%rdi
jmp    12ac <main+0x10c>
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd2f(%rip),%rdi
jmp    12da <main+0x13a>
lea    0xd41(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socket : %m\0A\00"
@.str.1 = [28 x i8] c"create socket success.....\0A\00"
@.str.2 = [14 x i8] c"192.168.137.3\00"
@.str.3 = [17 x i8] c"bind socket : %m\00"
@.str.4 = [26 x i8] c"bind socket success.....\0A\00"
@.str.5 = [23 x i8] c"socket net faild.....\0A\00"
@.str.6 = [19 x i8] c"sender closed....\0A\00"
@.str.7 = [8 x i8] c"%s::%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 8686)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%23 = call i32 @inet_aton(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %22)
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @bind(i32 %24, %struct.sockaddr* %25, i32 12)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %16
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %16
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %60
store i32 12, i32* %7
%35 = load i32, i32* %2
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%37 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%38 = call i32 @recvfrom(i32 %35, i8* %36, i32 1024, i32 0, %struct.sockaddr* %37, i32* %7)
store i32 %38, i32* %4
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %61
43: ; preds = %34
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %61
48: ; preds = %43
%49 = load i32, i32* %4
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %60
51: ; preds = %48
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %53
store i8 0, i8* %54
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i8* @inet_ntoa(i32 %56)
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %57, i8* %58)
br label %60
60: ; preds = %51, %48
br label %34
61: ; preds = %46, %41
%62 = load i32, i32* %2
%63 = call i32 @close(i32 %62)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socket : %m\0A\00"
@.str.2 = [14 x i8] c"192.168.137.3\00"
@.str.3 = [17 x i8] c"bind socket : %m\00"
@.str.7 = [8 x i8] c"%s::%s\0A\00"
@str = [27 x i8] c"create socket success.....\00"
@str.8 = [25 x i8] c"bind socket success.....\00"
@str.9 = [18 x i8] c"sender closed....\00"
@str.10 = [22 x i8] c"socket net faild.....\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1024 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = load i32, i32* @AF_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 %12
9: ; preds = %0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%14 = bitcast %struct.sockaddr_in* %1 to i8*
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 8686)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%20 = call i32 @inet_aton(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %19)
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i32 @bind(i32 %7, %struct.sockaddr* %21, i32 12)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %12
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%30 = bitcast %struct.sockaddr_in* %3 to i8*
%31 = bitcast i32* %4 to i8*
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
br label %34
34: ; preds = %44, %27
store i32 12, i32* %4
%35 = call i32 @recvfrom(i32 %7, i8* %29, i32 1024, i32 0, %struct.sockaddr* %32, i32* %4)
switch i32 %35, label %36 [
i32 -1, label %46
i32 0, label %45
]
36: ; preds = %34
%37 = icmp sgt i32 %35, 0
br i1 %37, label %38, label %44
38: ; preds = %36
%39 = zext i32 %35 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %39
store i8 0, i8* %40
%41 = load i32, i32* %33
%42 = call i8* @inet_ntoa(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %42, i8* %29)
br label %44
44: ; preds = %38, %36
br label %34
45: ; preds = %34
br label %46
46: ; preds = %34, %45
%47 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.9, i64 0, i64 0), %45 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0), %34 ]
%48 = call i32 @puts(i8* dereferenceable(1) %47)
%49 = call i32 @close(i32 %7)
ret i32 0
}