#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*/ recebuf;
typedef int /*<<< orphan*/ clientAddr;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_port = htons(1234);
  int sock;
  int ret;
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
  }
  if ((ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr))) < 0) {
    perror("bind");
  }
  struct sockaddr_in clientAddr;
  int len = sizeof(clientAddr);
  char recebuf[30] = {'\0'};
  int length = sizeof(recebuf) / sizeof(char);
  int n;
  while (1) {
    if ((n = recvfrom(sock, recebuf, 30, 0, (struct sockaddr *)&clientAddr,
                      &len)) > 0) {
      printf("receive package %d %s\n", length, recebuf);
      memset(recebuf, 0, length);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x4d2,%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11f1 <main+0x71>
lea    0xe14(%rip),%rdi
call   1090 <perror@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    121a <main+0x9a>
lea    0xdf2(%rip),%rdi
call   1090 <perror@plt>
movl   $0xc,-0x3c(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1060 <memset@plt>
movl   $0x1e,-0x64(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x60(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x1e,%edx
xor    %ecx,%ecx
lea    -0x3c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x68(%rbp)
cmp    $0x0,%eax
jle    1280 <main+0x100>
mov    -0x64(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    0xd9f(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
jmp    1238 <main+0xb8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    0x2e55(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x4d2,%edi
call   1030 <htons@plt>
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     125c <main+0xdc>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %eax,%eax
js     126d <main+0xed>
movl   $0xc,0xc(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x2e(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rbx
lea    0x40(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xdf3(%rip),%r12
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1e,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1070 <recvfrom@plt>
test   %eax,%eax
jle    1220 <main+0xa0>
mov    %r12,%rdi
mov    $0x1e,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1060 <memset@plt>
jmp    1220 <main+0xa0>
lea    0xd9d(%rip),%rdi
call   1090 <perror@plt>
jmp    11d5 <main+0x55>
lea    0xd93(%rip),%rdi
call   1090 <perror@plt>
jmp    11ee <main+0x6e>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [23 x i8] c"receive package %d %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca [30 x i8]
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = call i32 @htonl(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = call i32 @htons(i32 1234)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_DGRAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %2
%29 = load i32, i32* %7
%30 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%31 = call i32 @bind(i32 %29, %struct.sockaddr* %30, i32 12)
store i32 %31, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
store i32 12, i32* %10
%36 = bitcast [30 x i8]* %11 to i8*
store i32 30, i32* %12
br label %37
37: ; preds = %35, %50
%38 = load i32, i32* %7
%39 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%40 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%41 = call i32 @recvfrom(i32 %38, i8* %39, i32 30, i32 0, %struct.sockaddr* %40, i32* %10)
store i32 %41, i32* %13
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %37
%44 = load i32, i32* %12
%45 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %44, i8* %45)
%47 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%48 = load i32, i32* %12
%49 = call i32 @memset(i8* %47, i32 0, i32 %48)
br label %50
50: ; preds = %43, %37
br label %37
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [23 x i8] c"receive package %d %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [30 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_ANY
%11 = tail call i32 @htonl(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 1234)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @bind(i32 %17, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = bitcast %struct.sockaddr_in* %4 to i8*
%29 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %32
32: ; preds = %38, %27
%33 = call i32 @recvfrom(i32 %17, i8* %30, i32 30, i32 0, %struct.sockaddr* %31, i32* %5)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 30, i8* %30)
%37 = call i32 @memset(i8* %30, i32 0, i32 30)
br label %38
38: ; preds = %35, %32
br label %32
}