#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*/ name;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, int);
int read(int /*<<< orphan*/, char *, int);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int sd = socket(PF_INET, SOCK_DGRAM, 0);
  struct sockaddr_in name;
  name.sin_family = AF_INET;
  name.sin_port = htons(9500);
  name.sin_addr.s_addr = inet_addr("127.0.0.1");
  char buff[20];
  int len = sizeof(name);
  while (1) {
    int n = read(0, buff, sizeof(buff));
    int s = sendto(sd, buff, n, 0, (struct sockaddr *)&name, len);
    printf("data sent : %d\n", s);
    n = recvfrom(sd, buff, 20, 0, (struct sockaddr *)&name, &len);
    printf("data received : %d\n", n);
    write(1, buff, n);
  }
  close(sd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x251c,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xe35(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
movl   $0xc,-0x34(%rbp)
lea    -0x30(%rbp),%rsi
xor    %edi,%edi
mov    $0x14,%edx
call   1070 <read@plt>
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%edx
lea    -0x18(%rbp),%r8
mov    -0x34(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x14,%edx
xor    %ecx,%ecx
lea    -0x34(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
lea    0xdda(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11da <main+0x5a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x251c,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe35(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x10(%rsp)
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r12
lea    0xe28(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1070 <read@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1060 <sendto@plt>
lea    0xdde(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r12,%r9
call   1090 <recvfrom@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <write@plt>
jmp    1200 <main+0x80>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [16 x i8] c"data sent : %d\0A\00"
@.str.2 = [20 x i8] c"data received : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @htons(i32 9500)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
store i32 12, i32* %5
br label %18
18: ; preds = %0, %18
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%20 = call i32 @read(i32 0, i8* %19, i32 20)
store i32 %20, i32* %6
%21 = load i32, i32* %2
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%23 = load i32, i32* %6
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = load i32, i32* %5
%26 = call i32 @sendto(i32 %21, i8* %22, i32 %23, i32 0, %struct.sockaddr* %24, i32 %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%32 = call i32 @recvfrom(i32 %29, i8* %30, i32 20, i32 0, %struct.sockaddr* %31, i32* %5)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%36 = load i32, i32* %6
%37 = call i32 @write(i32 1, i8* %35, i32 %36)
br label %18
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [16 x i8] c"data sent : %d\0A\00"
@.str.2 = [20 x i8] c"data received : %d\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = bitcast %struct.sockaddr_in* %1 to i8*
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @htons(i32 9500)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %12, i32* %13
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%15 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%16 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %17
17: ; preds = %17, %0
%18 = call i32 @read(i32 0, i8* %14, i32 20)
%19 = load i32, i32* %3
%20 = call i32 @sendto(i32 %6, i8* %14, i32 %18, i32 0, %struct.sockaddr* %16, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @recvfrom(i32 %6, i8* %14, i32 20, i32 0, %struct.sockaddr* %16, i32* %3)
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = call i32 @write(i32 1, i8* %14, i32 %22)
br label %17
}