#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*/ _close(int);
scalar_t__ _connect(int, unsigned long *, int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int _read(int, unsigned char *, int);
int _socket(int, int, int);
int /*<<< orphan*/ _write(int, unsigned char *, int);
int _start(int argc, char **argv) {
  int s, l;
  unsigned long addr = 0x0100007f11110002;
  unsigned char buf[1024];
  if ((s = _socket(2, 1, 6)) < 0)
    return -2;
  if (_connect(s, &addr, 16) < 0) {
    return -3;
  }
  while (1) {
    if ((l = _read(s, buf, 1024)) <= 0)
      break;
    _write(1, buf, l);
    if (l < 1024)
      break;
  }
  _close(s);
  _exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0x100007f11110002,%rax
mov    %rax,-0x20(%rbp)
mov    $0x2,%edi
mov    $0x1,%esi
mov    $0x6,%edx
call   1040 <_socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ac <_start+0x4c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1237 <_start+0xd7>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1070 <_connect@plt>
cmp    $0x0,%rax
jge    11d3 <_start+0x73>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1237 <_start+0xd7>
jmp    11d8 <_start+0x78>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <_read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jg     11fd <_start+0x9d>
jmp    1228 <_start+0xc8>
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1060 <_write@plt>
cmpl   $0x400,-0x18(%rbp)
jge    1223 <_start+0xc3>
jmp    1228 <_start+0xc8>
jmp    11d8 <_start+0x78>
mov    -0x14(%rbp),%edi
call   1050 <_close@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_start>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
movabs $0x100007f11110002,%rax
mov    %rax,0x8(%rsp)
mov    $0x2,%edi
mov    $0x1,%esi
mov    $0x6,%edx
call   1040 <_socket@plt>
test   %eax,%eax
js     11fa <_start+0x9a>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1070 <_connect@plt>
mov    %rax,%rcx
mov    $0xfffffffd,%eax
test   %rcx,%rcx
js     11ff <_start+0x9f>
lea    0x10(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1080 <_read@plt>
test   %eax,%eax
jle    11ec <_start+0x8c>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <_write@plt>
cmp    $0x3ff,%ebp
ja     11c0 <_start+0x60>
mov    %ebx,%edi
call   1050 <_close@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    $0xfffffffe,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_start(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca [1024 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 72058139785101314, i64* %8
%10 = call i32 @_socket(i32 2, i32 1, i32 6)
store i32 %10, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -2, i32* %3
br label %37
13: ; preds = %2
%14 = load i32, i32* %6
%15 = call i64 @_connect(i32 %14, i64* %8, i32 16)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -3, i32* %3
br label %37
18: ; preds = %13
br label %19
19: ; preds = %18, %32
%20 = load i32, i32* %6
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%22 = call i32 @_read(i32 %20, i8* %21, i32 1024)
store i32 %22, i32* %7
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %33
25: ; preds = %19
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%27 = load i32, i32* %7
%28 = call i32 @_write(i32 1, i8* %26, i32 %27)
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 1024
br i1 %30, label %31, label %32
31: ; preds = %25
br label %33
32: ; preds = %25
br label %19
33: ; preds = %31, %24
%34 = load i32, i32* %6
%35 = call i32 @_close(i32 %34)
%36 = call i32 @_exit(i32 0)
unreachable
37: ; preds = %17, %12
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @_start(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [1024 x i8]
%5 = bitcast i64* %3 to i8*
store i64 72058139785101314, i64* %3
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @_socket(i32 2, i32 1, i32 6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = call i64 @_connect(i32 %7, i64* %3, i32 16)
%11 = icmp slt i64 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %9, %15
%13 = call i32 @_read(i32 %7, i8* %6, i32 1024)
%14 = icmp slt i32 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = call i32 @_write(i32 1, i8* %6, i32 %13)
%17 = icmp ult i32 %13, 1024
br i1 %17, label %18, label %12
18: ; preds = %15, %12
%19 = call i32 @_close(i32 %7)
%20 = call i32 @_exit(i32 0)
unreachable
21: ; preds = %9, %2
%22 = phi i32 [ -2, %2 ], [ -3, %9 ]
ret i32 %22
}