#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 /*<<< orphan*/ addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ sendto(int, unsigned char *, int, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  FILE *f;
  int len, size = 1500;
  int fd;
  int count = 0;
  struct sockaddr_in addr;
  if (argc < 3)
    return -1;
  f = fopen(argv[1], "rb");
  unsigned char buf[1500];
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero(&addr, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr(argv[2]);
  addr.sin_port = htons(5050);
  while (1) {
    if (count % 2) {
      size = 1500;
    } else {
      size = 1500 / 3;
    }
    len = fread(buf, sizeof(unsigned char), size, f);
    if (len <= 0)
      return 0;
    if (0 >= sendto(fd, buf, len, 0, (struct sockaddr *)&addr, sizeof(addr)))
      return 0;
    usleep(1000 * 10);
    count++;
  }
  close(fd);
  fclose(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x620,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x5dc,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bd <main+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d0 <main+0x150>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe34(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
mov    $0x13ba,%edi
call   1040 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1248 <main+0xc8>
movl   $0x5dc,-0x20(%rbp)
jmp    124f <main+0xcf>
movl   $0x1f4,-0x20(%rbp)
lea    -0x620(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1280 <main+0x100>
movl   $0x0,-0x4(%rbp)
jmp    12d0 <main+0x150>
mov    -0x24(%rbp),%edi
lea    -0x620(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jl     12b8 <main+0x138>
movl   $0x0,-0x4(%rbp)
jmp    12d0 <main+0x150>
mov    $0x2710,%edi
call   1090 <usleep@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1228 <main+0xa8>
mov    -0x4(%rbp),%eax
add    $0x620,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0xffffffff,%eax
cmp    $0x3,%edi
jl     128e <main+0x10e>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5f8,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe53(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    0x2e2c(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%r13d
mov    %rsp,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%rbx),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x13ba,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1f4,%r14d
mov    $0x1,%esi
mov    $0x1f4,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    127b <main+0xfb>
lea    0x10(%rsp),%rbx
mov    %rsp,%r12
xchg   %ax,%ax
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
test   %rax,%rax
jle    127b <main+0xfb>
mov    $0x2710,%edi
call   1090 <usleep@plt>
test   $0x1,%bpl
mov    $0x5dc,%edx
cmove  %r14d,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1030 <fread@plt>
add    $0x1,%ebp
test   %eax,%eax
jg     1230 <main+0xb0>
xor    %eax,%eax
add    $0x5f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"rb\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca [1500 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1500, i32* %8
store i32 0, i32* %10
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %61
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %9
%24 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %25, i32* %26
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @inet_addr(i8* %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = call i32 @htons(i32 5050)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %33, i32* %34
br label %35
35: ; preds = %16, %57
%36 = load i32, i32* %10
%37 = srem i32 %36, 2
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1500, i32* %8
br label %41
40: ; preds = %35
store i32 500, i32* %8
br label %41
41: ; preds = %40, %39
%42 = getelementptr inbounds [1500 x i8], [1500 x i8]* %12, i64 0, i64 0
%43 = load i32, i32* %8
%44 = load i32*, i32** %6
%45 = call i32 @fread(i8* %42, i32 1, i32 %43, i32* %44)
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = icmp sle i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %41
store i32 0, i32* %3
br label %61
49: ; preds = %41
%50 = load i32, i32* %9
%51 = getelementptr inbounds [1500 x i8], [1500 x i8]* %12, i64 0, i64 0
%52 = load i32, i32* %7
%53 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%54 = call i64 @sendto(i32 %50, i8* %51, i32 %52, i32 0, %struct.sockaddr* %53, i32 12)
%55 = icmp sge i64 0, %54
br i1 %55, label %56, label %57
56: ; preds = %49
store i32 0, i32* %3
br label %61
57: ; preds = %49
%58 = call i32 @usleep(i32 10000)
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
br label %35
61: ; preds = %56, %48, %15
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"rb\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1500 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = icmp slt i32 %0, 3
br i1 %6, label %41, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @inet_addr(i8* %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 5050)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @fread(i8* %11, i32 1, i32 500, i32* %10)
%26 = icmp slt i32 %25, 1
br i1 %26, label %40, label %27
27: ; preds = %7, %32
%28 = phi i32 [ %38, %32 ], [ %25, %7 ]
%29 = phi i32 [ %34, %32 ], [ 0, %7 ]
%30 = call i64 @sendto(i32 %14, i8* %11, i32 %28, i32 0, %struct.sockaddr* %24, i32 12)
%31 = icmp slt i64 %30, 1
br i1 %31, label %40, label %32
32: ; preds = %27
%33 = call i32 @usleep(i32 10000)
%34 = add nuw nsw i32 %29, 1
%35 = and i32 %34, 1
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i32 500, i32 1500
%38 = call i32 @fread(i8* %11, i32 1, i32 %37, i32* %10)
%39 = icmp slt i32 %38, 1
br i1 %39, label %40, label %27
40: ; preds = %32, %27, %7
br label %41
41: ; preds = %2, %40
%42 = phi i32 [ 0, %40 ], [ -1, %2 ]
ret i32 %42
}