#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 int /*<<< orphan*/ remoteaddr;
typedef int /*<<< orphan*/ pipe_buf;
typedef int /*<<< orphan*/ cmd_buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ memcmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ show_pipe(char **);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(void) {
  int i;
  int fd;
  int len;
  int ret;
  char pipe_buf[512];
  char cmd_buf[128];
  struct sockaddr_in remoteaddr;
  fd = socket(AF_INET, SOCK_STREAM, 0);
  if (fd == -1) {
    fprintf(stderr, "socket error, error code is %d.\n", -errno);
    goto exit;
  }
  printf("[%s:%d]"
         ""
         "socket %d\n",
         "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/troyseed/Test/refs/heads/master/Customer/"
         "socket.c",
         36, fd);
  remoteaddr.sin_family = AF_INET;
  remoteaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  remoteaddr.sin_port = htons(5001);
  len = sizeof(remoteaddr);
  ret = connect(fd, (struct sockaddr *)&remoteaddr, len);
  if (ret == -1) {
    fprintf(stderr, "connect error, error code is %d.\n", -errno);
    goto exit;
  }
  while (recv(fd, cmd_buf, sizeof(cmd_buf), 0) != -1) {
    if (0 == memcmp(cmd_buf, "CONNECT_OK", strlen("CONNECT_OK"))) {
      printf("conncet successfully.\n");
      break;
    } else if (0 == memcmp(cmd_buf, "CONNECT_NG", strlen("CONNECT_NG"))) {
      printf("conncet refused.\n");
      goto exit_close;
    } else
      continue;
  }
  while (1) {
    memset(cmd_buf, 0, sizeof(cmd_buf));
    memset(pipe_buf, 0, sizeof(pipe_buf));
    ret = send(fd, "pwd", 4, 0);
    if (ret == -1) {
      fprintf(stderr, "send error, error code is %d.\n", -errno);
      printf("[%s:%d]"
             ""
             "Send Cmd Err\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/troyseed/Test/refs/heads/master/"
             "Customer/socket.c",
             72);
      goto exit_close;
    }
    ret = recv(fd, pipe_buf, sizeof(pipe_buf), 0);
    if (ret == -1) {
      fprintf(stderr, "recv error, error code is %d.\n", -errno);
      printf("[%s:%d]"
             ""
             "Recv Respose Err\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/troyseed/Test/refs/heads/master/"
             "Customer/socket.c",
             79);
      break;
    }
    printf("Remote:");
    for (i = 0; i < sizeof(pipe_buf); i++) {
      if ('\n' == pipe_buf[i])
        break;
      putchar(pipe_buf[i]);
    }
    printf("$: ");
    memset(cmd_buf, 0, sizeof(cmd_buf));
    memset(pipe_buf, 0, sizeof(pipe_buf));
    gets(cmd_buf);
    ret = send(fd, cmd_buf, sizeof(cmd_buf), 0);
    if (ret == -1) {
      fprintf(stderr, "send error, error code is %d.\n", -errno);
      printf("[%s:%d]"
             ""
             "Send Cmd Err\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/troyseed/Test/refs/heads/master/"
             "Customer/socket.c",
             96);
      goto exit_close;
    }
    ret = strcmp(cmd_buf, "exit");
    if (0 == ret) {
      printf("[%s:%d]"
             ""
             "Exit\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/troyseed/Test/refs/heads/master/"
             "Customer/socket.c",
             101);
      goto exit_close;
    }
    ret = recv(fd, pipe_buf, sizeof(pipe_buf), 0);
    if (ret == -1) {
      printf("[%s:%d]"
             ""
             "Recv Respose Err\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/troyseed/Test/refs/heads/master/"
             "Customer/socket.c",
             107);
      fprintf(stderr, "recv error, error code is %d.\n", -errno);
      break;
    }
    show_pipe(&pipe_buf);
    printf("\n");
  }
exit_close:
  close(fd);
exit:
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    125d <main+0x5d>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
xor    %edx,%edx
mov    0x2d7e(%rip),%rax
sub    (%rax),%edx
lea    0xdad(%rip),%rsi
call   10f0 <fprintf@plt>
jmp    1680 <main+0x480>
mov    -0xc(%rbp),%ecx
lea    0xdba(%rip),%rdi
lea    0xdc5(%rip),%rsi
mov    $0x24,%edx
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2a8(%rbp)
lea    0xe2f(%rip),%rdi
call   10d0 <inet_addr@plt>
mov    %eax,-0x2ac(%rbp)
mov    $0x1389,%edi
call   1070 <htons@plt>
mov    %eax,-0x2b0(%rbp)
movl   $0xc,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x2b0(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1110 <connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12f6 <main+0xf6>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
xor    %edx,%edx
mov    0x2ce5(%rip),%rax
sub    (%rax),%edx
lea    0xddd(%rip),%rsi
call   10f0 <fprintf@plt>
jmp    1680 <main+0x480>
jmp    12fb <main+0xfb>
mov    -0xc(%rbp),%edi
lea    -0x2a0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
je     13bf <main+0x1bf>
lea    -0x2a0(%rbp),%rax
mov    %rax,-0x2b8(%rbp)
lea    0xdbc(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x2b8(%rbp),%rdi
mov    %eax,%edx
lea    0xda7(%rip),%rsi
call   10c0 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    136a <main+0x16a>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    13bf <main+0x1bf>
lea    -0x2a0(%rbp),%rax
mov    %rax,-0x2c0(%rbp)
lea    0xd8e(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x2c0(%rbp),%rdi
mov    %eax,%edx
lea    0xd79(%rip),%rsi
call   10c0 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    13ba <main+0x1ba>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1678 <main+0x478>
jmp    12fb <main+0xfb>
jmp    13c4 <main+0x1c4>
lea    -0x2a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10a0 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   10a0 <memset@plt>
mov    -0xc(%rbp),%edi
lea    0xd36(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    144c <main+0x24c>
mov    0x2bc4(%rip),%rax
mov    (%rax),%edi
xor    %edx,%edx
mov    0x2ba9(%rip),%rax
sub    (%rax),%edx
lea    0xd06(%rip),%rsi
call   10f0 <fprintf@plt>
lea    0xd19(%rip),%rdi
lea    0xbf8(%rip),%rsi
mov    $0x48,%edx
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1678 <main+0x478>
mov    -0xc(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    14ae <main+0x2ae>
mov    0x2b62(%rip),%rax
mov    (%rax),%edi
xor    %edx,%edx
mov    0x2b47(%rip),%rax
sub    (%rax),%edx
lea    0xcd8(%rip),%rsi
call   10f0 <fprintf@plt>
lea    0xceb(%rip),%rdi
lea    0xb96(%rip),%rsi
mov    $0x4f,%edx
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1673 <main+0x473>
lea    0xce5(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmp    $0x200,%rax
jae    1510 <main+0x310>
movslq -0x8(%rbp),%rax
movsbl -0x220(%rbp,%rax,1),%ecx
ff
mov    $0xa,%eax
cmp    %ecx,%eax
jne    14f1 <main+0x2f1>
jmp    1510 <main+0x310>
movslq -0x8(%rbp),%rax
movsbl -0x220(%rbp,%rax,1),%edi
ff
call   1050 <putchar@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    14c3 <main+0x2c3>
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x2a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10a0 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   10a0 <memset@plt>
lea    -0x2a0(%rbp),%rdi
call   1100 <gets@plt>
mov    -0xc(%rbp),%edi
lea    -0x2a0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    15b2 <main+0x3b2>
mov    0x2a5e(%rip),%rax
mov    (%rax),%edi
xor    %edx,%edx
mov    0x2a43(%rip),%rax
sub    (%rax),%edx
lea    0xba0(%rip),%rsi
call   10f0 <fprintf@plt>
lea    0xbb3(%rip),%rdi
lea    0xa92(%rip),%rsi
mov    $0x60,%edx
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1678 <main+0x478>
lea    -0x2a0(%rbp),%rdi
lea    0xbe6(%rip),%rsi
call   10e0 <strcmp@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    15f2 <main+0x3f2>
lea    0xbd1(%rip),%rdi
lea    0xa52(%rip),%rsi
mov    $0x65,%edx
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1678 <main+0x478>
mov    -0xc(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1654 <main+0x454>
lea    0xb65(%rip),%rdi
lea    0xa10(%rip),%rsi
mov    $0x6b,%edx
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x29a2(%rip),%rax
mov    (%rax),%edi
xor    %edx,%edx
mov    0x2987(%rip),%rax
sub    (%rax),%edx
lea    0xb18(%rip),%rsi
call   10f0 <fprintf@plt>
jmp    1673 <main+0x473>
lea    -0x220(%rbp),%rdi
call   1030 <show_pipe@plt>
lea    0xae4(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    13c4 <main+0x1c4>
jmp    1678 <main+0x478>
mov    -0xc(%rbp),%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x2c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x298,%rsp
mov    0x2dd0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     1310 <main+0x110>
mov    %eax,%r15d
lea    0xde1(%rip),%rdi
lea    0xdec(%rip),%rsi
xor    %ebx,%ebx
mov    $0x24,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
lea    0xe5a(%rip),%rdi
call   10e0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x1389,%edi
call   1080 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
je     132b <main+0x12b>
lea    0x10(%rsp),%rbp
lea    0xe4b(%rip),%rbx
lea    0xe4f(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
je     135c <main+0x15c>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10d0 <memcmp@plt>
test   %rax,%rax
je     1350 <main+0x150>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   10d0 <memcmp@plt>
test   %rax,%rax
jne    12b0 <main+0xb0>
lea    0xe89(%rip),%rdi
call   1060 <puts@plt>
jmp    159b <main+0x39b>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
mov    0x2ca8(%rip),%rax
sub    (%rax),%ebx
lea    0xcd7(%rip),%rsi
jmp    1344 <main+0x144>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
mov    0x2c8d(%rip),%rax
sub    (%rax),%ebx
lea    0xd85(%rip),%rsi
mov    %ebx,%edx
call   10f0 <fprintf@plt>
jmp    15a3 <main+0x3a3>
lea    0xe49(%rip),%rdi
call   1060 <puts@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10b0 <memset@plt>
lea    0x90(%rsp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   10b0 <memset@plt>
lea    0xd79(%rip),%rsi
mov    %r15d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
je     14e2 <main+0x2e2>
lea    0x90(%rsp),%r14
lea    0xdc2(%rip),%rbx
lea    0xdc3(%rip),%r12
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
je     1517 <main+0x317>
mov    %rbx,%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl 0x90(%rsp,%rbp,1),%eax
cmp    $0xa,%al
je     1411 <main+0x211>
movsbl %al,%edi
call   1050 <putchar@plt>
add    $0x1,%rbp
cmp    $0x200,%rbp
jne    13f0 <main+0x1f0>
mov    %r12,%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10b0 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   10b0 <memset@plt>
mov    %r13,%rdi
call   1100 <gets@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
je     154c <main+0x34c>
mov    $0x5,%edx
mov    %r13,%rdi
lea    0xd12(%rip),%rsi
call   10d0 <memcmp@plt>
test   %eax,%eax
je     1581 <main+0x381>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
cmp    $0xffffffff,%eax
je     15b7 <main+0x3b7>
mov    %r14,%rdi
call   1030 <show_pipe@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10b0 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   10b0 <memset@plt>
mov    %r15d,%edi
lea    0xc34(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
cmp    $0xffffffff,%eax
jne    13c0 <main+0x1c0>
mov    0x2aef(%rip),%rax
mov    (%rax),%edi
mov    0x2ad6(%rip),%rax
xor    %edx,%edx
sub    (%rax),%edx
lea    0xc08(%rip),%rsi
call   10f0 <fprintf@plt>
lea    0xc1b(%rip),%rdi
lea    0xb23(%rip),%rsi
mov    $0x48,%edx
jmp    1594 <main+0x394>
mov    0x2aba(%rip),%rax
mov    (%rax),%edi
mov    0x2aa1(%rip),%rax
xor    %edx,%edx
sub    (%rax),%edx
lea    0xc07(%rip),%rsi
call   10f0 <fprintf@plt>
lea    0xc1a(%rip),%rdi
lea    0xaee(%rip),%rsi
mov    $0x4f,%edx
jmp    1594 <main+0x394>
mov    0x2a85(%rip),%rax
mov    (%rax),%edi
mov    0x2a6c(%rip),%rax
xor    %edx,%edx
sub    (%rax),%edx
lea    0xb9e(%rip),%rsi
call   10f0 <fprintf@plt>
lea    0xbb1(%rip),%rdi
lea    0xab9(%rip),%rsi
mov    $0x60,%edx
jmp    1594 <main+0x394>
lea    0xbfa(%rip),%rdi
lea    0xaa4(%rip),%rsi
mov    $0x65,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r15d,%edi
call   10c0 <close@plt>
xor    %eax,%eax
add    $0x298,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb9a(%rip),%rdi
lea    0xa6e(%rip),%rsi
xor    %ebx,%ebx
mov    $0x6b,%edx
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x29fe(%rip),%rax
mov    (%rax),%edi
mov    0x29e5(%rip),%rax
sub    (%rax),%ebx
lea    0xb4d(%rip),%rsi
mov    %ebx,%edx
call   10f0 <fprintf@plt>
jmp    159b <main+0x39b>

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
@stderr = global i32 0
@.str = [33 x i8] c"socket error, error code is %d.\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"[%s:%d]socket %d\0A\00"
@.str.2 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/troyseed/Test/refs/heads/master/Customer/socket.c\00"
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [34 x i8] c"connect error, error code is %d.\0A\00"
@.str.5 = [11 x i8] c"CONNECT_OK\00"
@.str.6 = [23 x i8] c"conncet successfully.\0A\00"
@.str.7 = [11 x i8] c"CONNECT_NG\00"
@.str.8 = [18 x i8] c"conncet refused.\0A\00"
@.str.9 = [4 x i8] c"pwd\00"
@.str.10 = [31 x i8] c"send error, error code is %d.\0A\00"
@.str.11 = [21 x i8] c"[%s:%d]Send Cmd Err\0A\00"
@.str.12 = [31 x i8] c"recv error, error code is %d.\0A\00"
@.str.13 = [25 x i8] c"[%s:%d]Recv Respose Err\0A\00"
@.str.14 = [8 x i8] c"Remote:\00"
@.str.15 = [4 x i8] c"$: \00"
@.str.16 = [5 x i8] c"exit\00"
@.str.17 = [13 x i8] c"[%s:%d]Exit\0A\00"
@.str.18 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca [128 x i8]
%8 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = sub nsw i32 0, %16
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %158
19: ; preds = %0
%20 = load i32, i32* %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 36, i32 %20)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = call i32 @htons(i32 5001)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %27, i32* %28
store i32 12, i32* %4
%29 = load i32, i32* %3
%30 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%31 = load i32, i32* %4
%32 = call i32 @connect(i32 %29, %struct.sockaddr* %30, i32 %31)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %19
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = sub nsw i32 0, %37
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %158
40: ; preds = %19
br label %41
41: ; preds = %60, %40
%42 = load i32, i32* %3
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%44 = call i32 @recv(i32 %42, i8* %43, i32 128, i32 0)
%45 = icmp ne i32 %44, -1
br i1 %45, label %46, label %61
46: ; preds = %41
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%48 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%49 = call i64 @memcmp(i8* %47, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %48)
%50 = icmp eq i64 0, %49
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %61
53: ; preds = %46
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%55 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%56 = call i64 @memcmp(i8* %54, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 %55)
%57 = icmp eq i64 0, %56
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %155
60: ; preds = %53
br label %41
61: ; preds = %51, %41
br label %62
62: ; preds = %61, %150
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%64 = call i32 @memset(i8* %63, i32 0, i32 128)
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%66 = call i32 @memset(i8* %65, i32 0, i32 512)
%67 = load i32, i32* %3
%68 = call i32 @send(i32 %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 4, i32 0)
store i32 %68, i32* %5
%69 = load i32, i32* %5
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %77
71: ; preds = %62
%72 = load i32, i32* @stderr
%73 = load i32, i32* @errno
%74 = sub nsw i32 0, %73
%75 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 %74)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 72)
br label %155
77: ; preds = %62
%78 = load i32, i32* %3
%79 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%80 = call i32 @recv(i32 %78, i8* %79, i32 512, i32 0)
store i32 %80, i32* %5
%81 = load i32, i32* %5
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %89
83: ; preds = %77
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = sub nsw i32 0, %85
%87 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 79)
br label %154
89: ; preds = %77
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %2
br label %91
91: ; preds = %109, %89
%92 = load i32, i32* %2
%93 = sext i32 %92 to i64
%94 = icmp ult i64 %93, 512
br i1 %94, label %95, label %112
95: ; preds = %91
%96 = load i32, i32* %2
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %97
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = icmp eq i32 10, %100
br i1 %101, label %102, label %103
102: ; preds = %95
br label %112
103: ; preds = %95
%104 = load i32, i32* %2
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %105
%107 = load i8, i8* %106
%108 = call i32 @putchar(i8 signext %107)
br label %109
109: ; preds = %103
%110 = load i32, i32* %2
%111 = add nsw i32 %110, 1
store i32 %111, i32* %2
br label %91
112: ; preds = %102, %91
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0))
%114 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%115 = call i32 @memset(i8* %114, i32 0, i32 128)
%116 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%117 = call i32 @memset(i8* %116, i32 0, i32 512)
%118 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%119 = call i32 @gets(i8* %118)
%120 = load i32, i32* %3
%121 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%122 = call i32 @send(i32 %120, i8* %121, i32 128, i32 0)
store i32 %122, i32* %5
%123 = load i32, i32* %5
%124 = icmp eq i32 %123, -1
br i1 %124, label %125, label %131
125: ; preds = %112
%126 = load i32, i32* @stderr
%127 = load i32, i32* @errno
%128 = sub nsw i32 0, %127
%129 = call i32 @fprintf(i32 %126, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 %128)
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 96)
br label %155
131: ; preds = %112
%132 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%133 = call i32 @strcmp(i8* %132, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.16, i64 0, i64 0))
store i32 %133, i32* %5
%134 = load i32, i32* %5
%135 = icmp eq i32 0, %134
br i1 %135, label %136, label %138
136: ; preds = %131
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 101)
br label %155
138: ; preds = %131
%139 = load i32, i32* %3
%140 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%141 = call i32 @recv(i32 %139, i8* %140, i32 512, i32 0)
store i32 %141, i32* %5
%142 = load i32, i32* %5
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %150
144: ; preds = %138
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 107)
%146 = load i32, i32* @stderr
%147 = load i32, i32* @errno
%148 = sub nsw i32 0, %147
%149 = call i32 @fprintf(i32 %146, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i32 %148)
br label %154
150: ; preds = %138
%151 = bitcast [512 x i8]* %6 to i8**
%152 = call i32 @show_pipe(i8** %151)
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.18, i64 0, i64 0))
br label %62
154: ; preds = %144, %83
br label %155
155: ; preds = %154, %136, %125, %71, %58
%156 = load i32, i32* %3
%157 = call i32 @close(i32 %156)
br label %158
158: ; preds = %155, %35, %14
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
@stderr = global i32 0
@.str = [33 x i8] c"socket error, error code is %d.\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"[%s:%d]socket %d\0A\00"
@.str.2 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/troyseed/Test/refs/heads/master/Customer/socket.c\00"
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [34 x i8] c"connect error, error code is %d.\0A\00"
@.str.5 = [11 x i8] c"CONNECT_OK\00"
@.str.7 = [11 x i8] c"CONNECT_NG\00"
@.str.9 = [4 x i8] c"pwd\00"
@.str.10 = [31 x i8] c"send error, error code is %d.\0A\00"
@.str.11 = [21 x i8] c"[%s:%d]Send Cmd Err\0A\00"
@.str.12 = [31 x i8] c"recv error, error code is %d.\0A\00"
@.str.13 = [25 x i8] c"[%s:%d]Recv Respose Err\0A\00"
@.str.14 = [8 x i8] c"Remote:\00"
@.str.15 = [4 x i8] c"$: \00"
@.str.16 = [5 x i8] c"exit\00"
@.str.17 = [13 x i8] c"[%s:%d]Exit\0A\00"
@str = [17 x i8] c"conncet refused.\00"
@str.19 = [22 x i8] c"conncet successfully.\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = alloca [128 x i8]
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = sub nsw i32 0, %13
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %116
16: ; preds = %0
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 36, i32 %9)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 5001)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @connect(i32 %9, %struct.sockaddr* %24, i32 12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %32
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = sub nsw i32 0, %29
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %116
32: ; preds = %16, %41
%33 = call i32 @recv(i32 %9, i8* %5, i32 128, i32 0)
%34 = icmp eq i32 %33, -1
br i1 %34, label %47, label %35
35: ; preds = %32
%36 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%37 = call i64 @memcmp(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.19, i64 0, i64 0))
br label %47
41: ; preds = %35
%42 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%43 = call i64 @memcmp(i8* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %32
45: ; preds = %41
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %114
47: ; preds = %32, %39
%48 = call i32 @memset(i8* %5, i32 0, i32 128)
%49 = call i32 @memset(i8* %4, i32 0, i32 512)
%50 = call i32 @send(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 4, i32 0)
%51 = icmp eq i32 %50, -1
br i1 %51, label %54, label %52
52: ; preds = %47
%53 = bitcast [512 x i8]* %1 to i8**
br label %60
54: ; preds = %107, %47
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = sub nsw i32 0, %56
%58 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 72)
br label %114
60: ; preds = %52, %107
%61 = call i32 @recv(i32 %9, i8* %4, i32 512, i32 0)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %69
63: ; preds = %60
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = sub nsw i32 0, %65
%67 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i32 %66)
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 79)
br label %114
69: ; preds = %60
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
br label %71
71: ; preds = %69, %76
%72 = phi i64 [ 0, %69 ], [ %78, %76 ]
%73 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 %72
%74 = load i8, i8* %73
%75 = icmp eq i8 %74, 10
br i1 %75, label %80, label %76
76: ; preds = %71
%77 = call i32 @putchar(i8 signext %74)
%78 = add nuw nsw i64 %72, 1
%79 = icmp eq i64 %78, 512
br i1 %79, label %80, label %71
80: ; preds = %71, %76
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.15, i64 0, i64 0))
%82 = call i32 @memset(i8* %5, i32 0, i32 128)
%83 = call i32 @memset(i8* %4, i32 0, i32 512)
%84 = call i32 @gets(i8* %5)
%85 = call i32 @send(i32 %9, i8* %5, i32 128, i32 0)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %93
87: ; preds = %80
%88 = load i32, i32* @stderr
%89 = load i32, i32* @errno
%90 = sub nsw i32 0, %89
%91 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 %90)
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 96)
br label %114
93: ; preds = %80
%94 = call i32 bitcast (i64 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.16, i64 0, i64 0), i64 5)
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %93
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 101)
br label %114
98: ; preds = %93
%99 = call i32 @recv(i32 %9, i8* %4, i32 512, i32 0)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %107
101: ; preds = %98
%102 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.2, i64 0, i64 0), i32 107)
%103 = load i32, i32* @stderr
%104 = load i32, i32* @errno
%105 = sub nsw i32 0, %104
%106 = call i32 @fprintf(i32 %103, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), i32 %105)
br label %114
107: ; preds = %98
%108 = call i32 @show_pipe(i8** %53)
%109 = call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
%110 = call i32 @memset(i8* %5, i32 0, i32 128)
%111 = call i32 @memset(i8* %4, i32 0, i32 512)
%112 = call i32 @send(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 4, i32 0)
%113 = icmp eq i32 %112, -1
br i1 %113, label %54, label %60
114: ; preds = %63, %101, %96, %87, %54, %45
%115 = call i32 @close(i32 %9)
br label %116
116: ; preds = %114, %27, %11
ret i32 0
}