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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int tcp_connect(char *, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd;
  char buf[1024];
  ssize_t nbytes;
  if ((sockfd = tcp_connect("phddns60.oray.net", "6060")) == -1)
    exit(1);
  memset(buf, 0, sizeof(buf));
  if ((nbytes = read(sockfd, buf, 1024)) == -1) {
    fprintf(stderr, "read() failed: %s\n", strerror(errno));
    exit(1);
  }
  printf("[recv server welcome string - %ld bytes]:\n%s\n\n", nbytes, buf);
  nbytes = write(sockfd, "AUTH ROUTER6\r\n", sizeof("AUTH ROUTER6\r\n"));
  if (nbytes != sizeof("AUTH ROUTER6\r\n")) {
    perror("write() failed");
    exit(1);
  }
  memset(buf, 0, sizeof(buf));
  if ((nbytes = read(sockfd, buf, 1024)) == -1) {
    fprintf(stderr, "read() failed: %s\n", strerror(errno));
    exit(1);
  }
  printf("[recv server side key - %ld bytes]:\n%s\n\n", nbytes, buf);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   1040 <tcp_connect@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11e2 <main+0x42>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0xffffffff,%eax
jne    1254 <main+0xb4>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x428(%rbp),%edi
mov    %rax,%rdx
lea    0xdd2(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x424(%rbp),%esi
lea    -0x420(%rbp),%rdx
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
lea    0xde2(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
mov    %eax,-0x424(%rbp)
movslq -0x424(%rbp),%rax
cmp    $0xf,%rax
je     12ae <main+0x10e>
lea    0xdc9(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0xffffffff,%eax
jne    1320 <main+0x180>
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x42c(%rbp)
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x42c(%rbp),%edi
mov    %rax,%rdx
lea    0xd06(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x424(%rbp),%esi
lea    -0x420(%rbp),%rdx
lea    0xd43(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xe4f(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <tcp_connect@plt>
cmp    $0xffffffff,%eax
je     128a <main+0xea>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     1262 <main+0xc2>
lea    0xe35(%rip),%rdi
mov    %rsp,%rdx
mov    %eax,%esi
call   1050 <printf@plt>
lea    0xe53(%rip),%rsi
mov    %ebx,%edi
mov    $0xf,%edx
call   1030 <write@plt>
cmp    $0xf,%eax
jne    1294 <main+0xf4>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     1262 <main+0xc2>
lea    0xe33(%rip),%rdi
mov    %rsp,%rdx
mov    %eax,%esi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d77(%rip),%rax
mov    (%rax),%ebx
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd97(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdcd(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"phddns60.oray.net\00"
@.str.1 = [5 x i8] c"6060\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"read() failed: %s\0A\00"
@errno = global i32 0
@.str.3 = [47 x i8] c"[recv server welcome string - %ld bytes]:\0A%s\0A\0A\00"
@.str.4 = [15 x i8] c"AUTH ROUTER6\0D\0A\00"
@.str.5 = [15 x i8] c"write() failed\00"
@.str.6 = [41 x i8] c"[recv server side key - %ld bytes]:\0A%s\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @tcp_connect(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %9, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 1024)
%16 = load i32, i32* %6
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 1024)
store i32 %18, i32* %8
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %13
%27 = load i32, i32* %8
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %27, i8* %28)
%30 = load i32, i32* %6
%31 = call i32 @write(i32 %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 15)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = icmp ne i64 %33, 15
br i1 %34, label %35, label %38
35: ; preds = %26
%36 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %26
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 1024)
%41 = load i32, i32* %6
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%43 = call i32 @read(i32 %41, i8* %42, i32 1024)
store i32 %43, i32* %8
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %51
45: ; preds = %38
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %38
%52 = load i32, i32* %8
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%54 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %52, i8* %53)
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"phddns60.oray.net\00"
@.str.1 = [5 x i8] c"6060\00"
@stderr = global i32 0
@.str.2 = [19 x i8] c"read() failed: %s\0A\00"
@errno = global i32 0
@.str.3 = [47 x i8] c"[recv server welcome string - %ld bytes]:\0A%s\0A\0A\00"
@.str.4 = [15 x i8] c"AUTH ROUTER6\0D\0A\00"
@.str.5 = [15 x i8] c"write() failed\00"
@.str.6 = [41 x i8] c"[recv server side key - %ld bytes]:\0A%s\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @tcp_connect(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = call i32 @memset(i8* %4, i32 0, i32 1024)
%11 = call i32 @read(i32 %5, i8* %4, i32 1024)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %9
%20 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %11, i8* %4)
%21 = call i32 @write(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 15)
%22 = icmp eq i32 %21, 15
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = call i32 @memset(i8* %4, i32 0, i32 1024)
%28 = call i32 @read(i32 %5, i8* %4, i32 1024)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26
%37 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %28, i8* %4)
%38 = call i32 @close(i32 %5)
ret i32 0
}