#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*/ atoi(char *);
scalar_t__ connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char *argv[]) {
  int sockfd[65536];
  int i;
  struct sockaddr_in svaddr;
  char buffer[1024];
  if (argc != 3) {
    fprintf(stderr, "Uasge: %s <ip> <port>\n", argv[0]);
    exit(-1);
  }
  memset(&svaddr, 0, sizeof(svaddr));
  svaddr.sin_family = AF_INET;
  svaddr.sin_port = htons(atoi(argv[2]));
  if (inet_pton(AF_INET, argv[1], &(svaddr.sin_addr)) != 1) {
    fprintf(stderr, "inet_pton() convert %s failed: %s\n", argv[1],
            strerror(errno));
    exit(errno);
  }
  i = 0;
  while (1) {
    if ((sockfd[i] = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
      perror("socket() failed");
      exit(errno);
    }
    if (connect(sockfd[i], (struct sockaddr *)&svaddr, sizeof(svaddr)) != 0) {
      perror("connect() failed");
      exit(errno);
    }
    printf("client %d connected\n", ++i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11fb <main+0x4b>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    -0x40020(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40018(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x4001c(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x40020(%rbp),%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
je     12b5 <main+0x105>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4042c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40428(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x4042c(%rbp),%edi
mov    -0x40428(%rbp),%rdx
mov    %rax,%rcx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x0,-0x40014(%rbp)
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
movslq -0x40014(%rbp),%rcx
mov    %eax,-0x40010(%rbp,%rcx,4)
cmp    $0xffffffff,%eax
jne    1309 <main+0x159>
lea    0xd44(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movslq -0x40014(%rbp),%rax
mov    -0x40010(%rbp,%rax,4),%edi
lea    -0x40020(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
je     134c <main+0x19c>
lea    0xd11(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x40014(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x40014(%rbp)
lea    0xcf9(%rip),%rdi
call   1040 <printf@plt>
jmp    12bf <main+0x10f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1281 <main+0xd1>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e07(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r12),%edi
mov    0x8(%rbx),%rsi
mov    %r14,%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
jne    12a5 <main+0xf5>
mov    (%r12),%edi
mov    0x2daf(%rip),%rbp
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     1278 <main+0xc8>
mov    $0x1,%ebx
mov    %rsp,%r14
lea    0xe1c(%rip),%r15
nop
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
jne    12df <main+0x12f>
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    (%r12),%edi
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
add    $0x1,%ebx
cmp    $0xffffffff,%eax
jne    1240 <main+0x90>
lea    0xdbb(%rip),%rdi
jmp    12e6 <main+0x136>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd6c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2d0f(%rip),%r14
mov    (%r14),%edi
call   10c0 <strerror@plt>
lea    0xd4f(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
call   10a0 <exit@plt>
lea    0xd64(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Uasge: %s <ip> <port>\0A\00"
@AF_INET = global i32 0
@.str.1 = [35 x i8] c"inet_pton() convert %s failed: %s\0A\00"
@errno = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@.str.3 = [17 x i8] c"connect() failed\00"
@.str.4 = [21 x i8] c"client %d connected\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [65536 x i32]
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca [1024 x i8]
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, 3
br i1 %11, label %12, label %19
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 ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = call i32 @htons(i32 %26)
%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 = icmp ne i32 %34, 1
br i1 %35, label %36, label %46
36: ; preds = %19
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %42)
%44 = load i32, i32* @errno
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %19
store i32 0, i32* %7
br label %47
47: ; preds = %46, %71
%48 = load i32, i32* @AF_INET
%49 = load i32, i32* @SOCK_STREAM
%50 = call i32 @socket(i32 %48, i32 %49, i32 0)
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [65536 x i32], [65536 x i32]* %6, i64 0, i64 %52
store i32 %50, i32* %53
%54 = icmp eq i32 %50, -1
br i1 %54, label %55, label %59
55: ; preds = %47
%56 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%57 = load i32, i32* @errno
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %47
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [65536 x i32], [65536 x i32]* %6, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%65 = call i64 @connect(i32 %63, %struct.sockaddr* %64, i32 12)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %59
%68 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%69 = load i32, i32* @errno
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %59
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
%74 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %73)
br label %47
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Uasge: %s <ip> <port>\0A\00"
@AF_INET = global i32 0
@.str.1 = [35 x i8] c"inet_pton() convert %s failed: %s\0A\00"
@errno = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [16 x i8] c"socket() failed\00"
@.str.3 = [17 x i8] c"connect() failed\00"
@.str.4 = [21 x i8] c"client %d connected\0A\00"
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, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%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 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
%18 = call i32 @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%24 = call i32 @inet_pton(i32 %20, i8* %22, i32* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %33
26: ; preds = %11
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
%30 = icmp eq i32 %29, -1
br i1 %30, label %41, label %31
31: ; preds = %26
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %45
33: ; preds = %11
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %21
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %37)
%39 = load i32, i32* @errno
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %54, %26
%42 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* @errno
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %31, %54
%46 = phi i32 [ %29, %31 ], [ %59, %54 ]
%47 = phi i32 [ 0, %31 ], [ %55, %54 ]
%48 = call i64 @connect(i32 %46, %struct.sockaddr* %32, i32 12)
%49 = icmp eq i64 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%52 = load i32, i32* @errno
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %45
%55 = add nuw nsw i32 %47, 1
%56 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %55)
%57 = load i32, i32* @AF_INET
%58 = load i32, i32* @SOCK_STREAM
%59 = call i32 @socket(i32 %57, i32 %58, i32 0)
%60 = icmp eq i32 %59, -1
br i1 %60, label %41, label %45
}