#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_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr const *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
size_t read(int /*<<< orphan*/, char *, size_t);
char *realloc(char *, size_t);
size_t recv(int, char *, size_t, int /*<<< orphan*/);
int send(int, char *, size_t, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ write(int /*<<< orphan*/, char *, size_t);
int main() {
  int sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (sock_fd == -1) {
    perror("socket");
    exit(1);
  }
  struct sockaddr_in server;
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  server.sin_port = htons(8080);
  if (connect(sock_fd, (const struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("connect");
    exit(1);
  }
  ssize_t r;
  char *query = (char *)malloc(sizeof(char));
  if (query == NULL) {
    perror(NULL);
    exit(1);
  }
  size_t len_q = 0;
  size_t size_q = 1;
  while ((r = read(0, query + len_q, size_q - len_q)) > 0) {
    if (len_q + r == size_q) {
      char *temp = realloc(query, size_q * 2 * sizeof(char));
      if (temp == NULL) {
        perror("realloc");
        exit(1);
      }
      query = temp;
      size_q = size_q * 2;
    }
    len_q += r;
  }
  int s;
  if ((s = send(sock_fd, query, len_q, 0)) < 0) {
    perror("send");
    exit(1);
  }
  ssize_t answer_r;
  char *answer = (char *)malloc(sizeof(char));
  if (answer == NULL) {
    perror("malloc");
    exit(1);
  }
  size_t len_a = 0;
  size_t size_a = 1;
  while ((answer_r = recv(sock_fd, answer + len_a, size_a - len_a, 0)) > 0) {
    if (len_a + answer_r == size_a) {
      char *temp = realloc(answer, size_a * 2 * sizeof(char));
      if (temp == NULL) {
        perror("realloc");
        exit(1);
      }
      answer = temp;
      size_a *= 2;
    }
    len_a += answer_r;
  }
  if (answer_r < 0) {
    perror("recv");
    exit(1);
  }
  if (write(0, answer, len_a) < 0) {
    perror("write");
    exit(1);
  }
  free(answer);
  free(query);
  if (r < 0) {
    perror("read");
    exit(1);
  }
  close(sock_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    0x2dd8(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1232 <main+0x52>
lea    0xddd(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xdc2(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1f90,%edi
call   1060 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    128b <main+0xab>
lea    0xd95(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12b7 <main+0xd7>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movq   $0x0,-0x30(%rbp)
movq   $0x1,-0x38(%rbp)
mov    -0x28(%rbp),%rsi
add    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
sub    -0x30(%rbp),%rdx
xor    %edi,%edi
call   1090 <read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jbe    135d <main+0x17d>
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    134c <main+0x16c>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
shl    $0x1,%rsi
shl    $0x0,%rsi
call   10c0 <realloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1338 <main+0x158>
lea    0xcf0(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    12c7 <main+0xe7>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jge    1391 <main+0x1b1>
lea    0xc9f(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    $0x1,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    13c0 <main+0x1e0>
lea    0xc75(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movq   $0x0,-0x60(%rbp)
movq   $0x1,-0x68(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x58(%rbp),%rsi
add    -0x60(%rbp),%rsi
mov    -0x68(%rbp),%rdx
sub    -0x60(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jbe    1469 <main+0x289>
mov    -0x60(%rbp),%rax
add    -0x50(%rbp),%rax
cmp    -0x68(%rbp),%rax
jne    1458 <main+0x278>
mov    -0x58(%rbp),%rdi
mov    -0x68(%rbp),%rsi
shl    $0x1,%rsi
shl    $0x0,%rsi
call   10c0 <realloc@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    1444 <main+0x264>
lea    0xbe4(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x70(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x68(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rax
add    -0x60(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    13d0 <main+0x1f0>
cmpq   $0x0,-0x50(%rbp)
jae    148a <main+0x2aa>
lea    0xbb2(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x58(%rbp),%rsi
mov    -0x60(%rbp),%rdx
xor    %edi,%edi
call   1050 <write@plt>
cmp    $0x0,%rax
jge    14b9 <main+0x2d9>
lea    0xb88(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jae    14ec <main+0x30c>
lea    0xb5b(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2df5(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     13ac <main+0x1cc>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xde2(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x1f90,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
js     13b5 <main+0x1d5>
mov    $0x1,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     13be <main+0x1de>
mov    %rax,%r15
xor    %ebx,%ebx
mov    $0x1,%ebp
mov    $0x1,%edx
xor    %edi,%edi
mov    %rax,%rsi
call   1090 <read@plt>
test   %rax,%rax
je     12cf <main+0xef>
xor    %ebx,%ebx
jmp    12a6 <main+0xc6>
nopl   0x0(%rax)
lea    (%r15,%rbx,1),%rsi
mov    %rbp,%rdx
sub    %rbx,%rdx
xor    %edi,%edi
call   1090 <read@plt>
test   %rax,%rax
je     12cf <main+0xef>
mov    %rbx,%rcx
mov    %rax,%rbx
add    %rcx,%rbx
cmp    %rbp,%rbx
jne    1290 <main+0xb0>
add    %rbp,%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   10c0 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1290 <main+0xb0>
jmp    135d <main+0x17d>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
js     13c2 <main+0x1e2>
mov    $0x1,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     13cb <main+0x1eb>
mov    %rax,%r12
mov    $0x1,%ebp
xor    %ebx,%ebx
mov    $0x1,%edx
mov    %r14d,%edi
mov    %rax,%rsi
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %rax,%rax
je     1373 <main+0x193>
xor    %ebx,%ebx
jmp    1339 <main+0x159>
nop
lea    (%r12,%rbx,1),%rsi
mov    %rbp,%rdx
sub    %rbx,%rdx
mov    %r14d,%edi
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %rax,%rax
je     1373 <main+0x193>
mov    %rbx,%rcx
mov    %rax,%rbx
add    %rcx,%rbx
cmp    %rbp,%rbx
jne    1320 <main+0x140>
add    %rbp,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
call   10c0 <realloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1320 <main+0x140>
lea    0xcb5(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <write@plt>
test   %rax,%rax
js     13d4 <main+0x1f4>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc4d(%rip),%rdi
jmp    1364 <main+0x184>
lea    0xc55(%rip),%rdi
jmp    1364 <main+0x184>
xor    %edi,%edi
jmp    1364 <main+0x184>
lea    0xc58(%rip),%rdi
jmp    1364 <main+0x184>
lea    0xc54(%rip),%rdi
jmp    1364 <main+0x184>
lea    0xc52(%rip),%rdi
jmp    1364 <main+0x184>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [8 x i8] c"realloc\00"
@.str.4 = [5 x i8] c"send\00"
@.str.5 = [7 x i8] c"malloc\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [5 x i8] c"read\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
store i32 0, i32* %1
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = load i32, i32* @IPPROTO_TCP
%18 = call i32 @socket(i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %0
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = call i32 @htons(i32 8080)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* %2
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i64 @connect(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %24
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %24
%40 = call i64 @malloc(i32 1)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %5
%42 = load i8*, i8** %5
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = call i32 @perror(i8* null)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %39
store i64 0, i64* %6
store i64 1, i64* %7
br label %48
48: ; preds = %78, %47
%49 = load i8*, i8** %5
%50 = load i64, i64* %6
%51 = getelementptr inbounds i8, i8* %49, i64 %50
%52 = load i64, i64* %7
%53 = load i64, i64* %6
%54 = sub i64 %52, %53
%55 = call i64 @read(i32 0, i8* %51, i64 %54)
store i64 %55, i64* %4
%56 = icmp ugt i64 %55, 0
br i1 %56, label %57, label %82
57: ; preds = %48
%58 = load i64, i64* %6
%59 = load i64, i64* %4
%60 = add i64 %58, %59
%61 = load i64, i64* %7
%62 = icmp eq i64 %60, %61
br i1 %62, label %63, label %78
63: ; preds = %57
%64 = load i8*, i8** %5
%65 = load i64, i64* %7
%66 = mul i64 %65, 2
%67 = mul i64 %66, 1
%68 = call i8* @realloc(i8* %64, i64 %67)
store i8* %68, i8** %8
%69 = load i8*, i8** %8
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %63
%72 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %63
%75 = load i8*, i8** %8
store i8* %75, i8** %5
%76 = load i64, i64* %7
%77 = mul i64 %76, 2
store i64 %77, i64* %7
br label %78
78: ; preds = %74, %57
%79 = load i64, i64* %4
%80 = load i64, i64* %6
%81 = add i64 %80, %79
store i64 %81, i64* %6
br label %48
82: ; preds = %48
%83 = load i32, i32* %2
%84 = load i8*, i8** %5
%85 = load i64, i64* %6
%86 = call i32 @send(i32 %83, i8* %84, i64 %85, i32 0)
store i32 %86, i32* %9
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %82
%89 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %82
%92 = call i64 @malloc(i32 1)
%93 = inttoptr i64 %92 to i8*
store i8* %93, i8** %11
%94 = load i8*, i8** %11
%95 = icmp eq i8* %94, null
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %91
store i64 0, i64* %12
store i64 1, i64* %13
br label %100
100: ; preds = %131, %99
%101 = load i32, i32* %2
%102 = load i8*, i8** %11
%103 = load i64, i64* %12
%104 = getelementptr inbounds i8, i8* %102, i64 %103
%105 = load i64, i64* %13
%106 = load i64, i64* %12
%107 = sub i64 %105, %106
%108 = call i64 @recv(i32 %101, i8* %104, i64 %107, i32 0)
store i64 %108, i64* %10
%109 = icmp ugt i64 %108, 0
br i1 %109, label %110, label %135
110: ; preds = %100
%111 = load i64, i64* %12
%112 = load i64, i64* %10
%113 = add i64 %111, %112
%114 = load i64, i64* %13
%115 = icmp eq i64 %113, %114
br i1 %115, label %116, label %131
116: ; preds = %110
%117 = load i8*, i8** %11
%118 = load i64, i64* %13
%119 = mul i64 %118, 2
%120 = mul i64 %119, 1
%121 = call i8* @realloc(i8* %117, i64 %120)
store i8* %121, i8** %14
%122 = load i8*, i8** %14
%123 = icmp eq i8* %122, null
br i1 %123, label %124, label %127
124: ; preds = %116
%125 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%126 = call i32 @exit(i32 1)
unreachable
127: ; preds = %116
%128 = load i8*, i8** %14
store i8* %128, i8** %11
%129 = load i64, i64* %13
%130 = mul i64 %129, 2
store i64 %130, i64* %13
br label %131
131: ; preds = %127, %110
%132 = load i64, i64* %10
%133 = load i64, i64* %12
%134 = add i64 %133, %132
store i64 %134, i64* %12
br label %100
135: ; preds = %100
%136 = load i64, i64* %10
%137 = icmp ult i64 %136, 0
br i1 %137, label %138, label %141
138: ; preds = %135
%139 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%140 = call i32 @exit(i32 1)
unreachable
141: ; preds = %135
%142 = load i8*, i8** %11
%143 = load i64, i64* %12
%144 = call i64 @write(i32 0, i8* %142, i64 %143)
%145 = icmp slt i64 %144, 0
br i1 %145, label %146, label %149
146: ; preds = %141
%147 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%148 = call i32 @exit(i32 1)
unreachable
149: ; preds = %141
%150 = load i8*, i8** %11
%151 = call i32 @free(i8* %150)
%152 = load i8*, i8** %5
%153 = call i32 @free(i8* %152)
%154 = load i64, i64* %4
%155 = icmp ult i64 %154, 0
br i1 %155, label %156, label %159
156: ; preds = %149
%157 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%158 = call i32 @exit(i32 1)
unreachable
159: ; preds = %149
%160 = load i32, i32* %2
%161 = call i32 @close(i32 %160)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [8 x i8] c"realloc\00"
@.str.4 = [5 x i8] c"send\00"
@.str.5 = [7 x i8] c"malloc\00"
@.str.7 = [6 x i8] c"write\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_STREAM
%4 = load i32, i32* @IPPROTO_TCP
%5 = tail call i32 @socket(i32 %2, i32 %3, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = bitcast %struct.sockaddr_in* %1 to i8*
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 8080)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%19 = call i64 @connect(i32 %5, %struct.sockaddr* %18, i32 12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %10
%22 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %10
%25 = call i64 @malloc(i32 1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 @perror(i8* null)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %24
%31 = inttoptr i64 %25 to i8*
%32 = call i64 @read(i32 0, i8* %31, i64 1)
%33 = icmp eq i64 %32, 0
br i1 %33, label %55, label %34
34: ; preds = %30, %48
%35 = phi i64 [ %53, %48 ], [ %32, %30 ]
%36 = phi i8* [ %50, %48 ], [ %31, %30 ]
%37 = phi i64 [ %39, %48 ], [ 0, %30 ]
%38 = phi i64 [ %49, %48 ], [ 1, %30 ]
%39 = add i64 %35, %37
%40 = icmp eq i64 %39, %38
br i1 %40, label %41, label %48
41: ; preds = %34
%42 = shl i64 %38, 1
%43 = call i8* @realloc(i8* %36, i64 %42)
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %41, %34
%49 = phi i64 [ %38, %34 ], [ %42, %41 ]
%50 = phi i8* [ %36, %34 ], [ %43, %41 ]
%51 = getelementptr inbounds i8, i8* %50, i64 %39
%52 = sub i64 %49, %39
%53 = call i64 @read(i32 0, i8* %51, i64 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %34
55: ; preds = %48, %30
%56 = phi i64 [ 0, %30 ], [ %39, %48 ]
%57 = phi i8* [ %31, %30 ], [ %50, %48 ]
%58 = call i32 @send(i32 %5, i8* %57, i64 %56, i32 0)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %55
%64 = call i64 @malloc(i32 1)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %63
%70 = inttoptr i64 %64 to i8*
%71 = call i64 @recv(i32 %5, i8* %70, i64 1, i32 0)
%72 = icmp eq i64 %71, 0
br i1 %72, label %94, label %73
73: ; preds = %69, %87
%74 = phi i64 [ %92, %87 ], [ %71, %69 ]
%75 = phi i64 [ %89, %87 ], [ 1, %69 ]
%76 = phi i64 [ %78, %87 ], [ 0, %69 ]
%77 = phi i8* [ %88, %87 ], [ %70, %69 ]
%78 = add i64 %74, %76
%79 = icmp eq i64 %78, %75
br i1 %79, label %80, label %87
80: ; preds = %73
%81 = shl i64 %75, 1
%82 = call i8* @realloc(i8* %77, i64 %81)
%83 = icmp eq i8* %82, null
br i1 %83, label %84, label %87
84: ; preds = %80
%85 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %80, %73
%88 = phi i8* [ %77, %73 ], [ %82, %80 ]
%89 = phi i64 [ %75, %73 ], [ %81, %80 ]
%90 = getelementptr inbounds i8, i8* %88, i64 %78
%91 = sub i64 %89, %78
%92 = call i64 @recv(i32 %5, i8* %90, i64 %91, i32 0)
%93 = icmp eq i64 %92, 0
br i1 %93, label %94, label %73
94: ; preds = %87, %69
%95 = phi i8* [ %70, %69 ], [ %88, %87 ]
%96 = phi i64 [ 0, %69 ], [ %78, %87 ]
%97 = call i64 @write(i32 0, i8* %95, i64 %96)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %94
%100 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %94
%103 = call i32 @free(i8* %95)
%104 = call i32 @free(i8* %57)
%105 = call i32 @close(i32 %5)
ret i32 0
}