#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*/ 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");
  send(sockfd, "4", 1, MSG_OOB);
  printf("wrote 1 byte of OOB data\n");
  write(sockfd, "56", 2);
  printf("wrote 2 bytes of normal data\n");
  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     11a8 <main+0x48>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124d <main+0xed>
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    11d5 <main+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    124d <main+0xed>
mov    -0x14(%rbp),%edi
lea    0xe3a(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
lea    0xe2d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%ecx
lea    0xe33(%rip),%rsi
mov    $0x1,%edx
call   1050 <send@plt>
lea    0xe24(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    0xe2f(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
lea    0xe21(%rip),%rdi
call   1060 <printf@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   %rbx
cmp    $0x3,%edi
jne    11f3 <main+0x93>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1050 <tcp_connect@plt>
cmp    $0xffffffff,%eax
je     120b <main+0xab>
mov    %eax,%ebx
lea    0xe90(%rip),%rsi
mov    %eax,%edi
mov    $0x3,%edx
call   1040 <write@plt>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%ecx
lea    0xe6c(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <send@plt>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4f(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <write@plt>
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xdfa(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
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"
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 %38
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 %38
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 = load i32, i32* %6
%30 = load i32, i32* @MSG_OOB
%31 = call i32 @send(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32, i32* %6
%34 = call i32 @write(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%35 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %25, %24, %9
%39 = load i32, i32* %3
ret i32 %39
}

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 = [29 x i8] c"wrote 3 bytes of normal data\00"
@str.7 = [25 x i8] c"wrote 1 byte of OOB data\00"
@str.8 = [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 %24
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 %24, 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 = load i32, i32* @MSG_OOB
%19 = tail call i32 @send(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %18)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%21 = tail call i32 @write(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.8, i64 0, i64 0))
%23 = tail call i32 @close(i32 %13)
br label %24
24: ; preds = %8, %15, %4
%25 = phi i32 [ -1, %4 ], [ 0, %15 ], [ -1, %8 ]
ret i32 %25
}