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

/* Variables and functions */
int /*<<< orphan*/ MSG_OOB;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_SNDBUF;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int tcp_connect(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, size;
  char buf[16384];
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <host> <port>\n", argv[0]);
    return -1;
  }
  if ((sockfd = tcp_connect(argv[1], argv[2])) == -1)
    return -1;
  size = 32768;
  setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size));
  write(sockfd, buf, 16384);
  printf("wrote 16384 bytes of normal data\n");
  sleep(5);
  send(sockfd, "a", 1, MSG_OOB);
  printf("wrote 1 byte of OOB data\n");
  write(sockfd, buf, 1024);
  printf("wrote 1024 bytes of normal data\n");
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11cb <main+0x4b>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe46(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a5 <main+0x125>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <tcp_connect@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f8 <main+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a5 <main+0x125>
movl   $0x8000,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
lea    -0x4020(%rbp),%rsi
mov    $0x4000,%edx
call   1040 <write@plt>
lea    0xddb(%rip),%rdi
call   1070 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    -0x14(%rbp),%edi
mov    0x2d81(%rip),%rax
mov    (%rax),%ecx
lea    0xddb(%rip),%rsi
mov    $0x1,%edx
call   1060 <send@plt>
lea    0xdcc(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x4020(%rbp),%rsi
mov    $0x400,%edx
call   1040 <write@plt>
lea    0xdc6(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x4018,%rsp
cmp    $0x3,%edi
jne    124f <main+0xcf>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1060 <tcp_connect@plt>
cmp    $0xffffffff,%eax
je     1267 <main+0xe7>
mov    %eax,%ebx
movl   $0x8000,0xc(%rsp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4000,%edx
call   1050 <write@plt>
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%ecx
lea    0xe40(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <send@plt>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1050 <write@plt>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
jmp    126c <main+0xec>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd9e(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x4018,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s <host> <port>\0A\00"
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@.str.1 = [34 x i8] c"wrote 16384 bytes of normal data\0A\00"
@.str.2 = [2 x i8] c"a\00"
@MSG_OOB = global i32 0
@.str.3 = [26 x i8] c"wrote 1 byte of OOB data\0A\00"
@.str.4 = [33 x i8] c"wrote 1024 bytes of normal data\0A\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 [16384 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %47
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @tcp_connect(i8* %20, i8* %23)
store i32 %24, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %17
store i32 -1, i32* %3
br label %47
27: ; preds = %17
store i32 32768, i32* %7
%28 = load i32, i32* %6
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_SNDBUF
%31 = call i32 @setsockopt(i32 %28, i32 %29, i32 %30, i32* %7, i32 4)
%32 = load i32, i32* %6
%33 = getelementptr inbounds [16384 x i8], [16384 x i8]* %8, i64 0, i64 0
%34 = call i32 @write(i32 %32, i8* %33, i32 16384)
%35 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @sleep(i32 5)
%37 = load i32, i32* %6
%38 = load i32, i32* @MSG_OOB
%39 = call i32 @send(i32 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* %6
%42 = getelementptr inbounds [16384 x i8], [16384 x i8]* %8, i64 0, i64 0
%43 = call i32 @write(i32 %41, i8* %42, i32 1024)
%44 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
store i32 0, i32* %3
br label %47
47: ; preds = %27, %26, %11
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s <host> <port>\0A\00"
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@.str.2 = [2 x i8] c"a\00"
@MSG_OOB = global i32 0
@str = [33 x i8] c"wrote 16384 bytes of normal data\00"
@str.5 = [25 x i8] c"wrote 1 byte of OOB data\00"
@str.6 = [32 x i8] c"wrote 1024 bytes of normal data\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [16384 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %32
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @tcp_connect(i8* %14, i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %32, label %19
19: ; preds = %12
store i32 32768, i32* %3
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_SNDBUF
%22 = call i32 @setsockopt(i32 %17, i32 %20, i32 %21, i32* %3, i32 4)
%23 = call i32 @write(i32 %17, i8* %6, i32 16384)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%25 = call i32 @sleep(i32 5)
%26 = load i32, i32* @MSG_OOB
%27 = call i32 @send(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %26)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%29 = call i32 @write(i32 %17, i8* %6, i32 1024)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%31 = call i32 @close(i32 %17)
br label %32
32: ; preds = %12, %19, %8
%33 = phi i32 [ -1, %8 ], [ 0, %19 ], [ -1, %12 ]
ret i32 %33
}