#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 in_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
int create_socket(struct in_addr *, int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_frames(int);
int main(int argc, char *argv[]) {
  char *ip = "172.16.50.1";
  if (argc >= 2)
    ip = argv[1];
  struct in_addr remote_ip;
  inet_aton(ip, &remote_ip);
  int port = 1000;
  printf("Remote host: %s:%d\n", ip, port);
  for (int p = 0; p < 1024; p++) {
    int mySocket = create_socket(&remote_ip, port + p);
    send_frames(mySocket);
    close(mySocket);
  }
  printf("Sender finished\n");
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1197 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <inet_aton@plt>
movl   $0x3e8,-0x24(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x400,-0x28(%rbp)
jge    1204 <main+0xa4>
mov    -0x24(%rbp),%esi
add    -0x28(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1080 <create_socket@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <send_frames@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c7 <main+0x67>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1182 <main+0x12>
mov    0x8(%rsi),%r14
jmp    1189 <main+0x19>
lea    0xe77(%rip),%r14
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <inet_aton@plt>
lea    0xe6e(%rip),%rdi
mov    $0x3e8,%ebp
mov    %r14,%rsi
mov    $0x3e8,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebp,%esi
call   1090 <create_socket@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <send_frames@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x1,%ebp
cmp    $0x7e8,%ebp
jne    11c0 <main+0x50>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [12 x i8] c"172.16.50.1\00"
@.str.1 = [20 x i8] c"Remote host: %s:%d\0A\00"
@.str.2 = [17 x i8] c"Sender finished\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.in_addr
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
br label %17
17: ; preds = %13, %2
%18 = load i8*, i8** %6
%19 = call i32 @inet_aton(i8* %18, %struct.in_addr* %7)
store i32 1000, i32* %8
%20 = load i8*, i8** %6
%21 = load i32, i32* %8
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
store i32 0, i32* %9
br label %23
23: ; preds = %35, %17
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 1024
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = add nsw i32 %27, %28
%30 = call i32 @create_socket(%struct.in_addr* %7, i32 %29)
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = call i32 @send_frames(i32 %31)
%33 = load i32, i32* %10
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %26
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %23
38: ; preds = %23
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 (...) @getchar()
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [12 x i8] c"172.16.50.1\00"
@.str.1 = [20 x i8] c"Remote host: %s:%d\0A\00"
@str = [16 x i8] c"Sender finished\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
br label %8
8: ; preds = %5, %2
%9 = phi i8* [ %7, %5 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = bitcast %struct.in_addr* %3 to i8*
%11 = call i32 @inet_aton(i8* %9, %struct.in_addr* %3)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 1000)
br label %16
13: ; preds = %16
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%15 = call i32 (...) @getchar()
ret i32 0
16: ; preds = %8, %16
%17 = phi i32 [ 0, %8 ], [ %22, %16 ]
%18 = add nuw nsw i32 %17, 1000
%19 = call i32 @create_socket(%struct.in_addr* %3, i32 %18)
%20 = call i32 @send_frames(i32 %19)
%21 = call i32 @close(i32 %19)
%22 = add nuw nsw i32 %17, 1
%23 = icmp eq i32 %22, 1024
br i1 %23, label %13, label %16
}