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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ Connect(int, struct sockaddr *, int);
int /*<<< orphan*/ Inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SOCK_STREAM;
int Socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ err_quit(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ str_cli(int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in srvaddr;
  if (argc != 2)
    err_quit("usage: echocli <IPaddress>");
  sockfd = Socket(AF_INET, SOCK_STREAM, 0);
  memset(&srvaddr, 0, sizeof(srvaddr));
  srvaddr.sin_family = AF_INET;
  srvaddr.sin_port = htons(9877);
  Inet_pton(AF_INET, argv[1], &srvaddr.sin_addr);
  Connect(sockfd, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
  str_cli(stdin, sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119c <main+0x2c>
lea    0xe69(%rip),%rdi
call   1060 <err_quit@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <Inet_pton@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1050 <str_cli@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
je     118e <main+0x1e>
lea    0xe77(%rip),%rdi
call   1060 <err_quit@plt>
mov    0x2e53(%rip),%r15
mov    (%r15),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r15),%edi
mov    0x8(%r14),%rsi
mov    %rbx,%rdx
call   1070 <Inet_pton@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%esi
call   1050 <str_cli@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"usage: echocli <IPaddress>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @err_quit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @Socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 9877)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%26 = call i32 @Inet_pton(i32 %21, i8* %24, i32* %25)
%27 = load i32, i32* %6
%28 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%29 = call i32 @Connect(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = load i32, i32* @stdin
%31 = load i32, i32* %6
%32 = call i32 @str_cli(i32 %30, i32 %31)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"usage: echocli <IPaddress>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @err_quit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @Socket(i32 %9, i32 %10, i32 0)
%12 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 9877)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%21 = call i32 @Inet_pton(i32 %17, i8* %19, i32* %20)
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @Connect(i32 %11, %struct.sockaddr* %22, i32 12)
%24 = load i32, i32* @stdin
%25 = call i32 @str_cli(i32 %24, i32 %11)
ret i32 0
}