#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*/ servaddr;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ puts(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int i;
  int sockfd;
  int clilen, n;
  char line[12];
  struct sockaddr_in servaddr, cliaddr;
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(5001);
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
    puts("Socket fail");
    exit(1);
  }
  if (bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    puts("Binding fail");
    close(sockfd);
    exit(1);
  }
  for (;;) {
    clilen = sizeof(cliaddr);
    if ((n = recvfrom(sockfd, line, 11, 0, (struct sockaddr *)&cliaddr,
                      &clilen)) < 0) {
      puts("Error receiving");
      close(sockfd);
      exit(1);
    }
    puts(line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x1389,%edi
call   1040 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x38(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1219 <main+0x89>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    1252 <main+0xc2>
lea    0xdd1(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1257 <main+0xc7>
movl   $0xc,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x2c(%rbp),%rsi
lea    -0x48(%rbp),%r8
mov    $0xb,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    12a3 <main+0x113>
lea    0xd8d(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x2c(%rbp),%rdi
call   1030 <puts@plt>
jmp    1257 <main+0xc7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x1389,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
jns    1209 <main+0x79>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
jns    122b <main+0x9b>
lea    0xde3(%rip),%rdi
jmp    12a3 <main+0x113>
movl   $0xc,0xc(%rsp)
lea    0x2c(%rsp),%rsi
lea    0x20(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r14d,%edi
mov    $0xb,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
test   %eax,%eax
js     129c <main+0x10c>
lea    0x2c(%rsp),%rbx
lea    0x20(%rsp),%r15
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <puts@plt>
movl   $0xc,0xc(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xb,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %rbp,%r9
call   1070 <recvfrom@plt>
test   %eax,%eax
jns    1270 <main+0xe0>
lea    0xd76(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"Socket fail\00"
@.str.1 = [13 x i8] c"Binding fail\00"
@.str.2 = [16 x i8] c"Error receiving\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 [12 x i8]
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 5001)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load i32, i32* @PF_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 %29
26: ; preds = %2
%27 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
%30 = load i32, i32* %7
%31 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%32 = call i64 @bind(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %29
br label %40
40: ; preds = %51, %39
store i32 12, i32* %8
%41 = load i32, i32* %7
%42 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%43 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%44 = call i32 @recvfrom(i32 %41, i8* %42, i32 11, i32 0, %struct.sockaddr* %43, i32* %8)
store i32 %44, i32* %9
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* %7
%49 = call i32 @close(i32 %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %40
%52 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%53 = call i32 @puts(i8* %52)
br label %40
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [12 x i8] c"Socket fail\00"
@.str.1 = [13 x i8] c"Binding fail\00"
@.str.2 = [16 x i8] c"Error receiving\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [12 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 5001)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = tail call i32 @htonl(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_DGRAM
%21 = tail call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%28 = call i64 @bind(i32 %21, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
store i32 12, i32* %3
%32 = call i32 @recvfrom(i32 %21, i8* %8, i32 11, i32 0, %struct.sockaddr* %31, i32* %3)
%33 = icmp slt i32 %32, 0
br i1 %33, label %38, label %42
34: ; preds = %26
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @close(i32 %21)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %42, %30
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @close(i32 %21)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %30, %42
%43 = call i32 @puts(i8* %8)
store i32 12, i32* %3
%44 = call i32 @recvfrom(i32 %21, i8* %8, i32 11, i32 0, %struct.sockaddr* %31, i32* %3)
%45 = icmp slt i32 %44, 0
br i1 %45, label %38, label %42
}