#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 */
typedef int /*<<< orphan*/ val;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int MAP_ANONYMOUS;
int MAP_POPULATE;
int MAP_PRIVATE;
int /*<<< orphan*/ PF_INET;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_SNDBUF;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
void *mmap(int /*<<< orphan*/, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, char *, int);
int main(int argc, char **argv) {
  int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  int prot = PROT_READ | PROT_WRITE;
  void *buffer = mmap(0, (1 << 24), prot,
                      MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0);
  int i;
  int val = (1 << 18);
  ({
    int res;
    res = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
    if (res < 0) {
      perror("setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val))");
      return -1;
    };
    res;
  });
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  addr.sin_port = htons(1234);
  addr.sin_family = AF_INET;
  char *saddr = "127.0.0.1";
  if (argc > 1)
    saddr = argv[1];
  ({
    int res;
    res = inet_aton(saddr, (struct in_addr *)&addr.sin_addr.s_addr);
    if (res < 0) {
      perror("inet_aton(saddr, (struct in_addr *) &addr.sin_addr.s_addr)");
      return -1;
    };
    res;
  });
  ({
    int res;
    res = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
    if (res < 0) {
      perror("connect(fd, (struct sockaddr *) &addr, sizeof(addr))");
      return -1;
    };
    res;
  });
  while (1) {
    int i;
    for (i = 0; i < ((1 << 24) / (1 << 19)); i++) {
      if (write(fd, (char *)buffer + (i * (1 << 19)), (1 << 19)) != (1 << 19))
        return -1;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    0x2dbf(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    0x2dd8(%rip),%rax
mov    (%rax),%ecx
mov    0x2d9f(%rip),%rax
or     (%rax),%ecx
mov    0x2dbe(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0x1000000,%esi
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x20(%rbp)
movl   $0x40000,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1266 <main+0xd6>
lea    0xdab(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1f6>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    $0x4d2,%edi
call   1060 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    0x2d48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
lea    0xd9d(%rip),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    12b6 <main+0x126>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <inet_aton@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    12e8 <main+0x158>
lea    0xd6c(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1f6>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1324 <main+0x194>
lea    0xd6b(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1f6>
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x20,-0x5c(%rbp)
jge    1381 <main+0x1f1>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x5c(%rbp),%eax
shl    $0x13,%eax
cltq
add    %rax,%rsi
mov    $0x80000,%edx
call   1040 <write@plt>
cmp    $0x80000,%eax
je     136e <main+0x1de>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1f6>
jmp    1373 <main+0x1e3>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1331 <main+0x1a1>
jmp    132a <main+0x19a>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    0x2e2f(%rip),%rcx
mov    0x2dc8(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2de5(%rip),%rsi
mov    0x2dae(%rip),%rcx
mov    (%rcx),%ecx
or     (%rsi),%ecx
mov    %eax,%r12d
mov    0x2dc8(%rip),%rax
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x1000000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbx
movl   $0x40000,0xc(%rsp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     12da <main+0x14a>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    $0x4d2,%edi
call   1060 <htons@plt>
mov    %eax,0x18(%rsp)
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
cmp    $0x2,%r15d
jl     1277 <main+0xe7>
mov    0x8(%r14),%rdi
jmp    127e <main+0xee>
lea    0xdbb(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <inet_aton@plt>
test   %eax,%eax
js     12e3 <main+0x153>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %eax,%eax
js     12ec <main+0x15c>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rbx,%rbp,1),%rsi
mov    %r12d,%edi
mov    $0x80000,%edx
call   1040 <write@plt>
cmp    $0x80000,%eax
jne    12f8 <main+0x168>
add    $0x80000,%rbp
cmp    $0x1000000,%rbp
jne    12b0 <main+0x120>
jmp    12a2 <main+0x112>
lea    0xd1f(%rip),%rdi
jmp    12f3 <main+0x163>
lea    0xd59(%rip),%rdi
jmp    12f3 <main+0x163>
lea    0xd8b(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_POPULATE = global i32 0
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@.str = [57 x i8] c"setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val))\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [59 x i8] c"inet_aton(saddr, (struct in_addr *) &addr.sin_addr.s_addr)\00"
@.str.3 = [53 x i8] c"connect(fd, (struct sockaddr *) &addr, sizeof(addr))\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.sockaddr_in
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* @PF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = load i32, i32* @IPPROTO_TCP
%23 = call i32 @socket(i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* @PROT_READ
%25 = load i32, i32* @PROT_WRITE
%26 = or i32 %24, %25
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = load i32, i32* @MAP_ANONYMOUS
%29 = load i32, i32* @MAP_PRIVATE
%30 = or i32 %28, %29
%31 = load i32, i32* @MAP_POPULATE
%32 = or i32 %30, %31
%33 = call i8* @mmap(i32 0, i32 16777216, i32 %27, i32 %32, i32 -1, i32 0)
store i8* %33, i8** %8
store i32 262144, i32* %10
%34 = load i32, i32* %6
%35 = load i32, i32* @SOL_SOCKET
%36 = load i32, i32* @SO_SNDBUF
%37 = call i32 @setsockopt(i32 %34, i32 %35, i32 %36, i32* %10, i32 4)
store i32 %37, i32* %11
%38 = load i32, i32* %11
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %2
%41 = call i32 @perror(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %98
42: ; preds = %2
%43 = load i32, i32* %11
store i32 %43, i32* %12
%44 = load i32, i32* %12
%45 = call i32 @memset(%struct.sockaddr_in* %13, i32 0, i32 12)
%46 = call i32 @htons(i32 1234)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %46, i32* %47
%48 = load i32, i32* @AF_INET
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i32 %48, i32* %49
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %14
%50 = load i32, i32* %4
%51 = icmp sgt i32 %50, 1
br i1 %51, label %52, label %56
52: ; preds = %42
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
store i8* %55, i8** %14
br label %56
56: ; preds = %52, %42
%57 = load i8*, i8** %14
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %58, i32 0, i32 0
%60 = bitcast i32* %59 to %struct.in_addr*
%61 = call i32 @inet_aton(i8* %57, %struct.in_addr* %60)
store i32 %61, i32* %15
%62 = load i32, i32* %15
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %56
%65 = call i32 @perror(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %98
66: ; preds = %56
%67 = load i32, i32* %15
store i32 %67, i32* %16
%68 = load i32, i32* %16
%69 = load i32, i32* %6
%70 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%71 = call i32 @connect(i32 %69, %struct.sockaddr* %70, i32 12)
store i32 %71, i32* %17
%72 = load i32, i32* %17
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %66
%75 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %98
76: ; preds = %66
%77 = load i32, i32* %17
store i32 %77, i32* %18
%78 = load i32, i32* %18
br label %79
79: ; preds = %76, %97
store i32 0, i32* %19
br label %80
80: ; preds = %94, %79
%81 = load i32, i32* %19
%82 = icmp slt i32 %81, 32
br i1 %82, label %83, label %97
83: ; preds = %80
%84 = load i32, i32* %6
%85 = load i8*, i8** %8
%86 = load i32, i32* %19
%87 = mul nsw i32 %86, 524288
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %85, i64 %88
%90 = call i32 @write(i32 %84, i8* %89, i32 524288)
%91 = icmp ne i32 %90, 524288
br i1 %91, label %92, label %93
92: ; preds = %83
store i32 -1, i32* %3
br label %98
93: ; preds = %83
br label %94
94: ; preds = %93
%95 = load i32, i32* %19
%96 = add nsw i32 %95, 1
store i32 %96, i32* %19
br label %80
97: ; preds = %80
br label %79
98: ; preds = %92, %74, %64, %40
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_POPULATE = global i32 0
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@.str = [57 x i8] c"setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val))\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [59 x i8] c"inet_aton(saddr, (struct in_addr *) &addr.sin_addr.s_addr)\00"
@.str.3 = [53 x i8] c"connect(fd, (struct sockaddr *) &addr, sizeof(addr))\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = load i32, i32* @PROT_READ
%10 = load i32, i32* @PROT_WRITE
%11 = or i32 %10, %9
%12 = load i32, i32* @MAP_ANONYMOUS
%13 = load i32, i32* @MAP_PRIVATE
%14 = or i32 %13, %12
%15 = load i32, i32* @MAP_POPULATE
%16 = or i32 %14, %15
%17 = tail call i8* @mmap(i32 0, i32 16777216, i32 %11, i32 %16, i32 -1, i32 0)
%18 = bitcast i32* %3 to i8*
store i32 262144, i32* %3
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_SNDBUF
%21 = call i32 @setsockopt(i32 %8, i32 %19, i32 %20, i32* %3, i32 4)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 @perror(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
br label %59
25: ; preds = %2
%26 = bitcast %struct.sockaddr_in* %4 to i8*
%27 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%28 = call i32 @htons(i32 1234)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %28, i32* %29
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %30, i32* %31
%32 = icmp sgt i32 %0, 1
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
br label %36
36: ; preds = %33, %25
%37 = phi i8* [ %35, %33 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %25 ]
%38 = bitcast %struct.sockaddr_in* %4 to %struct.in_addr*
%39 = call i32 @inet_aton(i8* %37, %struct.in_addr* %38)
%40 = icmp slt i32 %39, 0
br i1 %40, label %55, label %41
41: ; preds = %36
%42 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%43 = call i32 @connect(i32 %8, %struct.sockaddr* %42, i32 12)
%44 = icmp slt i32 %43, 0
br i1 %44, label %55, label %45
45: ; preds = %46, %41
br label %49
46: ; preds = %49
%47 = add nuw nsw i64 %50, 1
%48 = icmp eq i64 %47, 32
br i1 %48, label %45, label %49
49: ; preds = %45, %46
%50 = phi i64 [ 0, %45 ], [ %47, %46 ]
%51 = shl nuw nsw i64 %50, 19
%52 = getelementptr inbounds i8, i8* %17, i64 %51
%53 = call i32 @write(i32 %8, i8* %52, i32 524288)
%54 = icmp eq i32 %53, 524288
br i1 %54, label %46, label %58
55: ; preds = %41, %36
%56 = phi i8* [ getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), %36 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), %41 ]
%57 = call i32 @perror(i8* %56)
br label %58
58: ; preds = %49, %55
br label %59
59: ; preds = %23, %58
ret i32 -1
}