#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_family;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ s_oth;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
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 recl = 10;
  char buff[recl];
  char address[] = "192.168.12.211";
  struct sockaddr_in addr, s_oth;
  int l = sizeof(s_oth);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(5000);
  addr.sin_addr.s_addr = inet_addr(address);
  int s = socket(addr.sin_family, SOCK_DGRAM, IPPROTO_UDP);
  printf(" socket s = %d \n", s);
  int v = bind(s, (struct sockaddr *)&addr, sizeof(addr));
  if (v < 0) {
    printf("error bind \n");
    close(s);
    return 0;
  }
  while (1) {
    if (recvfrom(s, buff, recl, 0, (struct sockaddr *)&s_oth, &l) == -1) {
      printf("error recv \n");
      close(s);
      return 0;
    }
    printf("buf =%s \n", buff);
  }
  close(s);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    0xe4d(%rip),%rax
mov    %rax,-0x27(%rbp)
mov    0xe4b(%rip),%eax
mov    %eax,-0x1f(%rbp)
mov    0xe45(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xe3d(%rip),%al
mov    %al,-0x19(%rbp)
movl   $0xc,-0x4c(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x1388,%edi
call   1030 <htons@plt>
mov    %eax,-0x30(%rbp)
lea    -0x27(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1275 <main+0x105>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    12e1 <main+0x171>
jmp    127a <main+0x10a>
jmp    127f <main+0x10f>
mov    -0x60(%rbp),%rsi
mov    -0x50(%rbp),%edi
mov    -0x8(%rbp),%edx
lea    -0x48(%rbp),%r8
xor    %ecx,%ecx
lea    -0x4c(%rbp),%r9
call   1070 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    12ca <main+0x15a>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x58(%rbp)
jmp    12e1 <main+0x171>
mov    -0x60(%rbp),%rsi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127a <main+0x10a>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
movabs $0x3131322e32312e,%rax
mov    %rax,0x3f(%rsp)
movabs $0x2e3836312e323931,%rax
36 38 2e
mov    %rax,0x38(%rsp)
movl   $0xc,0xc(%rsp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,0x10(%rsp)
mov    $0x1388,%edi
call   1040 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0x38(%rsp),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   10a0 <socket@plt>
mov    %eax,%ebp
lea    0xe10(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %eax,%eax
js     128b <main+0x10b>
lea    0x20(%rsp),%rsi
lea    0x48(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0xa,%edx
xor    %ecx,%ecx
call   1080 <recvfrom@plt>
lea    0xde9(%rip),%r14
cmp    $0xffffffff,%eax
je     1292 <main+0x112>
lea    0xdd3(%rip),%r15
lea    0x20(%rsp),%rbx
lea    0x48(%rsp),%r12
lea    0xc(%rsp),%r13
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r13,%r9
call   1080 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    1260 <main+0xe0>
jmp    1292 <main+0x112>
lea    0xda4(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.address = [15 x i8] c"192.168.12.211\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [17 x i8] c" socket s = %d \0A\00"
@.str.1 = [13 x i8] c"error bind \0A\00"
@.str.2 = [13 x i8] c"error recv \0A\00"
@.str.3 = [10 x i8] c"buf =%s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [15 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %2
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i8, i64 %13
store i64 %13, i64* %4
%16 = bitcast [15 x i8]* %5 to i8*
store i32 12, i32* %8
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %17, i32* %18
%19 = call i32 @htons(i32 5000)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%22 = call i32 @inet_addr(i8* %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @SOCK_DGRAM
%28 = load i32, i32* @IPPROTO_UDP
%29 = call i32 @socket(i32 %26, i32 %27, i32 %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %9
%33 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%34 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 12)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%39 = load i32, i32* %9
%40 = call i32 @close(i32 %39)
store i32 0, i32* %1
store i32 1, i32* %11
br label %55
41: ; preds = %0
br label %42
42: ; preds = %53, %41
br label %43
43: ; preds = %42
%44 = load i32, i32* %9
%45 = load i32, i32* %2
%46 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%47 = call i32 @recvfrom(i32 %44, i8* %15, i32 %45, i32 0, %struct.sockaddr* %46, i32* %8)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %43
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%51 = load i32, i32* %9
%52 = call i32 @close(i32 %51)
store i32 0, i32* %1
store i32 1, i32* %11
br label %55
53: ; preds = %43
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %42
55: ; preds = %49, %37
%56 = load i8*, i8** %3
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.address = [15 x i8] c"192.168.12.211\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [17 x i8] c" socket s = %d \0A\00"
@.str.3 = [10 x i8] c"buf =%s \0A\00"
@str = [12 x i8] c"error recv \00"
@str.4 = [12 x i8] c"error bind \00"
define i32 @main() {
%1 = alloca [15 x i8]
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [10 x i8]
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 5000)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* %7)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_DGRAM
%18 = load i32, i32* @IPPROTO_UDP
%19 = call i32 @socket(i32 %11, i32 %17, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%22 = call i32 @bind(i32 %19, %struct.sockaddr* %21, i32 12)
%23 = icmp slt i32 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %0
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @recvfrom(i32 %19, i8* %6, i32 10, i32 0, %struct.sockaddr* %25, i32* %4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %32, label %28
28: ; preds = %24, %28
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%30 = call i32 @recvfrom(i32 %19, i8* %6, i32 10, i32 0, %struct.sockaddr* %25, i32* %4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %28
32: ; preds = %28, %24, %0
%33 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0), %0 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), %24 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0), %28 ]
%34 = call i32 @puts(i8* dereferenceable(1) %33)
%35 = call i32 @close(i32 %19)
ret i32 0
}