#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) {
  int sock, i = 0;
  struct sockaddr_in destination, source;
  int size = 10000;
  int addr_len = sizeof(struct sockaddr_in);
  char data[200] = "TEST\n";
  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) {
    printf("Sending burst ...\n");
    for (i = 0; i < 5000; i++) {
      addr_len = sizeof(destination);
      size =
          sendto(sock, data, 5, 0, (struct sockaddr *)&destination, addr_len);
    }
    for (i = 0; i < 500; i++) {
      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    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x2710,-0x2c(%rbp)
movl   $0xc,-0x30(%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    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1771,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rdx
lea    0xde8(%rip),%rsi
call   1070 <inet_pton@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    0xdc3(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x1388,-0xc(%rbp)
jge    1296 <main+0x116>
movl   $0xc,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x100(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    -0x30(%rbp),%r9d
mov    $0x5,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1253 <main+0xd3>
movl   $0x0,-0xc(%rbp)
cmpl   $0x1f4,-0xc(%rbp)
jge    12d6 <main+0x156>
mov    -0x8(%rbp),%edi
lea    -0x100(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x7d0,%edx
xor    %ecx,%ecx
lea    -0x30(%rbp),%r9
call   1080 <recvfrom@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    129d <main+0x11d>
jmp    1240 <main+0xc0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
movl   $0xc,0xc(%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),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2dd9(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x1771,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%rbx),%edi
lea    0xdd4(%rip),%rsi
mov    %rbp,%rdx
call   1060 <inet_pton@plt>
mov    (%rbx),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %eax,%ebp
lea    0x30(%rsp),%r15
lea    0x20(%rsp),%r12
lea    0xc(%rsp),%r13
xchg   %ax,%ax
lea    0xda3(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1388,%r14d
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
movl   $0xc,0xc(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x5,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
add    $0xffffffff,%r14d
jne    1280 <main+0x110>
mov    $0x1f4,%ebx
nopl   (%rax)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r13,%r9
call   1070 <recvfrom@plt>
add    $0xffffffff,%ebx
jne    12b0 <main+0x140>
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 = [19 x i8] c"Sending burst ...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca [200 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
store i32 10000, i32* %6
store i32 12, i32* %7
%9 = bitcast [200 x i8]* %8 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 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 6001)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%23 = call i32 @inet_pton(i32 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %22)
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = load i32, i32* @IPPROTO_UDP
%27 = call i32 @socket(i32 %24, i32 %25, i32 %26)
store i32 %27, i32* %2
br label %28
28: ; preds = %0, %54
%29 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %30
30: ; preds = %39, %28
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 5000
br i1 %32, label %33, label %42
33: ; preds = %30
store i32 12, i32* %7
%34 = load i32, i32* %2
%35 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%37 = load i32, i32* %7
%38 = call i32 @sendto(i32 %34, i8* %35, i32 5, i32 0, %struct.sockaddr* %36, i32 %37)
store i32 %38, i32* %6
br label %39
39: ; preds = %33
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %30
42: ; preds = %30
store i32 0, i32* %3
br label %43
43: ; preds = %51, %42
%44 = load i32, i32* %3
%45 = icmp slt i32 %44, 500
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i32, i32* %2
%48 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%49 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%50 = call i32 @recvfrom(i32 %47, i8* %48, i32 2000, i32 0, %struct.sockaddr* %49, i32* %7)
br label %51
51: ; preds = %46
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %43
54: ; preds = %43
br label %28
}

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 = [18 x i8] c"Sending burst ...\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*
store i32 12, i32* %3
%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 = %34, %0
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %27, %29
%30 = phi i32 [ 0, %27 ], [ %32, %29 ]
store i32 12, i32* %3
%31 = call i32 @sendto(i32 %24, i8* %8, i32 5, i32 0, %struct.sockaddr* %25, i32 12)
%32 = add nuw nsw i32 %30, 1
%33 = icmp eq i32 %32, 5000
br i1 %33, label %34, label %29
34: ; preds = %29, %34
%35 = phi i32 [ %37, %34 ], [ 0, %29 ]
%36 = call i32 @recvfrom(i32 %24, i8* %8, i32 2000, i32 0, %struct.sockaddr* %26, i32* %3)
%37 = add nuw nsw i32 %35, 1
%38 = icmp eq i32 %37, 500
br i1 %38, label %27, label %34
}