#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 scalar_t__ u_short;

/* Variables and functions */
scalar_t__ atoi(char *);
scalar_t__ do_scan(char *, scalar_t__, scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char *ahost;
  u_short startp;
  u_short stopp;
  if ((argc != 2) && (argc != 4)) {
    printf("usage: %s <host> [<start port> <end port>]\n", argv[0]);
    return 1;
  }
  if (argc == 4) {
    startp = (u_short)atoi(argv[2]);
    stopp = (u_short)atoi(argv[3]);
  } else {
    startp = (u_short)1;
    stopp = (u_short)65535;
  }
  ahost = argv[1];
  if (do_scan(ahost, startp, stopp) < 0)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1179 <main+0x49>
cmpl   $0x4,-0x8(%rbp)
je     1179 <main+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <main+0xc4>
cmpl   $0x4,-0x8(%rbp)
jne    11aa <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <atoi@plt>
mov    %rax,-0x28(%rbp)
jmp    11ba <main+0x8a>
movq   $0x1,-0x20(%rbp)
movq   $0xffff,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <do_scan@plt>
cmp    $0x0,%rax
jge    11ed <main+0xbd>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <main+0xc4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
je     115b <main+0x2b>
cmp    $0x4,%edi
jne    1178 <main+0x48>
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
call   1050 <atoi@plt>
mov    %rax,%rdx
jmp    1166 <main+0x36>
mov    $0xffff,%edx
mov    $0x1,%r14d
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1030 <do_scan@plt>
shr    $0x3f,%rax
jmp    118c <main+0x5c>
mov    (%rbx),%rsi
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [44 x i8] c"usage: %s <host> [<start port> <end port>]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
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 %19
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %43
19: ; preds = %11, %2
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 4
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i64 @atoi(i8* %25)
store i64 %26, i64* %7
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i64 @atoi(i8* %29)
store i64 %30, i64* %8
br label %32
31: ; preds = %19
store i64 1, i64* %7
store i64 65535, i64* %8
br label %32
32: ; preds = %31, %22
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = load i64, i64* %7
%38 = load i64, i64* %8
%39 = call i64 @do_scan(i8* %36, i64 %37, i64 %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %32
store i32 1, i32* %3
br label %43
42: ; preds = %32
store i32 0, i32* %3
br label %43
43: ; preds = %42, %41, %14
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [44 x i8] c"usage: %s <host> [<start port> <end port>]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %3 [
i32 4, label %6
i32 2, label %13
]
3: ; preds = %2
%4 = load i8*, i8** %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %21
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i64 @atoi(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 3
%11 = load i8*, i8** %10
%12 = tail call i64 @atoi(i8* %11)
br label %13
13: ; preds = %2, %6
%14 = phi i64 [ %9, %6 ], [ 1, %2 ]
%15 = phi i64 [ %12, %6 ], [ 65535, %2 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i64 @do_scan(i8* %17, i64 %14, i64 %15)
%19 = lshr i64 %18, 63
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %13, %3
%22 = phi i32 [ 1, %3 ], [ %20, %13 ]
ret i32 %22
}