#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 */
typedef int /*<<< orphan*/ target_addr;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ *h_addr_list;
};
typedef int /*<<< orphan*/ in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, ...);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(void) {
  int soc;
  struct sockaddr_in target_addr;
  char hostname[256];
  int port;
  struct hostent *host;
  char input_buf[256];
  int exit_flg = 0;
  int input_len;
  char recv_buf[256];
  int recv_len;
  char tmp;
  int send_len;
  printf("hostname: ");
  scanf("%s", hostname);
  printf("port: ");
  scanf("%d", &port);
  scanf("%*c", tmp);
  host = gethostbyname(hostname);
  if (host == NULL) {
    printf("gethostbyname error!\n");
    return -1;
  }
  soc = socket(AF_INET, SOCK_STREAM, 0);
  if (soc == -1) {
    printf("socket error!\n");
    return -1;
  }
  target_addr.sin_family = AF_INET;
  target_addr.sin_port = htons(port);
  target_addr.sin_addr.s_addr = *(in_addr_t *)host->h_addr_list[0];
  if (connect(soc, (struct sockaddr *)&target_addr, sizeof(target_addr)) ==
      -1) {
    printf("connect error!\n");
    close(soc);
    return -1;
  }
  printf("connect success.\n");
  while (!exit_flg) {
    memset(input_buf, 0, sizeof(char) * 256);
    fputs(">", stdout);
    fgets(input_buf, 256, stdin);
    input_len = strlen(input_buf);
    if (input_buf[input_len - 1] == '\n') {
      input_buf[input_len - 1] = '\0';
      input_len = strlen(input_buf);
    }
    if (strcmp(input_buf, "fin") == 0) {
      exit_flg = 1;
    } else {
      input_buf[input_len] = '\r';
      input_buf[input_len + 1] = '\n';
      send_len = send(soc, input_buf, input_len + 2, 0);
      if (send_len <= 0) {
        break;
      }
      recv_len = recv(soc, recv_buf, sizeof(char) * 256, 0);
      if (recv_len <= 0) {
        break;
      }
      recv_buf[recv_len - 1] = '\0';
      recv_buf[recv_len - 2] = '\0';
      printf("%s\n", recv_buf);
    }
  }
  close(soc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x234(%rbp)
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   10e0 <scanf@plt>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xde1(%rip),%rdi
lea    -0x124(%rbp),%rsi
mov    $0x0,%al
call   10e0 <scanf@plt>
movsbl -0x345(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   10e0 <scanf@plt>
lea    -0x120(%rbp),%rdi
call   10d0 <gethostbyname@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    1292 <main+0xb2>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f3 <main+0x313>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    12d2 <main+0xf2>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f3 <main+0x313>
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x124(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    -0x130(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0xffffffff,%eax
jne    133a <main+0x15a>
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14f3 <main+0x313>
lea    0xd10(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x234(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1361 <main+0x181>
jmp    14e4 <main+0x304>
lea    -0x230(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
mov    0x2c4d(%rip),%rax
mov    (%rax),%esi
lea    0xcdf(%rip),%rdi
call   1080 <fputs@plt>
lea    -0x230(%rbp),%rdi
mov    0x2c49(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   10b0 <fgets@plt>
lea    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x238(%rbp)
mov    -0x238(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x230(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    13f6 <main+0x216>
mov    -0x238(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x230(%rbp,%rax,1)
lea    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x238(%rbp)
lea    -0x230(%rbp),%rdi
lea    0xc61(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1422 <main+0x242>
movl   $0x1,-0x234(%rbp)
jmp    14df <main+0x2ff>
movslq -0x238(%rbp),%rax
movb   $0xd,-0x230(%rbp,%rax,1)
0d
mov    -0x238(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0xa,-0x230(%rbp,%rax,1)
0a
mov    -0x8(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x238(%rbp),%edx
add    $0x2,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x34c(%rbp)
cmpl   $0x0,-0x34c(%rbp)
jg     1476 <main+0x296>
jmp    14e4 <main+0x304>
mov    -0x8(%rbp),%edi
lea    -0x340(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x344(%rbp)
cmpl   $0x0,-0x344(%rbp)
jg     14a4 <main+0x2c4>
jmp    14e4 <main+0x304>
mov    -0x344(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x340(%rbp,%rax,1)
mov    -0x344(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0x340(%rbp,%rax,1)
lea    -0x340(%rbp),%rsi
lea    0xb91(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1348 <main+0x168>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x328,%rsp
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdf5(%rip),%rdi
lea    0x220(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   10f0 <scanf@plt>
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdd8(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   10f0 <scanf@plt>
lea    0xdc8(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   10f0 <scanf@plt>
mov    %rbx,%rdi
call   10e0 <gethostbyname@plt>
test   %rax,%rax
je     13bc <main+0x1cc>
mov    %rax,%rbx
mov    0x2d74(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
je     13d1 <main+0x1e1>
mov    %eax,%r13d
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0xc(%rsp),%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%rbx),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0xc,%edx
call   1100 <connect@plt>
cmp    $0xffffffff,%eax
je     13df <main+0x1ef>
lea    0xd4d(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rbx
lea    0xd36(%rip),%r14
lea    0xd31(%rip),%r15
lea    0x120(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   10a0 <memset@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1090 <fputs@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1358 <main+0x168>
movb   $0x0,0x1f(%rsp,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     13c5 <main+0x1d5>
movslq %ebp,%rdx
movw   $0xa0d,0x20(%rsp,%rdx,1)
add    $0x2,%edx
mov    %r13d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1070 <send@plt>
test   %eax,%eax
jle    13c5 <main+0x1d5>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    13c5 <main+0x1d5>
lea    -0x1(%rax),%ecx
movb   $0x0,0x120(%rsp,%rcx,1)
cltq
movb   $0x0,-0x2(%rax,%r12,1)
mov    %r12,%rdi
call   1040 <puts@plt>
jmp    1300 <main+0x110>
lea    0xc8d(%rip),%rdi
jmp    13d8 <main+0x1e8>
mov    %r13d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
jmp    13f8 <main+0x208>
lea    0xc6a(%rip),%rdi
call   1040 <puts@plt>
jmp    13f3 <main+0x203>
lea    0xc4d(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
call   10b0 <close@plt>
mov    $0xffffffff,%eax
add    $0x328,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64* }
%struct.sockaddr = type { i32 }
@.str = [11 x i8] c"hostname: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"port: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"%*c\00"
@.str.5 = [22 x i8] c"gethostbyname error!\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.6 = [15 x i8] c"socket error!\0A\00"
@.str.7 = [16 x i8] c"connect error!\0A\00"
@.str.8 = [18 x i8] c"connect success.\0A\00"
@.str.9 = [2 x i8] c">\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.10 = [4 x i8] c"fin\00"
@.str.11 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca %struct.hostent*
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca i8
%13 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%19 = load i8, i8* %12
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %6
%24 = load %struct.hostent*, %struct.hostent** %6
%25 = icmp eq %struct.hostent* %24, null
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %132
28: ; preds = %0
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %2
%32 = load i32, i32* %2
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %132
36: ; preds = %28
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %37, i32* %38
%39 = load i32, i32* %5
%40 = call i32 @htons(i32 %39)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %40, i32* %41
%42 = load %struct.hostent*, %struct.hostent** %6
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %42, i32 0, i32 0
%44 = load i64*, i64** %43
%45 = getelementptr inbounds i64, i64* %44, i64 0
%46 = load i64, i64* %45
%47 = inttoptr i64 %46 to i32*
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 0
store i32 %48, i32* %50
%51 = load i32, i32* %2
%52 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%53 = call i32 @connect(i32 %51, %struct.sockaddr* %52, i32 12)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %36
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%57 = load i32, i32* %2
%58 = call i32 @close(i32 %57)
store i32 -1, i32* %1
br label %132
59: ; preds = %36
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %61
61: ; preds = %128, %59
%62 = load i32, i32* %8
%63 = icmp ne i32 %62, 0
%64 = xor i1 %63, true
br i1 %64, label %65, label %129
65: ; preds = %61
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%67 = call i32 @memset(i8* %66, i32 0, i32 256)
%68 = load i32, i32* @stdout
%69 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%71 = load i32, i32* @stdin
%72 = call i32 @fgets(i8* %70, i32 256, i32 %71)
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%74 = call i32 @strlen(i8* %73)
store i32 %74, i32* %9
%75 = load i32, i32* %9
%76 = sub nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 10
br i1 %81, label %82, label %89
82: ; preds = %65
%83 = load i32, i32* %9
%84 = sub nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %85
store i8 0, i8* %86
%87 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%88 = call i32 @strlen(i8* %87)
store i32 %88, i32* %9
br label %89
89: ; preds = %82, %65
%90 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%91 = call i64 @strcmp(i8* %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %89
store i32 1, i32* %8
br label %128
94: ; preds = %89
%95 = load i32, i32* %9
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %96
store i8 13, i8* %97
%98 = load i32, i32* %9
%99 = add nsw i32 %98, 1
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %100
store i8 10, i8* %101
%102 = load i32, i32* %2
%103 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%104 = load i32, i32* %9
%105 = add nsw i32 %104, 2
%106 = call i32 @send(i32 %102, i8* %103, i32 %105, i32 0)
store i32 %106, i32* %13
%107 = load i32, i32* %13
%108 = icmp sle i32 %107, 0
br i1 %108, label %109, label %110
109: ; preds = %94
br label %129
110: ; preds = %94
%111 = load i32, i32* %2
%112 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%113 = call i32 @recv(i32 %111, i8* %112, i32 256, i32 0)
store i32 %113, i32* %11
%114 = load i32, i32* %11
%115 = icmp sle i32 %114, 0
br i1 %115, label %116, label %117
116: ; preds = %110
br label %129
117: ; preds = %110
%118 = load i32, i32* %11
%119 = sub nsw i32 %118, 1
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %120
store i8 0, i8* %121
%122 = load i32, i32* %11
%123 = sub nsw i32 %122, 2
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %124
store i8 0, i8* %125
%126 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %126)
br label %128
128: ; preds = %117, %93
br label %61
129: ; preds = %116, %109, %61
%130 = load i32, i32* %2
%131 = call i32 @close(i32 %130)
store i32 0, i32* %1
br label %132
132: ; preds = %129, %55, %34, %26
%133 = load i32, i32* %1
ret i32 %133
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64* }
%struct.sockaddr = type { i32 }
@.str = [11 x i8] c"hostname: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"port: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"%*c\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.9 = [2 x i8] c">\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.10 = [4 x i8] c"fin\00"
@str = [17 x i8] c"connect success.\00"
@str.12 = [15 x i8] c"connect error!\00"
@str.13 = [14 x i8] c"socket error!\00"
@str.14 = [21 x i8] c"gethostbyname error!\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 0)
%16 = call %struct.hostent* @gethostbyname(i8* %7)
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.14, i64 0, i64 0))
br label %87
20: ; preds = %0
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.13, i64 0, i64 0))
br label %87
27: ; preds = %20
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %28, i32* %29
%30 = load i32, i32* %3
%31 = call i32 @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 0
%34 = load i64*, i64** %33
%35 = load i64, i64* %34
%36 = inttoptr i64 %35 to i32*
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %37, i32* %38
%39 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%40 = call i32 @connect(i32 %23, %struct.sockaddr* %39, i32 12)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %27
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
%44 = call i32 @close(i32 %23)
br label %87
45: ; preds = %27
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %77, %45
%48 = call i32 @memset(i8* %9, i32 0, i32 256)
%49 = load i32, i32* @stdout
%50 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 %49)
%51 = load i32, i32* @stdin
%52 = call i32 @fgets(i8* %9, i32 256, i32 %51)
%53 = call i32 @strlen(i8* %9)
%54 = add nsw i32 %53, -1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 10
br i1 %58, label %59, label %61
59: ; preds = %47
store i8 0, i8* %56
%60 = call i32 @strlen(i8* %9)
br label %61
61: ; preds = %59, %47
%62 = phi i32 [ %60, %59 ], [ %53, %47 ]
%63 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%64 = icmp eq i64 %63, 0
br i1 %64, label %85, label %65
65: ; preds = %61
%66 = sext i32 %62 to i64
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %66
store i8 13, i8* %67
%68 = add nsw i32 %62, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %69
store i8 10, i8* %70
%71 = add nsw i32 %62, 2
%72 = call i32 @send(i32 %23, i8* %9, i32 %71, i32 0)
%73 = icmp slt i32 %72, 1
br i1 %73, label %85, label %74
74: ; preds = %65
%75 = call i32 @recv(i32 %23, i8* %10, i32 256, i32 0)
%76 = icmp slt i32 %75, 1
br i1 %76, label %85, label %77
77: ; preds = %74
%78 = add nsw i32 %75, -1
%79 = zext i32 %78 to i64
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %79
store i8 0, i8* %80
%81 = add nsw i32 %75, -2
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %82
store i8 0, i8* %83
%84 = call i32 @puts(i8* %10)
br label %47
85: ; preds = %61, %74, %65
%86 = call i32 @close(i32 %23)
br label %87
87: ; preds = %85, %42, %25, %18
%88 = phi i32 [ -1, %18 ], [ -1, %25 ], [ -1, %42 ], [ 0, %85 ]
ret i32 %88
}