#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;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ des_ip;
typedef int /*<<< orphan*/ des_data;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ abuf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, char *, char *, int);
int list_add(char *, int /*<<< orphan*/);
int /*<<< orphan*/ list_showall();
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void reg_listen(int sockfd) {
  int num;
  char buf[128];
  char abuf[256];
  socklen_t alen = sizeof(abuf);
  struct sockaddr_in *des;
  char des_ip[32] = {0};
  char des_data[16] = {0};
  int count = 0;
  int ret = 0;
  while (1) {
    num = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)abuf, &alen);
    if (num == 0) {
      sleep(3);
      continue;
    } else if (num < 0) {
      printf("error: recvfrom -1\n");
      continue;
    }
    des = (struct sockaddr_in *)abuf;
    memset(des_data, 0, sizeof(des_data));
    memcpy(des_data, &(des->sin_addr.s_addr), sizeof(des->sin_addr.s_addr));
    inet_ntop(AF_INET, des_data, des_ip, sizeof(des_ip));
    ret = list_add(des_ip, strlen(des_ip));
    if (ret == 1)
      printf("\n%s already have\n", des_ip);
    list_showall();
    strncpy(buf, "this is 10.0.215.215", sizeof(buf));
    for (count = 3; count > 0; --count) {
      num = sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)abuf, alen);
      if (num >= 0)
        break;
      else
        printf("error: sendto -1\n");
    }
  }
  return;
}


