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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ htons(int);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ str_cli(int);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd[5];
  struct sockaddr_in svaddr;
  int ret, i;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <IP address>\n", argv[0]);
    return -1;
  }
  for (i = 0; i < 5; ++i) {
    sockfd[i] = socket(AF_INET, SOCK_STREAM, 0);
    memset(&svaddr, 0, sizeof(svaddr));
    svaddr.sin_family = AF_INET;
    svaddr.sin_port = htons(10000);
    ret = inet_pton(AF_INET, argv[1], &svaddr.sin_addr);
    if (ret != 1) {
      fprintf(stderr, "inet_pton() for %s failed: %s\n", argv[1],
              strerror(errno));
      close(sockfd[i]);
      return -1;
    }
    ret = connect(sockfd[i], (struct sockaddr *)&svaddr, sizeof(svaddr));
    if (ret == -1) {
      fprintf(stderr, "connect() failed: %s\n", strerror(errno));
      close(sockfd[i]);
      return -1;
    }
  }
  str_cli(sockfd[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11da <main+0x4a>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1341 <main+0x1b1>
movl   $0x0,-0x48(%rbp)
cmpl   $0x5,-0x48(%rbp)
jge    1332 <main+0x1a2>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ecx
movslq -0x48(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x2710,%edi
call   1030 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x40(%rbp),%rdx
call   1080 <inet_pton@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x1,-0x44(%rbp)
je     12b5 <main+0x125>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movslq -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1341 <main+0x1b1>
movslq -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    131f <main+0x18f>
mov    0x2cf9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movslq -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1341 <main+0x1b1>
jmp    1324 <main+0x194>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11e1 <main+0x51>
mov    -0x30(%rbp),%edi
call   1060 <str_cli@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    123d <main+0xad>
xor    %ebp,%ebp
mov    0x2e35(%rip),%r12
mov    0x2e16(%rip),%r13
mov    %rsp,%r15
nopl   (%rax)
mov    (%r12),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
mov    %eax,0x10(%rsp,%rbp,4)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    $0x2710,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r12),%edi
mov    0x8(%r14),%rsi
mov    %r15,%rdx
call   1080 <inet_pton@plt>
cmp    $0x1,%eax
jne    1259 <main+0xc9>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     128c <main+0xfc>
add    $0x1,%rbp
cmp    $0x5,%rbp
jne    11c0 <main+0x30>
mov    0x10(%rsp),%edi
call   1060 <str_cli@plt>
xor    %eax,%eax
jmp    12c2 <main+0x132>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdb0(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12bd <main+0x12d>
mov    0x2d78(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%r14),%r14
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd9d(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12b6 <main+0x126>
mov    0x2d45(%rip),%rax
mov    (%rax),%ebp
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd8d(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
add    $0x28,%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 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s <IP address>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"inet_pton() for %s failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"connect() failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i32]
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %3
br label %82
18: ; preds = %2
store i32 0, i32* %9
br label %19
19: ; preds = %75, %18
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 5
br i1 %21, label %22, label %78
22: ; preds = %19
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %27
store i32 %25, i32* %28
%29 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @htons(i32 10000)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* @AF_INET
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%39 = call i32 @inet_pton(i32 %34, i8* %37, i32* %38)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 1
br i1 %41, label %42, label %55
42: ; preds = %22
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %48)
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
store i32 -1, i32* %3
br label %82
55: ; preds = %22
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%61 = call i32 @connect(i32 %59, %struct.sockaddr* %60, i32 12)
store i32 %61, i32* %8
%62 = load i32, i32* %8
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %74
64: ; preds = %55
%65 = load i32, i32* @stderr
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%69 = load i32, i32* %9
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 %70
%72 = load i32, i32* %71
%73 = call i32 @close(i32 %72)
store i32 -1, i32* %3
br label %82
74: ; preds = %55
br label %75
75: ; preds = %74
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
store i32 %77, i32* %9
br label %19
78: ; preds = %19
%79 = getelementptr inbounds [5 x i32], [5 x i32]* %6, i64 0, i64 0
%80 = load i32, i32* %79
%81 = call i32 @str_cli(i32 %80)
store i32 0, i32* %3
br label %82
82: ; preds = %78, %64, %42, %12
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s <IP address>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [31 x i8] c"inet_pton() for %s failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"connect() failed: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i32]
%4 = alloca %struct.sockaddr_in
%5 = bitcast [5 x i32]* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%13 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %54
18: ; preds = %41
%19 = add nuw nsw i64 %22, 1
%20 = icmp eq i64 %19, 5
br i1 %20, label %50, label %21
21: ; preds = %8, %18
%22 = phi i64 [ 0, %8 ], [ %19, %18 ]
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %22
store i32 %25, i32* %26
%27 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%28 = load i32, i32* @AF_INET
store i32 %28, i32* %9
%29 = call i32 @htons(i32 10000)
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 = icmp eq i32 %32, 1
br i1 %33, label %41, label %34
34: ; preds = %21
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %11
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %38)
%40 = call i32 @close(i32 %25)
br label %54
41: ; preds = %21
%42 = call i32 @connect(i32 %25, %struct.sockaddr* %13, i32 12)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %18
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = call i32 @close(i32 %25)
br label %54
50: ; preds = %18
%51 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%52 = load i32, i32* %51
%53 = call i32 @str_cli(i32 %52)
br label %54
54: ; preds = %50, %44, %34, %14
%55 = phi i32 [ -1, %14 ], [ -1, %34 ], [ -1, %44 ], [ 0, %50 ]
ret i32 %55
}