#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr const *, int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    printf("Usage : %s IP port\n", argv[0]);
    return 1;
  }
  char *server_ip = argv[1];
  int port = atoi(argv[2]);
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in server_addr;
  bzero(&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(port);
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_addr.s_addr = inet_addr(server_ip);
  int err = connect(sock, (const struct sockaddr *)&server_addr,
                    sizeof(struct sockaddr_in));
  if (err < 0) {
    printf("connect faild\n");
    return 2;
  }
  const char *msg = "{\"method\":\"stopservice\"}";
  if (send(sock, msg, strlen(msg), 0) < 0) {
    printf("send faild\n");
    return 3;
  }
  printf("Enter [Enter] to exit\n");
  getchar();
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1201 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    132d <main+0x16d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    12b3 <main+0xf3>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    132d <main+0x16d>
lea    0xd69(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x0,%rax
jge    1309 <main+0x149>
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    132d <main+0x16d>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10a0 <getchar@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jg     11fc <main+0x2c>
mov    (%rsi),%rsi
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%ebp
jmp    12db <main+0x10b>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebp
mov    0x2dd6(%rip),%rbx
mov    (%rbx),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%r12d
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %r14,%rdi
call   10a0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %eax,%eax
js     12b7 <main+0xe7>
lea    0xd98(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
mov    %r12d,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %rax,%rax
js     12ca <main+0xfa>
lea    0xd8c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10b0 <getchar@plt>
mov    %r12d,%edi
call   1090 <close@plt>
jmp    12db <main+0x10b>
lea    0xd90(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%ebp
jmp    12db <main+0x10b>
lea    0xd72(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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.sockaddr = type { i32 }
@.str = [20 x i8] c"Usage : %s IP port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [15 x i8] c"connect faild\0A\00"
@.str.2 = [25 x i8] c"{\22method\22:\22stopservice\22}\00"
@.str.3 = [12 x i8] c"send faild\0A\00"
@.str.4 = [23 x i8] c"Enter [Enter] to exit\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %65
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %7
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
store i32 %29, i32* %8
%30 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* %7
%34 = call i32 @htons(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = call i32 @htonl(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
store i32 %37, i32* %39
%40 = load i8*, i8** %6
%41 = call i32 @inet_addr(i8* %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = load i32, i32* %8
%45 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%46 = call i32 @connect(i32 %44, %struct.sockaddr* %45, i32 12)
store i32 %46, i32* %10
%47 = load i32, i32* %10
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %19
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %65
51: ; preds = %19
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8** %11
%52 = load i32, i32* %8
%53 = load i8*, i8** %11
%54 = load i8*, i8** %11
%55 = call i32 @strlen(i8* %54)
%56 = call i64 @send(i32 %52, i8* %53, i32 %55, i32 0)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %51
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %65
60: ; preds = %51
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 (...) @getchar()
%63 = load i32, i32* %8
%64 = call i32 @close(i32 %63)
store i32 0, i32* %3
br label %65
65: ; preds = %60, %58, %49, %14
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"Usage : %s IP port\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [25 x i8] c"{\22method\22:\22stopservice\22}\00"
@str = [22 x i8] c"Enter [Enter] to exit\00"
@str.5 = [11 x i8] c"send faild\00"
@str.6 = [14 x i8] c"connect faild\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %44
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = bitcast %struct.sockaddr_in* %3 to i8*
%18 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 %13)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = tail call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%26 = tail call i32 @inet_addr(i8* %10)
store i32 %26, i32* %25
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @connect(i32 %16, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %8
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
br label %42
32: ; preds = %8
%33 = call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%34 = call i64 @send(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 0)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
br label %42
38: ; preds = %32
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%40 = call i32 (...) @getchar()
%41 = call i32 @close(i32 %16)
br label %42
42: ; preds = %36, %38, %30
%43 = phi i32 [ 2, %30 ], [ 3, %36 ], [ 0, %38 ]
br label %44
44: ; preds = %42, %5
%45 = phi i32 [ 1, %5 ], [ %43, %42 ]
ret i32 %45
}