#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[5];
  int i;
  struct sockaddr_in srvaddr;
  if (argc != 2)
    err_quit("usage: echocli <IPaddress>");
  for (i = 0; i < 5; ++i) {
    sockfd[i] = 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[i], (struct sockaddr *)&srvaddr, sizeof(srvaddr));
  }
  str_cli(stdin, sockfd[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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>
movl   $0x0,-0x34(%rbp)
cmpl   $0x5,-0x34(%rbp)
jge    1237 <main+0xc7>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x40(%rbp),%rdx
call   1070 <Inet_pton@plt>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a3 <main+0x33>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%esi
call   1050 <str_cli@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
cmp    $0x2,%edi
je     1192 <main+0x22>
lea    0xe73(%rip),%rdi
call   1060 <err_quit@plt>
mov    0x2e4f(%rip),%r12
mov    (%r12),%edi
mov    0x2e2c(%rip),%r13
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,%r14d
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r12),%edi
mov    0x8(%r15),%rsi
mov    %rbp,%rdx
call   1070 <Inet_pton@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    (%r12),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r12),%edi
mov    0x8(%r15),%rsi
mov    %rbp,%rdx
call   1070 <Inet_pton@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    (%r12),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r12),%edi
mov    0x8(%r15),%rsi
mov    %rbp,%rdx
call   1070 <Inet_pton@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    (%r12),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r12),%edi
mov    0x8(%r15),%rsi
mov    %rbp,%rdx
call   1070 <Inet_pton@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    (%r12),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   1080 <Socket@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%r12),%edi
mov    0x8(%r15),%rsi
mov    %rbp,%rdx
call   1070 <Inet_pton@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <Connect@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
mov    %r14d,%esi
call   1050 <str_cli@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 [5 x i32]
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @err_quit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
store i32 0, i32* %7
br label %14
14: ; preds = %41, %13
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 5
br i1 %16, label %17, label %44
17: ; preds = %14
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @Socket(i32 %18, i32 %19, i32 0)
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %22
store i32 %20, i32* %23
%24 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @htons(i32 9877)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* @AF_INET
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%34 = call i32 @Inet_pton(i32 %29, i8* %32, i32* %33)
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%40 = call i32 @Connect(i32 %38, %struct.sockaddr* %39, i32 12)
br label %41
41: ; preds = %17
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %14
44: ; preds = %14
%45 = load i32, i32* @stdin
%46 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%47 = load i32, i32* %46
%48 = call i32 @str_cli(i32 %45, i32 %47)
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 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%13 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @Socket(i32 %14, i32 %15, i32 0)
%17 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
store i32 %18, i32* %9
%19 = call i32 @htons(i32 9877)
store i32 %19, i32* %10
%20 = load i32, i32* @AF_INET
%21 = load i8*, i8** %11
%22 = call i32 @Inet_pton(i32 %20, i8* %21, i32* %12)
%23 = call i32 @Connect(i32 %16, %struct.sockaddr* %13, i32 12)
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @Socket(i32 %24, i32 %25, i32 0)
%27 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%28 = load i32, i32* @AF_INET
store i32 %28, i32* %9
%29 = call i32 @htons(i32 9877)
store i32 %29, i32* %10
%30 = load i32, i32* @AF_INET
%31 = load i8*, i8** %11
%32 = call i32 @Inet_pton(i32 %30, i8* %31, i32* %12)
%33 = call i32 @Connect(i32 %26, %struct.sockaddr* %13, i32 12)
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @Socket(i32 %34, i32 %35, i32 0)
%37 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%38 = load i32, i32* @AF_INET
store i32 %38, i32* %9
%39 = call i32 @htons(i32 9877)
store i32 %39, i32* %10
%40 = load i32, i32* @AF_INET
%41 = load i8*, i8** %11
%42 = call i32 @Inet_pton(i32 %40, i8* %41, i32* %12)
%43 = call i32 @Connect(i32 %36, %struct.sockaddr* %13, i32 12)
%44 = load i32, i32* @AF_INET
%45 = load i32, i32* @SOCK_STREAM
%46 = call i32 @Socket(i32 %44, i32 %45, i32 0)
%47 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%48 = load i32, i32* @AF_INET
store i32 %48, i32* %9
%49 = call i32 @htons(i32 9877)
store i32 %49, i32* %10
%50 = load i32, i32* @AF_INET
%51 = load i8*, i8** %11
%52 = call i32 @Inet_pton(i32 %50, i8* %51, i32* %12)
%53 = call i32 @Connect(i32 %46, %struct.sockaddr* %13, i32 12)
%54 = load i32, i32* @AF_INET
%55 = load i32, i32* @SOCK_STREAM
%56 = call i32 @Socket(i32 %54, i32 %55, i32 0)
%57 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%58 = load i32, i32* @AF_INET
store i32 %58, i32* %9
%59 = call i32 @htons(i32 9877)
store i32 %59, i32* %10
%60 = load i32, i32* @AF_INET
%61 = load i8*, i8** %11
%62 = call i32 @Inet_pton(i32 %60, i8* %61, i32* %12)
%63 = call i32 @Connect(i32 %56, %struct.sockaddr* %13, i32 12)
%64 = load i32, i32* @stdin
%65 = call i32 @str_cli(i32 %64, i32 %16)
ret i32 0
}