#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ setlinebuf(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
int main(void) {
  int sock_fd, length, gotenv = 0;
  struct sockaddr_in address;
  char line[80];
  setlinebuf(stdin);
  setlinebuf(stdout);
  address.sin_family = PF_INET;
  address.sin_port = htons(6666);
  address.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(&(address.sin_zero), '\0', 8);
  if ((sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
    exit(1);
  if (connect(sock_fd, (struct sockaddr *)&address, sizeof(struct sockaddr)) ==
      -1)
    exit(1);
  while (!gotenv) {
    fgets(line, 80, stdin);
    if ('\n' == line[0])
      gotenv = 1;
    else
      send(sock_fd, line, strlen(line), 0);
  }
  send(sock_fd, line, strlen(line), 0);
  while (0 < (length = recv(sock_fd, line, 79, 0))) {
    line[length] = '\0';
    fputs(line, stdout);
    fgets(line, 80, stdin);
    send(sock_fd, line, strlen(line) - 1, 0);
  }
  close(sock_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1080 <setlinebuf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1080 <setlinebuf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x1a0a,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
lea    0xddb(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
mov    0x2d8a(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1273 <main+0xa3>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1297 <main+0xc7>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    129c <main+0xcc>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12b2 <main+0xe2>
jmp    1313 <main+0x143>
lea    -0x70(%rbp),%rdi
mov    0x2d2b(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   10b0 <fgets@plt>
movsbl -0x70(%rbp),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    12e6 <main+0x116>
movl   $0x1,-0x10(%rbp)
jmp    130e <main+0x13e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    129c <main+0xcc>
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x4f,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jge    13d8 <main+0x208>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rdi
mov    0x2c43(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
lea    -0x70(%rbp),%rdi
mov    0x2c59(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   10b0 <fgets@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %rax,%rdx
sub    $0x1,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    1347 <main+0x177>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    0x2e05(%rip),%r14
mov    (%r14),%edi
call   1080 <setlinebuf@plt>
mov    0x2dce(%rip),%r15
mov    (%r15),%edi
call   1080 <setlinebuf@plt>
mov    0x2dc7(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    $0x1a0a,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0xde4(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1090 <memset@plt>
mov    (%rbx),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     1338 <main+0x168>
mov    %eax,%r12d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     1338 <main+0x168>
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%edx
mov    %rbp,%rdi
mov    $0x50,%esi
call   10b0 <fgets@plt>
movzbl 0x10(%rsp),%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xa,%bl
jne    1280 <main+0xb0>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0x4f,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1321 <main+0x151>
lea    0x10(%rsp),%rbx
nop
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1070 <fputs@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x50,%esi
call   10b0 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    -0x1(%rax),%rdx
mov    %r12d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x4f,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     12d0 <main+0x100>
mov    %r12d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stdin = global i32 0
@stdout = global i32 0
@PF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [80 x i8]
store i32 0, i32* %1
store i32 0, i32* %4
%7 = load i32, i32* @stdin
%8 = call i32 @setlinebuf(i32 %7)
%9 = load i32, i32* @stdout
%10 = call i32 @setlinebuf(i32 %9)
%11 = load i32, i32* @PF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 3
store i32 %11, i32* %12
%13 = call i32 @htons(i32 6666)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%19 = call i32 @memset(i32* %18, i8 signext 0, i32 8)
%20 = load i32, i32* @PF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = load i32, i32* @IPPROTO_TCP
%23 = call i32 @socket(i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %2
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %0
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %0
%28 = load i32, i32* %2
%29 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%30 = call i32 @connect(i32 %28, %struct.sockaddr* %29, i32 4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
br label %35
35: ; preds = %54, %34
%36 = load i32, i32* %4
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %55
39: ; preds = %35
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %40, i32 80, i32 %41)
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 10, %45
br i1 %46, label %47, label %48
47: ; preds = %39
store i32 1, i32* %4
br label %54
48: ; preds = %39
%49 = load i32, i32* %2
%50 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%51 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%52 = call i64 @strlen(i8* %51)
%53 = call i32 @send(i32 %49, i8* %50, i64 %52, i32 0)
br label %54
54: ; preds = %48, %47
br label %35
55: ; preds = %35
%56 = load i32, i32* %2
%57 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%59 = call i64 @strlen(i8* %58)
%60 = call i32 @send(i32 %56, i8* %57, i64 %59, i32 0)
br label %61
61: ; preds = %66, %55
%62 = load i32, i32* %2
%63 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%64 = call i32 @recv(i32 %62, i8* %63, i32 79, i32 0)
store i32 %64, i32* %3
%65 = icmp slt i32 0, %64
br i1 %65, label %66, label %82
66: ; preds = %61
%67 = load i32, i32* %3
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 %68
store i8 0, i8* %69
%70 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%71 = load i32, i32* @stdout
%72 = call i32 @fputs(i8* %70, i32 %71)
%73 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%74 = load i32, i32* @stdin
%75 = call i32 @fgets(i8* %73, i32 80, i32 %74)
%76 = load i32, i32* %2
%77 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%78 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%79 = call i64 @strlen(i8* %78)
%80 = sub nsw i64 %79, 1
%81 = call i32 @send(i32 %76, i8* %77, i64 %80, i32 0)
br label %61
82: ; preds = %61
%83 = load i32, i32* %2
%84 = call i32 @close(i32 %83)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stdin = global i32 0
@stdout = global i32 0
@PF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [80 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = tail call i32 @setlinebuf(i32 %5)
%7 = load i32, i32* @stdout
%8 = tail call i32 @setlinebuf(i32 %7)
%9 = load i32, i32* @PF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 6666)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%16 = call i32 @memset(i32* %15, i8 signext 0, i32 8)
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = load i32, i32* @IPPROTO_TCP
%20 = call i32 @socket(i32 %17, i32 %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %0
%25 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%26 = call i32 @connect(i32 %20, %struct.sockaddr* %25, i32 4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %24, %30
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %4, i32 80, i32 %31)
%33 = load i8, i8* %4
%34 = icmp eq i8 %33, 10
%35 = call i64 @strlen(i8* %4)
%36 = call i32 @send(i32 %20, i8* %4, i64 %35, i32 0)
br i1 %34, label %37, label %30
37: ; preds = %30
%38 = call i32 @recv(i32 %20, i8* %4, i32 79, i32 0)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %53
40: ; preds = %37, %40
%41 = phi i32 [ %51, %40 ], [ %38, %37 ]
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %42
store i8 0, i8* %43
%44 = load i32, i32* @stdout
%45 = call i32 @fputs(i8* %4, i32 %44)
%46 = load i32, i32* @stdin
%47 = call i32 @fgets(i8* %4, i32 80, i32 %46)
%48 = call i64 @strlen(i8* %4)
%49 = add nsw i64 %48, -1
%50 = call i32 @send(i32 %20, i8* %4, i64 %49, i32 0)
%51 = call i32 @recv(i32 %20, i8* %4, i32 79, i32 0)
%52 = icmp sgt i32 %51, 0
br i1 %52, label %40, label %53
53: ; preds = %40, %37
%54 = call i32 @close(i32 %20)
ret i32 0
}