#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 */

/* Variables and functions */
int /*<<< orphan*/ MSG_OOB;
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*/ sleep(int);
int /*<<< orphan*/ stderr;
int tcp_connect(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd;
  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;
  write(sockfd, "123", 3);
  printf("wrote 3 bytes of normal data\n");
  sleep(1);
  send(sockfd, "4", 1, MSG_OOB);
  printf("wrote 1 byte of OOB data\n");
  sleep(1);
  write(sockfd, "56", 2);
  printf("wrote 2 bytes of normal data\n");
  sleep(1);
  send(sockfd, "7", 1, MSG_OOB);
  printf("wrote 1 byte of OOB data\n");
  sleep(1);
  write(sockfd, "89", 2);
  printf("wrote 2 bytes of normal data\n");
  sleep(1);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b8 <main+0x48>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d8 <main+0x168>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <tcp_connect@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11e5 <main+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d8 <main+0x168>
mov    -0x14(%rbp),%edi
lea    0xe2a(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
lea    0xe1d(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x14(%rbp),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%ecx
lea    0xe19(%rip),%rsi
mov    $0x1,%edx
call   1050 <send@plt>
lea    0xe0a(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x14(%rbp),%edi
lea    0xe0b(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
lea    0xdfd(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x14(%rbp),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%ecx
lea    0xdf9(%rip),%rsi
mov    $0x1,%edx
call   1050 <send@plt>
lea    0xdad(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x14(%rbp),%edi
lea    0xdd1(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
lea    0xda0(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    127e <main+0x10e>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1050 <tcp_connect@plt>
cmp    $0xffffffff,%eax
je     1296 <main+0x126>
mov    %eax,%ebx
lea    0xe79(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1040 <write@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    0x2e1f(%rip),%r12
mov    (%r12),%ecx
lea    0xe49(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <send@plt>
lea    0xe5d(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xe1f(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <write@plt>
lea    0xe4a(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    (%r12),%ecx
lea    0xdf2(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <send@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xdcf(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    129b <main+0x12b>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd6f(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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