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

/* Variables and functions */
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ check_connect_port(int, int const, char *);
int /*<<< orphan*/ exit(int);
char getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ showUsage(char *);
size_t strlen(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  int totalNum = 50;
  int startPort = 1000;
  char address[32] = "127.0.0.1";
  if (argc < 2) {
    showUsage(argv[0]);
    exit(1);
  }
  char ch;
  while ((ch = getopt(argc, argv, "p:h:N:")) != -1) {
    switch (ch) {
    case 'p':
      startPort = atoi(optarg);
      break;
    case 'h':
      strncpy(address, optarg, 31);
      address[strlen(optarg)] = '\0';
      break;
    case 'N':
      totalNum = atoi(optarg);
      break;
    default:
      showUsage(argv[0]);
      exit(1);
    }
  }
  int k = 0;
  const int unit = 1000;
  for (k = 0; k < totalNum / unit; k++) {
    check_connect_port(startPort + k * unit, unit, address);
  }
  check_connect_port(startPort + k * unit, totalNum % unit, address);
}


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)
movl   $0x32,-0x14(%rbp)
movl   $0x3e8,-0x18(%rbp)
mov    0xe65(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe62(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe5f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe5c(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e0 <main+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <showUsage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11e5 <main+0x75>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2d(%rip),%rdx
call   1070 <getopt@plt>
mov    %al,-0x41(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12b4 <main+0x144>
movsbl -0x41(%rbp),%eax
mov    %eax,-0x50(%rbp)
sub    $0x4e,%eax
je     1283 <main+0x113>
jmp    121c <main+0xac>
mov    -0x50(%rbp),%eax
sub    $0x68,%eax
je     1254 <main+0xe4>
jmp    122d <main+0xbd>
mov    -0x50(%rbp),%eax
sub    $0x70,%eax
jne    1299 <main+0x129>
jmp    123e <main+0xce>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    12af <main+0x13f>
lea    -0x40(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1050 <strlen@plt>
movb   $0x0,-0x40(%rbp,%rax,1)
jmp    12af <main+0x13f>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    12af <main+0x13f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <showUsage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11e5 <main+0x75>
movl   $0x0,-0x48(%rbp)
movl   $0x3e8,-0x4c(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jge    130f <main+0x19f>
mov    -0x18(%rbp),%edi
imul   $0x3e8,-0x48(%rbp),%eax
add    %eax,%edi
lea    -0x40(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <check_connect_port@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    12c9 <main+0x159>
mov    -0x18(%rbp),%edi
imul   $0x3e8,-0x48(%rbp),%eax
add    %eax,%edi
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    -0x40(%rbp),%rdx
call   1040 <check_connect_port@plt>
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,%rbp
movaps 0xe88(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe6c(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
jl     12e3 <main+0x173>
mov    %edi,%ebx
lea    0xe76(%rip),%rdx
mov    %rbp,%rsi
call   1070 <getopt@plt>
xor    %ecx,%ecx
mov    $0x3e8,%r15d
mov    $0x32,%r14d
cmp    $0xff,%al
je     12a5 <main+0x135>
mov    0x2e29(%rip),%r13
lea    0xe4a(%rip),%r12
jmp    120f <main+0x9f>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%esi
mov    %rsp,%rdi
mov    $0x1f,%edx
call   1030 <strncpy@plt>
mov    0x0(%r13),%edi
call   1050 <strlen@plt>
movb   $0x0,(%rsp,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1070 <getopt@plt>
cmp    $0xff,%al
je     124e <main+0xde>
movsbl %al,%eax
cmp    $0x4e,%eax
je     1240 <main+0xd0>
cmp    $0x68,%eax
je     11e0 <main+0x70>
cmp    $0x70,%eax
jne    12e3 <main+0x173>
mov    0x0(%r13),%edi
call   1080 <atoi@plt>
mov    %eax,%r15d
jmp    11fe <main+0x8e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%edi
call   1080 <atoi@plt>
mov    %eax,%r14d
jmp    11fe <main+0x8e>
cmp    $0x3e8,%r14d
jl     12a3 <main+0x133>
movslq %r14d,%rax
imul   $0x10624dd3,%rax,%r12
mov    %r12,%rax
shr    $0x3f,%rax
sar    $0x26,%r12
add    %eax,%r12d
mov    %rsp,%r13
mov    %r15d,%ebp
mov    %r12d,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    $0x3e8,%esi
mov    %r13,%rdx
call   1040 <check_connect_port@plt>
add    $0x3e8,%ebp
add    $0xffffffff,%ebx
jne    1280 <main+0x110>
imul   $0x3e8,%r12d,%ecx
jmp    12a5 <main+0x135>
xor    %ecx,%ecx
add    %ecx,%r15d
movslq %r14d,%rsi
imul   $0x10624dd3,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%esi
mov    %rsp,%rdx
mov    %r15d,%edi
call   1040 <check_connect_port@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%rdi
call   1060 <showUsage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@__const.main.address = [32 x i8] c"127.0.0.1\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [7 x i8] c"p:h:N:\00"
@optarg = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [32 x i8]
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 50, i32* %6
store i32 1000, i32* %7
%12 = bitcast [32 x i8]* %8 to i8*
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @showUsage(i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
br label %22
22: ; preds = %50, %21
%23 = load i32, i32* %4
%24 = load i8**, i8*** %5
%25 = call signext i8 @getopt(i32 %23, i8** %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8 %25, i8* %9
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %51
28: ; preds = %22
%29 = load i8, i8* %9
%30 = sext i8 %29 to i32
switch i32 %30, label %44 [
i32 112, label %31
i32 104, label %34
i32 78, label %41
]
31: ; preds = %28
%32 = load i32, i32* @optarg
%33 = call i32 @atoi(i32 %32)
store i32 %33, i32* %7
br label %50
34: ; preds = %28
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%36 = load i32, i32* @optarg
%37 = call i32 @strncpy(i8* %35, i32 %36, i32 31)
%38 = load i32, i32* @optarg
%39 = call i64 @strlen(i32 %38)
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 %39
store i8 0, i8* %40
br label %50
41: ; preds = %28
%42 = load i32, i32* @optarg
%43 = call i32 @atoi(i32 %42)
store i32 %43, i32* %6
br label %50
44: ; preds = %28
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @showUsage(i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %41, %34, %31
br label %22
51: ; preds = %22
store i32 0, i32* %10
store i32 1000, i32* %11
store i32 0, i32* %10
br label %52
52: ; preds = %64, %51
%53 = load i32, i32* %10
%54 = load i32, i32* %6
%55 = sdiv i32 %54, 1000
%56 = icmp slt i32 %53, %55
br i1 %56, label %57, label %67
57: ; preds = %52
%58 = load i32, i32* %7
%59 = load i32, i32* %10
%60 = mul nsw i32 %59, 1000
%61 = add nsw i32 %58, %60
%62 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%63 = call i32 @check_connect_port(i32 %61, i32 1000, i8* %62)
br label %64
64: ; preds = %57
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %52
67: ; preds = %52
%68 = load i32, i32* %7
%69 = load i32, i32* %10
%70 = mul nsw i32 %69, 1000
%71 = add nsw i32 %68, %70
%72 = load i32, i32* %6
%73 = srem i32 %72, 1000
%74 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%75 = call i32 @check_connect_port(i32 %71, i32 %73, i8* %74)
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@__const.main.address = [32 x i8] c"127.0.0.1\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [7 x i8] c"p:h:N:\00"
@optarg = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8 %7, -1
br i1 %8, label %51, label %16
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 @showUsage(i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %37
%14 = sdiv i32 %39, 1000
%15 = icmp sgt i32 %39, 999
br i1 %15, label %42, label %51
16: ; preds = %6, %37
%17 = phi i8 [ %40, %37 ], [ %7, %6 ]
%18 = phi i32 [ %39, %37 ], [ 50, %6 ]
%19 = phi i32 [ %38, %37 ], [ 1000, %6 ]
%20 = sext i8 %17 to i32
switch i32 %20, label %33 [
i32 112, label %21
i32 104, label %24
i32 78, label %30
]
21: ; preds = %16
%22 = load i32, i32* @optarg
%23 = call i32 @atoi(i32 %22)
br label %37
24: ; preds = %16
%25 = load i32, i32* @optarg
%26 = call i32 @strncpy(i8* %4, i32 %25, i32 31)
%27 = load i32, i32* @optarg
%28 = call i64 @strlen(i32 %27)
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %28
store i8 0, i8* %29
br label %37
30: ; preds = %16
%31 = load i32, i32* @optarg
%32 = call i32 @atoi(i32 %31)
br label %37
33: ; preds = %16
%34 = load i8*, i8** %1
%35 = call i32 @showUsage(i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30, %24, %21
%38 = phi i32 [ %19, %30 ], [ %19, %24 ], [ %23, %21 ]
%39 = phi i32 [ %32, %30 ], [ %18, %24 ], [ %18, %21 ]
%40 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%41 = icmp eq i8 %40, -1
br i1 %41, label %13, label %16
42: ; preds = %13, %42
%43 = phi i32 [ %47, %42 ], [ 0, %13 ]
%44 = mul nuw nsw i32 %43, 1000
%45 = add nsw i32 %44, %38
%46 = call i32 @check_connect_port(i32 %45, i32 1000, i8* %4)
%47 = add nuw nsw i32 %43, 1
%48 = icmp eq i32 %47, %14
br i1 %48, label %49, label %42
49: ; preds = %42
%50 = mul i32 %14, 1000
br label %51
51: ; preds = %6, %49, %13
%52 = phi i32 [ %39, %13 ], [ %39, %49 ], [ 50, %6 ]
%53 = phi i32 [ %38, %13 ], [ %38, %49 ], [ 1000, %6 ]
%54 = phi i32 [ 0, %13 ], [ %50, %49 ], [ 0, %6 ]
%55 = add nsw i32 %54, %53
%56 = srem i32 %52, 1000
%57 = call i32 @check_connect_port(i32 %55, i32 %56, i8* %4)
ret i32 0
}