x86 assembly (clang, -O0):
<reg_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x100,-0x194(%rbp)
lea    -0x1c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
lea    -0x1d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
movl   $0x0,-0x1d4(%rbp)
movl   $0x0,-0x1d8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
lea    -0x190(%rbp),%r8
mov    $0x80,%edx
xor    %ecx,%ecx
lea    -0x194(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1242 <reg_listen+0x92>
mov    $0x3,%edi
call   10d0 <sleep@plt>
jmp    1202 <reg_listen+0x52>
cmpl   $0x0,-0x8(%rbp)
jge    125f <reg_listen+0xaf>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1202 <reg_listen+0x52>
jmp    1264 <reg_listen+0xb4>
lea    -0x190(%rbp),%rax
mov    %rax,-0x1a0(%rbp)
lea    -0x1d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
lea    -0x1d0(%rbp),%rdi
mov    -0x1a0(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <memcpy@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    -0x1d0(%rbp),%rsi
lea    -0x1c0(%rbp),%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
lea    -0x1c0(%rbp),%rax
mov    %rax,-0x1e0(%rbp)
lea    -0x1c0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1e0(%rbp),%rdi
mov    %eax,%esi
call   10c0 <list_add@plt>
mov    %eax,-0x1d8(%rbp)
cmpl   $0x1,-0x1d8(%rbp)
jne    130e <reg_listen+0x15e>
lea    -0x1c0(%rbp),%rsi
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1090 <list_showall@plt>
lea    -0x90(%rbp),%rdi
lea    0xd03(%rip),%rsi
mov    $0x80,%edx
call   1040 <strncpy@plt>
movl   $0x3,-0x1d4(%rbp)
cmpl   $0x0,-0x1d4(%rbp)
jle    13c4 <reg_listen+0x214>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1ec(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0x1e8(%rbp)
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1ec(%rbp),%edi
mov    -0x1e8(%rbp),%rsi
mov    %eax,%edx
lea    -0x190(%rbp),%r8
mov    -0x194(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     139d <reg_listen+0x1ed>
jmp    13c4 <reg_listen+0x214>
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13b0 <reg_listen+0x200>
mov    -0x1d4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1d4(%rbp)
jmp    1337 <reg_listen+0x187>
jmp    1202 <reg_listen+0x52>

x86 assembly (clang, -O2):
<reg_listen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1c8,%rsp
mov    %edi,%ebx
movl   $0x100,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x40(%rsp),%r14
lea    0xc0(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%rbp
lea    0x20(%rsp),%r13
jmp    121a <reg_listen+0x5a>
nopl   0x0(%rax,%rax,1)
mov    $0x3,%edi
call   10e0 <sleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   10c0 <recvfrom@plt>
test   %eax,%eax
je     1210 <reg_listen+0x50>
js     1360 <reg_listen+0x1a0>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    $0x20,%ecx
call   1030 <inet_ntop@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   10d0 <list_add@plt>
cmp    $0x1,%eax
jne    129b <reg_listen+0xdb>
lea    0xd6f(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10a0 <list_showall@plt>
mov    %r14,%rdi
lea    0xd66(%rip),%rsi
mov    $0x80,%edx
call   1040 <strncpy@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    0xc(%rsp),%r9d
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1090 <sendto@plt>
test   %eax,%eax
jns    121a <reg_listen+0x5a>
lea    0xd44(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    0xc(%rsp),%r9d
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1090 <sendto@plt>
test   %eax,%eax
jns    121a <reg_listen+0x5a>
lea    0xd12(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    0xc(%rsp),%r9d
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1090 <sendto@plt>
test   %eax,%eax
jns    121a <reg_listen+0x5a>
lea    0xce0(%rip),%rdi
call   1050 <puts@plt>
jmp    121a <reg_listen+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xcd1(%rip),%rdi
call   1050 <puts@plt>
jmp    121a <reg_listen+0x5a>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"error: recvfrom -1\0A\00"
@AF_INET = global i32 0
@.str.1 = [18 x i8] c"\0A%s already have\0A\00"
@.str.2 = [21 x i8] c"this is 10.0.215.215\00"
@.str.3 = [18 x i8] c"error: sendto -1\0A\00"
define void @reg_listen(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca %struct.sockaddr_in*
%8 = alloca [32 x i8]
%9 = alloca [16 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %2
store i32 256, i32* %6
%12 = bitcast [32 x i8]* %8 to i8*
%13 = bitcast [16 x i8]* %9 to i8*
store i32 0, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %1, %22, %27, %78
%15 = load i32, i32* %2
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = bitcast i8* %17 to %struct.sockaddr*
%19 = call i32 @recvfrom(i32 %15, i8* %16, i32 128, i32 0, %struct.sockaddr* %18, i32* %6)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @sleep(i32 3)
br label %14
24: ; preds = %14
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %14
29: ; preds = %24
br label %30
30: ; preds = %29
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%32 = bitcast i8* %31 to %struct.sockaddr_in*
store %struct.sockaddr_in* %32, %struct.sockaddr_in** %7
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 16)
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%36 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %36, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
%39 = call i32 @memcpy(i8* %35, i32* %38, i32 4)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%43 = call i32 @inet_ntop(i32 %40, i8* %41, i8* %42, i32 32)
%44 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @list_add(i8* %44, i32 %46)
store i32 %47, i32* %11
%48 = load i32, i32* %11
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %53
50: ; preds = %30
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %30
%54 = call i32 (...) @list_showall()
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%56 = call i32 @strncpy(i8* %55, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 128)
store i32 3, i32* %10
br label %57
57: ; preds = %75, %53
%58 = load i32, i32* %10
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %78
60: ; preds = %57
%61 = load i32, i32* %2
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%66 = bitcast i8* %65 to %struct.sockaddr*
%67 = load i32, i32* %6
%68 = call i32 @sendto(i32 %61, i8* %62, i32 %64, i32 0, %struct.sockaddr* %66, i32 %67)
store i32 %68, i32* %3
%69 = load i32, i32* %3
%70 = icmp sge i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %60
br label %78
72: ; preds = %60
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %74
74: ; preds = %72
br label %75
75: ; preds = %74
%76 = load i32, i32* %10
%77 = add nsw i32 %76, -1
store i32 %77, i32* %10
br label %57
78: ; preds = %71, %57
br label %14
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str.1 = [18 x i8] c"\0A%s already have\0A\00"
@.str.2 = [21 x i8] c"this is 10.0.215.215\00"
@str = [17 x i8] c"error: sendto -1\00"
@str.4 = [19 x i8] c"error: recvfrom -1\00"
define void @reg_listen(i32 %0) {
%2 = alloca [128 x i8]
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %4 to i8*
store i32 256, i32* %4
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%12 = bitcast [256 x i8]* %3 to %struct.sockaddr*
%13 = bitcast [256 x i8]* %3 to i32*
br label %14
14: ; preds = %40, %1
%15 = call i32 @recvfrom(i32 %0, i8* %7, i32 128, i32 0, %struct.sockaddr* %12, i32* %4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @sleep(i32 3)
br label %40
19: ; preds = %14
%20 = icmp slt i32 %15, 0
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0))
br label %40
23: ; preds = %19
%24 = call i32 @memset(i8* %11, i32 0, i32 16)
%25 = call i32 @memcpy(i8* %11, i32* %13, i32 4)
%26 = load i32, i32* @AF_INET
%27 = call i32 @inet_ntop(i32 %26, i8* %11, i8* %10, i32 32)
%28 = call i32 @strlen(i8* %10)
%29 = call i32 @list_add(i8* %10, i32 %28)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %33
33: ; preds = %31, %23
%34 = call i32 (...) @list_showall()
%35 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 128)
%36 = call i32 @strlen(i8* %7)
%37 = load i32, i32* %4
%38 = call i32 @sendto(i32 %0, i8* %7, i32 %36, i32 0, %struct.sockaddr* %12, i32 %37)
%39 = icmp sgt i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %33, %41, %47, %53, %17, %21
br label %14
41: ; preds = %33
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%43 = call i32 @strlen(i8* %7)
%44 = load i32, i32* %4
%45 = call i32 @sendto(i32 %0, i8* %7, i32 %43, i32 0, %struct.sockaddr* %12, i32 %44)
%46 = icmp sgt i32 %45, -1
br i1 %46, label %40, label %47
47: ; preds = %41
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%49 = call i32 @strlen(i8* %7)
%50 = load i32, i32* %4
%51 = call i32 @sendto(i32 %0, i8* %7, i32 %49, i32 0, %struct.sockaddr* %12, i32 %50)
%52 = icmp sgt i32 %51, -1
br i1 %52, label %40, label %53
53: ; preds = %47
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %40
}