#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 */
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char **argv) {
  if (argc != 4) {
    printf("the number of arguments isn't vaild\n");
  } else {
    char *server_port = "5555";
    char *server_ip = argv[1];
    struct addrinfo hints, *server;
    int rc;
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    if ((rc = getaddrinfo(server_ip, server_port, &hints, &server)) != 0) {
      perror(gai_strerror(rc));
      exit(-1);
    }
    int sockfd =
        socket(server->ai_family, server->ai_socktype, server->ai_protocol);
    if (sockfd == -1) {
      perror("ERROR opening socket");
      exit(-1);
    }
    rc = connect(sockfd, server->ai_addr, server->ai_addrlen);
    if (rc == -1) {
      perror("ERROR on connect");
      close(sockfd);
      exit(-1);
    }
    send(sockfd, argv[2], strlen(argv[2]) + 1, 0);
    send(sockfd, "\r\n", 2, 0);
    send(sockfd, argv[3], strlen(argv[3]) + 1, 0);
    send(sockfd, "\r\n", 2, 0);
    printf("Done.\n");
    close(sockfd);
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11e1 <main+0x31>
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
jmp    1383 <main+0x1d3>
lea    0xe3d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     125b <main+0xab>
mov    -0x44(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    %rax,%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    1298 <main+0xe8>
lea    0xda1(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   10b0 <connect@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    12d8 <main+0x128>
lea    0xd7e(%rip),%rdi
call   1090 <perror@plt>
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x48(%rbp),%edi
lea    0xd3c(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x48(%rbp),%edi
lea    0xcf4(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    0xce4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
cmp    $0x4,%edi
jne    12c3 <main+0x113>
mov    %rsi,%r15
mov    0x8(%rsi),%rbp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
lea    0xe01(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbp,%rdi
mov    %r14,%rdx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
jne    12dc <main+0x12c>
mov    0x8(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x138>
mov    %eax,%ebp
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
je     12fe <main+0x14e>
mov    0x10(%r15),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0xdba(%rip),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    0x18(%r15),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0xd79(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    12cf <main+0x11f>
lea    0xd6a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edi
call   1060 <gai_strerror@plt>
mov    %rax,%rdi
jmp    12ef <main+0x13f>
lea    0xd16(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xd15(%rip),%rdi
call   1090 <perror@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [37 x i8] c"the number of arguments isn't vaild\0A\00"
@.str.1 = [5 x i8] c"5555\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [17 x i8] c"ERROR on connect\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@.str.5 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %94
16: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 20)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %21, i32* %22
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32 %23, i32* %24
%25 = load i8*, i8** %7
%26 = load i8*, i8** %6
%27 = call i32 @getaddrinfo(i8* %25, i8* %26, %struct.addrinfo* %8, %struct.addrinfo** %9)
store i32 %27, i32* %10
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %16
%30 = load i32, i32* %10
%31 = call i8* @gai_strerror(i32 %30)
%32 = call i32 @perror(i8* %31)
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %16
%35 = load %struct.addrinfo*, %struct.addrinfo** %9
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 4
%37 = load i32, i32* %36
%38 = load %struct.addrinfo*, %struct.addrinfo** %9
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 3
%40 = load i32, i32* %39
%41 = load %struct.addrinfo*, %struct.addrinfo** %9
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 2
%43 = load i32, i32* %42
%44 = call i32 @socket(i32 %37, i32 %40, i32 %43)
store i32 %44, i32* %11
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %34
%48 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %34
%51 = load i32, i32* %11
%52 = load %struct.addrinfo*, %struct.addrinfo** %9
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = load %struct.addrinfo*, %struct.addrinfo** %9
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @connect(i32 %51, i32 %54, i32 %57)
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %66
61: ; preds = %50
%62 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* %11
%64 = call i32 @close(i32 %63)
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %50
%67 = load i32, i32* %11
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 2
%70 = load i8*, i8** %69
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = call i32 @strlen(i8* %73)
%75 = add nsw i32 %74, 1
%76 = call i32 @send(i32 %67, i8* %70, i32 %75, i32 0)
%77 = load i32, i32* %11
%78 = call i32 @send(i32 %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 0)
%79 = load i32, i32* %11
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 3
%82 = load i8*, i8** %81
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 3
%85 = load i8*, i8** %84
%86 = call i32 @strlen(i8* %85)
%87 = add nsw i32 %86, 1
%88 = call i32 @send(i32 %79, i8* %82, i32 %87, i32 0)
%89 = load i32, i32* %11
%90 = call i32 @send(i32 %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 0)
%91 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%92 = load i32, i32* %11
%93 = call i32 @close(i32 %92)
store i32 0, i32* %3
br label %94
94: ; preds = %66, %14
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str.1 = [5 x i8] c"5555\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [17 x i8] c"ERROR on connect\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@str = [6 x i8] c"Done.\00"
@str.6 = [36 x i8] c"the number of arguments isn't vaild\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = icmp eq i32 %0, 4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0))
br label %64
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = bitcast %struct.addrinfo* %3 to i8*
%12 = bitcast %struct.addrinfo** %4 to i8*
%13 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 20)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_STREAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %16, i32* %17
%18 = call i32 @getaddrinfo(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %8
%21 = call i8* @gai_strerror(i32 %18)
%22 = call i32 @perror(i8* %21)
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %8
%25 = load %struct.addrinfo*, %struct.addrinfo** %4
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 4
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 2
%31 = load i32, i32* %30
%32 = call i32 @socket(i32 %27, i32 %29, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %24
%35 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %24
%38 = load %struct.addrinfo*, %struct.addrinfo** %4
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i64 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @connect(i32 %32, i32 %40, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %37
%46 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @close(i32 %32)
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %37
%50 = getelementptr inbounds i8*, i8** %1, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @strlen(i8* %51)
%53 = add nsw i32 %52, 1
%54 = call i32 @send(i32 %32, i8* %51, i32 %53, i32 0)
%55 = call i32 @send(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 0)
%56 = getelementptr inbounds i8*, i8** %1, i64 3
%57 = load i8*, i8** %56
%58 = call i32 @strlen(i8* %57)
%59 = add nsw i32 %58, 1
%60 = call i32 @send(i32 %32, i8* %57, i32 %59, i32 0)
%61 = call i32 @send(i32 %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 0)
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%63 = call i32 @close(i32 %32)
br label %64
64: ; preds = %49, %6
ret i32 0
}