#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*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ str_cli(int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  int i, sockfd[5];
  struct sockaddr_in servaddr;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <Server IP address>\neg. $ ./%s 127.0.0.1\n",
            argv[0], argv[0]);
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < 5; i++) {
    if ((sockfd[i] = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
      fprintf(stderr, "socket() error");
      exit(EXIT_FAILURE);
    }
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(9669);
    if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) {
      fprintf(stderr, "inet_pton(%s) error", argv[1]);
      exit(EXIT_FAILURE);
    }
    if (connect(sockfd[i], (struct sockaddr *)&servaddr, sizeof(servaddr)) <
        0) {
      perror("connect() error");
      exit(EXIT_FAILURE);
    }
  }
  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     11e3 <main+0x53>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1308 <main+0x178>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
movslq -0x14(%rbp),%rcx
mov    %eax,-0x30(%rbp,%rcx,4)
cmp    $0x0,%eax
jge    1243 <main+0xb3>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x25c5,%edi
call   1030 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <inet_pton@plt>
cmp    $0x0,%rax
jg     12bb <main+0x12b>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movslq -0x14(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    12f5 <main+0x165>
lea    0xd75(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12fa <main+0x16a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <main+0x5a>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%esi
call   1040 <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    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    12a2 <main+0x112>
xor    %ebx,%ebx
mov    0x2e35(%rip),%r12
mov    0x2e0e(%rip),%r13
mov    %rsp,%r15
nopl   (%rax)
mov    (%r12),%edi
mov    0x0(%r13),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,0x10(%rsp,%rbx,4)
test   %eax,%eax
js     1252 <main+0xc2>
mov    %eax,%ebp
mov    %r15,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    $0x25c5,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r12),%edi
mov    0x8(%r14),%rsi
mov    %r15,%rdx
call   1060 <inet_pton@plt>
test   %rax,%rax
jle    126b <main+0xdb>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     1288 <main+0xf8>
add    $0x1,%rbx
cmp    $0x5,%rbx
jne    11c0 <main+0x30>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%esi
call   1040 <str_cli@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1294 <main+0x104>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdc4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1294 <main+0x104>
lea    0xdc8(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rcx
lea    0xd4b(%rip),%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1294 <main+0x104>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [52 x i8] c"usage: %s <Server IP address>\0Aeg. $ ./%s 127.0.0.1\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@.str.2 = [20 x i8] c"inet_pton(%s) error\00"
@.str.3 = [16 x i8] c"connect() error\00"
@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 [5 x 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 %22
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
store i32 0, i32* %6
br label %23
23: ; preds = %73, %22
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 5
br i1 %25, label %26, label %76
26: ; preds = %23
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 %31
store i32 %29, i32* %32
%33 = icmp slt i32 %29, 0
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %26
%40 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %41, i32* %42
%43 = call i32 @htons(i32 9669)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %43, i32* %44
%45 = load i32, i32* @AF_INET
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%50 = call i64 @inet_pton(i32 %45, i8* %48, i32* %49)
%51 = icmp sle i64 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %39
%53 = load i32, i32* @stderr
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %39
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%66 = call i64 @connect(i32 %64, %struct.sockaddr* %65, i32 12)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %60
%69 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %60
br label %73
73: ; preds = %72
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %23
76: ; preds = %23
%77 = load i32, i32* @stdin
%78 = getelementptr inbounds [5 x i32], [5 x i32]* %7, i64 0, i64 0
%79 = load i32, i32* %78
%80 = call i32 @str_cli(i32 %77, i32 %79)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [52 x i8] c"usage: %s <Server IP address>\0Aeg. $ ./%s 127.0.0.1\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@.str.2 = [20 x i8] c"inet_pton(%s) error\00"
@.str.3 = [16 x i8] c"connect() error\00"
@stdin = global i32 0
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 %23
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %49
%21 = add nuw nsw i64 %24, 1
%22 = icmp eq i64 %21, 5
br i1 %22, label %56, label %23
23: ; preds = %8, %20
%24 = phi i64 [ 0, %8 ], [ %21, %20 ]
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %24
store i32 %27, i32* %28
%29 = icmp slt i32 %27, 0
br i1 %29, label %30, label %35
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %23
%36 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%37 = load i32, i32* @AF_INET
store i32 %37, i32* %9
%38 = call i32 @htons(i32 9669)
store i32 %38, i32* %10
%39 = load i32, i32* @AF_INET
%40 = load i8*, i8** %11
%41 = call i64 @inet_pton(i32 %39, i8* %40, i32* %12)
%42 = icmp slt i64 %41, 1
br i1 %42, label %43, label %49
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %11
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %35
%50 = call i64 @connect(i32 %27, %struct.sockaddr* %13, i32 12)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %20
52: ; preds = %49
%53 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %20
%57 = load i32, i32* @stdin
%58 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
%59 = load i32, i32* %58
%60 = call i32 @str_cli(i32 %57, i32 %59)
ret i32 0
}