#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 sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ myaddr;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ perror(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 socket_fd;
  socklen_t length;
  int nbytes;
  char buf[BUFSIZ];
  struct sockaddr_in myaddr;
  struct sockaddr_in client_addr;
  if ((socket_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket failed");
    exit(1);
  }
  bzero((char *)&myaddr, sizeof(myaddr));
  myaddr.sin_family = AF_INET;
  myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  myaddr.sin_port = htons(5134);
  if (bind(socket_fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
    perror("bind failed\n");
    exit(1);
  }
  length = sizeof(client_addr);
  printf("Server is ready to receive !!\n");
  printf("Can strike Cntrl-c to stop Server >>\n");
  while (1) {
    nbytes = recvfrom(socket_fd, &buf, 1024, 0, (struct sockaddr *)&client_addr,
                      &length);
    if (nbytes < 0) {
      perror("could not read datagram!!");
      continue;
    }
    printf("Received data form %s : %d\n", inet_ntoa(client_addr.sin_addr),
           htons(client_addr.sin_port));
    printf("%s\n", buf);
    printf("Can Strike Crtl-c to stop Server >>\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1216 <main+0x76>
lea    0xdf9(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x140e,%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    127f <main+0xdf>
lea    0xd9e(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0xc,-0xc(%rbp)
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a7 <main+0x107>
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0xc(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    12e0 <main+0x140>
lea    0xd8a(%rip),%rdi
call   1090 <perror@plt>
jmp    12a2 <main+0x102>
mov    -0x3c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%edi
call   1040 <htons@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12a2 <main+0x102>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e06(%rip),%r12
mov    (%r12),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12e4 <main+0x134>
mov    %eax,%r14d
lea    -0x38(%rbp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    $0x140e,%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
js     12ed <main+0x13d>
movl   $0xc,-0x2c(%rbp)
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe05(%rip),%rdi
call   1030 <puts@plt>
lea    -0x48(%rbp),%r15
lea    -0x2c(%rbp),%r12
jmp    12ba <main+0x10a>
nopl   0x0(%rax)
mov    -0x44(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%r13
mov    -0x48(%rbp),%edi
call   1050 <htons@plt>
lea    0xd9b(%rip),%rdi
mov    %r13,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xddf(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1080 <recvfrom@plt>
test   %eax,%eax
jns    1280 <main+0xd0>
lea    0xd3e(%rip),%rdi
call   10a0 <perror@plt>
jmp    12ba <main+0x10a>
lea    0xd15(%rip),%rdi
jmp    12f4 <main+0x144>
lea    0xd1a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [14 x i8] c"socket failed\00"
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"bind failed\0A\00"
@.str.2 = [31 x i8] c"Server is ready to receive !!\0A\00"
@.str.3 = [38 x i8] c"Can strike Cntrl-c to stop Server >>\0A\00"
@.str.4 = [26 x i8] c"could not read datagram!!\00"
@.str.5 = [28 x i8] c"Received data form %s : %d\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [37 x i8] c"Can Strike Crtl-c to stop Server >>\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = bitcast %struct.sockaddr_in* %7 to i8*
%22 = call i32 @bzero(i8* %21, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = call i32 @htons(i32 5134)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* %2
%32 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%33 = call i64 @bind(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %20
%36 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %20
store i32 12, i32* %3
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %51, %49, %38
br label %42
42: ; preds = %41
%43 = load i32, i32* %2
%44 = bitcast i8* %12 to i8**
%45 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%46 = call i32 @recvfrom(i32 %43, i8** %44, i32 1024, i32 0, %struct.sockaddr* %45, i32* %3)
store i32 %46, i32* %4
%47 = load i32, i32* %4
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %42
%50 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %41
51: ; preds = %42
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%53 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i8* @inet_ntoa(i32 %54)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @htons(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %55, i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
br label %41
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [14 x i8] c"socket failed\00"
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"bind failed\0A\00"
@.str.4 = [26 x i8] c"could not read datagram!!\00"
@.str.5 = [28 x i8] c"Received data form %s : %d\0A\00"
@str = [30 x i8] c"Server is ready to receive !!\00"
@str.8 = [37 x i8] c"Can strike Cntrl-c to stop Server >>\00"
@str.9 = [36 x i8] c"Can Strike Crtl-c to stop Server >>\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %1 to i8*
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = call i32 @bzero(i8* %8, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = tail call i32 @htonl(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 5134)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %24, i32* %25
%26 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%27 = call i64 @bind(i32 %12, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
store i32 12, i32* %1
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.8, i64 0, i64 0))
%35 = bitcast i8* %7 to i8**
%36 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
br label %39
39: ; preds = %44, %32
%40 = call i32 @recvfrom(i32 %12, i8** %35, i32 1024, i32 0, %struct.sockaddr* %36, i32* %1)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %45
br label %39
45: ; preds = %39
%46 = load i32, i32* %37
%47 = call i8* @inet_ntoa(i32 %46)
%48 = load i32, i32* %38
%49 = call i32 @htons(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %47, i32 %49)
%51 = call i32 @puts(i8* %7)
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0))
br label %44
}