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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int sockfd;
  int n;
  socklen_t len;
  char msg[1024];
  struct sockaddr_in servaddr, cliaddr;
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = INADDR_ANY;
  servaddr.sin_port = htons(5035);
  printf("\n\n Binded");
  bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  printf("\n\n Listening...");
  for (;;) {
    printf("\n ");
    len = sizeof(cliaddr);
    n = recvfrom(sockfd, msg, 1024, 0, (struct sockaddr *)&cliaddr, &len);
    printf("\n Client's Message : %s\n", msg);
    if (n < 6)
      perror("send error");
    sendto(sockfd, msg, n, 0, (struct sockaddr *)&cliaddr, len);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x41c(%rbp)
mov    $0x13ab,%edi
call   1030 <htons@plt>
mov    %eax,-0x420(%rbp)
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xc,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
lea    -0x430(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x10(%rbp),%r9
call   1060 <recvfrom@plt>
mov    %eax,-0xc(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x6,-0xc(%rbp)
jge    1281 <main+0x101>
lea    0xdba(%rip),%rdi
call   1080 <perror@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x430(%rbp),%r8
mov    -0x10(%rbp),%r9d
xor    %ecx,%ecx
call   1050 <sendto@plt>
jmp    121d <main+0x9d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2e50(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x13ab,%edi
call   1030 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0xdfd(%rip),%r13
jmp    1247 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1050 <sendto@plt>
lea    0xdcc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0xc,0xc(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1060 <recvfrom@plt>
mov    %eax,%r14d
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x5,%r14d
jg     1230 <main+0xb0>
lea    0xda5(%rip),%rdi
call   1080 <perror@plt>
jmp    1230 <main+0xb0>

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
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [10 x i8] c"\0A\0A Binded\00"
@.str.1 = [16 x i8] c"\0A\0A Listening...\00"
@.str.2 = [3 x i8] c"\0A \00"
@.str.3 = [25 x i8] c"\0A Client's Message : %s\0A\00"
@.str.4 = [11 x i8] c"send error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = call i32 @htons(i32 5035)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %17, i32* %18
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %36, %0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 12, i32* %4
%26 = load i32, i32* %2
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%28 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%29 = call i32 @recvfrom(i32 %26, i8* %27, i32 1024, i32 0, %struct.sockaddr* %28, i32* %4)
store i32 %29, i32* %3
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 6
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %24
%37 = load i32, i32* %2
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%39 = load i32, i32* %3
%40 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%41 = load i32, i32* %4
%42 = call i32 @sendto(i32 %37, i8* %38, i32 %39, i32 0, %struct.sockaddr* %40, i32 %41)
br label %24
}

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
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [10 x i8] c"\0A\0A Binded\00"
@.str.1 = [16 x i8] c"\0A\0A Listening...\00"
@.str.2 = [3 x i8] c"\0A \00"
@.str.3 = [25 x i8] c"\0A Client's Message : %s\0A\00"
@.str.4 = [11 x i8] c"send error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 5035)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %17, i32* %18
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i32 @bind(i32 %11, %struct.sockaddr* %20, i32 12)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %24
24: ; preds = %31, %0
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 12, i32* %1
%26 = call i32 @recvfrom(i32 %11, i8* %6, i32 1024, i32 0, %struct.sockaddr* %23, i32* %1)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%28 = icmp slt i32 %26, 6
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = load i32, i32* %1
%33 = call i32 @sendto(i32 %11, i8* %6, i32 %26, i32 0, %struct.sockaddr* %23, i32 %32)
br label %24
}