#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 */

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ destination;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ 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 main(void) {
  struct sockaddr_in destination, source;
  int sock, size = 10000;
  int addr_len = sizeof(struct sockaddr_in);
  char data[200] = "TEST\n";
  unsigned long count[3] = {0, 0, 0};
  bzero(&destination, sizeof(destination));
  destination.sin_family = AF_INET;
  destination.sin_port = htons(6001);
  inet_pton(AF_INET, "127.0.0.1", &destination.sin_addr);
  sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  while (1) {
    addr_len = sizeof(destination);
    printf("send data\n");
    size = sendto(sock, data, 5, 0, (struct sockaddr *)&destination, addr_len);
    recvfrom(sock, data, 2000, 0, (struct sockaddr *)&source, &addr_len);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2710,-0x28(%rbp)
movl   $0xc,-0x2c(%rbp)
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
movb   $0x54,-0x100(%rbp)
movb   $0x45,-0xff(%rbp)
movb   $0x53,-0xfe(%rbp)
movb   $0x54,-0xfd(%rbp)
movb   $0xa,-0xfc(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x1771,%edi
call   1030 <htons@plt>
mov    %eax,-0xc(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rdx
lea    0xddc(%rip),%rsi
call   1070 <inet_pton@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
movl   $0xc,-0x2c(%rbp)
lea    0xdb0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
lea    -0x100(%rbp),%rsi
lea    -0x10(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    $0x5,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x100(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x7d0,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   1080 <recvfrom@plt>
jmp    124c <main+0xcc>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movq   $0x0,0xf0(%rsp)
movl   $0x54534554,0x30(%rsp)
54
movb   $0xa,0x34(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2de1(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x1771,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%rbx),%edi
lea    0xddc(%rip),%rsi
mov    %r14,%rdx
call   1060 <inet_pton@plt>
mov    (%rbx),%edi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
mov    0x2d8a(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %eax,%ebp
lea    0xdbc(%rip),%r15
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r12
lea    0xc(%rsp),%r13
nopl   (%rax)
movl   $0xc,0xc(%rsp)
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1050 <sendto@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r13,%r9
call   1070 <recvfrom@plt>
jmp    1260 <main+0xf0>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@str = [10 x i8] c"send data\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [200 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
store i8 84, i8* %8
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 1
store i8 69, i8* %9
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 2
store i8 83, i8* %10
%11 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 3
store i8 84, i8* %11
%12 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 4
store i8 10, i8* %12
%13 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 6001)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%20 = call i32 @inet_pton(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %19)
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = load i32, i32* @IPPROTO_UDP
%24 = call i32 @socket(i32 %21, i32 %22, i32 %23)
%25 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%26 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %27
27: ; preds = %27, %0
store i32 12, i32* %3
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* %3
%30 = call i32 @sendto(i32 %24, i8* %8, i32 5, i32 0, %struct.sockaddr* %25, i32 %29)
%31 = call i32 @recvfrom(i32 %24, i8* %8, i32 2000, i32 0, %struct.sockaddr* %26, i32* %3)
br label %27
}