#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int dummy;
};
typedef int /*<<< orphan*/ des_ip;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_RAW;
int /*<<< orphan*/ SOCK_RAW;
unsigned int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(unsigned int);
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int rand();
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ tcpip_send(int, struct sockaddr_in *, int /*<<< orphan*/,
                      int /*<<< orphan*/, unsigned int, unsigned int,
                      int /*<<< orphan*/, int, int /*<<< orphan*/, int,
                      int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 6) {
    fprintf(stderr,
            "usage: %s <myIP> <scannedIP> <srcPort> <startPort> <endPort>\n",
            argv[0]);
    exit(1);
  }
  unsigned int src_port = atoi(argv[3]), st_port = atoi(argv[4]),
               end_port = atoi(argv[5]);
  unsigned int i;
  int sd;
  struct sockaddr_in des_addr;
  uint32_t src_ip, des_ip;
  srand(time(NULL));
  inet_aton(argv[1], (struct in_addr *)&src_ip);
  inet_aton(argv[2], (struct in_addr *)&des_ip);
  perror("line");
  sd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  memset(&des_addr, 0, sizeof(struct sockaddr));
  des_addr.sin_family = AF_INET;
  memcpy(&des_addr.sin_addr.s_addr, &des_ip, sizeof(des_ip));
  for (i = st_port; i <= end_port; i++) {
    des_addr.sin_port = htons(i);
    fprintf(stdout, "Send packet to %u port\n", i);
    if (tcpip_send(sd, &des_addr, src_ip, des_ip, src_port, i, 0, rand() % 1996,
                   0, 1500, NULL, 0) < 0) {
      fprintf(stderr, "Error in sendign to port %d\n", i);
      perror("Filed in sendto()");
    }
  }
  close(sd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x6,-0x8(%rbp)
je     122b <main+0x4b>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x34(%rbp),%rsi
call   10b0 <inet_aton@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <inet_aton@plt>
lea    0xdaa(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
mov    0x2d16(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x24(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
add    $0x4,%rdi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
ja     13e3 <main+0x203>
mov    -0x20(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xd25(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    $0x0,%al
call   10f0 <rand@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%ecx
mov    -0x44(%rbp),%r8d
mov    -0x40(%rbp),%r9d
mov    $0x7cc,%esi
cltd
idiv   %esi
mov    %edx,%eax
mov    -0x3c(%rbp),%edx
lea    -0x30(%rbp),%rsi
xor    %r10d,%r10d
xor    %r10d,%r10d
movl   $0x0,(%rsp)
mov    %eax,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x5dc,0x18(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
call   10a0 <tcpip_send@plt>
cmp    $0x0,%rax
jge    13d0 <main+0x1f0>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xc9e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xcad(%rip),%rdi
call   10c0 <perror@plt>
jmp    13d5 <main+0x1f5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12f4 <main+0x114>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x6,%edi
jne    1383 <main+0x1a3>
mov    0x18(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r14d
mov    0x20(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,%ebp
mov    0x28(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r15d
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    0x8(%rbx),%rdi
lea    0x4(%rsp),%rsi
call   10b0 <inet_aton@plt>
mov    0x10(%rbx),%rdi
mov    %rsp,%r12
mov    %r12,%rsi
call   10b0 <inet_aton@plt>
lea    0xdef(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d8d(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    0x2d59(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x0(%r13),%eax
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
jmp    12b3 <main+0xd3>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
cmp    %r15d,%ebp
ja     136b <main+0x18b>
mov    %ebp,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x4(%rsp),%r12d
mov    (%rsp),%r13d
xor    %eax,%eax
call   10f0 <rand@plt>
cltq
imul   $0x20d56b39,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x28,%rcx
add    %edx,%ecx
imul   $0x7cc,%ecx,%ecx
sub    %ecx,%eax
mov    %ebx,%edi
lea    0x8(%rsp),%rsi
mov    %r12d,%edx
mov    %r13d,%ecx
mov    %r14d,%r8d
mov    %ebp,%r9d
push   $0x0
push   $0x0
push   $0x5dc
push   $0x0
push   %rax
push   $0x0
call   10a0 <tcpip_send@plt>
add    $0x30,%rsp
test   %rax,%rax
jns    12b0 <main+0xd0>
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd17(%rip),%rdi
call   10c0 <perror@plt>
jmp    12b0 <main+0xd0>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc6a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [62 x i8] c"usage: %s <myIP> <scannedIP> <srcPort> <startPort> <endPort>\0A\00"
@.str.1 = [5 x i8] c"line\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@stdout = global i32 0
@.str.2 = [24 x i8] c"Send packet to %u port\0A\00"
@.str.3 = [29 x i8] c"Error in sendign to port %d\0A\00"
@.str.4 = [18 x i8] c"Filed in sendto()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 6
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %6
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 4
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %7
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 5
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %8
%36 = call i32 @time(i32* null)
%37 = call i32 @srand(i32 %36)
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = bitcast i32* %12 to %struct.in_addr*
%42 = call i32 @inet_aton(i8* %40, %struct.in_addr* %41)
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = bitcast i32* %13 to %struct.in_addr*
%47 = call i32 @inet_aton(i8* %45, %struct.in_addr* %46)
%48 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* @AF_INET
%50 = load i32, i32* @SOCK_RAW
%51 = load i32, i32* @IPPROTO_RAW
%52 = call i32 @socket(i32 %49, i32 %50, i32 %51)
store i32 %52, i32* %10
%53 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 4)
%54 = load i32, i32* @AF_INET
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %54, i32* %55
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%57 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %56, i32 0, i32 0
%58 = call i32 @memcpy(i32* %57, i32* %13, i32 4)
%59 = load i32, i32* %7
store i32 %59, i32* %9
br label %60
60: ; preds = %86, %23
%61 = load i32, i32* %9
%62 = load i32, i32* %8
%63 = icmp ule i32 %61, %62
br i1 %63, label %64, label %89
64: ; preds = %60
%65 = load i32, i32* %9
%66 = call i32 @htons(i32 %65)
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %66, i32* %67
%68 = load i32, i32* @stdout
%69 = load i32, i32* %9
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %69)
%71 = load i32, i32* %10
%72 = load i32, i32* %12
%73 = load i32, i32* %13
%74 = load i32, i32* %6
%75 = load i32, i32* %9
%76 = call i32 (...) @rand()
%77 = srem i32 %76, 1996
%78 = call i64 @tcpip_send(i32 %71, %struct.sockaddr_in* %11, i32 %72, i32 %73, i32 %74, i32 %75, i32 0, i32 %77, i32 0, i32 1500, i32* null, i32 0)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %64
%81 = load i32, i32* @stderr
%82 = load i32, i32* %9
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %82)
%84 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %85
85: ; preds = %80, %64
br label %86
86: ; preds = %85
%87 = load i32, i32* %9
%88 = add i32 %87, 1
store i32 %88, i32* %9
br label %60
89: ; preds = %60
%90 = load i32, i32* %10
%91 = call i32 @close(i32 %90)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.in_addr = type { i32 }
@stderr = global i32 0
@.str = [62 x i8] c"usage: %s <myIP> <scannedIP> <srcPort> <startPort> <endPort>\0A\00"
@.str.1 = [5 x i8] c"line\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@stdout = global i32 0
@.str.2 = [24 x i8] c"Send packet to %u port\0A\00"
@.str.3 = [29 x i8] c"Error in sendign to port %d\0A\00"
@.str.4 = [18 x i8] c"Filed in sendto()\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = icmp eq i32 %0, 6
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 5
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = bitcast %struct.sockaddr_in* %3 to i8*
%23 = bitcast i32* %4 to i8*
%24 = bitcast i32* %5 to i8*
%25 = tail call i32 @time(i32* null)
%26 = tail call i32 @srand(i32 %25)
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = bitcast i32* %4 to %struct.in_addr*
%30 = call i32 @inet_aton(i8* %28, %struct.in_addr* %29)
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = bitcast i32* %5 to %struct.in_addr*
%34 = call i32 @inet_aton(i8* %32, %struct.in_addr* %33)
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%36 = load i32, i32* @AF_INET
%37 = load i32, i32* @SOCK_RAW
%38 = load i32, i32* @IPPROTO_RAW
%39 = call i32 @socket(i32 %36, i32 %37, i32 %38)
%40 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 4)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%44 = call i32 @memcpy(i32* %43, i32* %5, i32 4)
%45 = icmp ugt i32 %18, %21
br i1 %45, label %66, label %46
46: ; preds = %12
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
br label %48
48: ; preds = %46, %63
%49 = phi i32 [ %18, %46 ], [ %64, %63 ]
%50 = call i32 @htons(i32 %49)
store i32 %50, i32* %47
%51 = load i32, i32* @stdout
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%53 = load i32, i32* %4
%54 = load i32, i32* %5
%55 = call i32 (...) @rand()
%56 = srem i32 %55, 1996
%57 = call i64 @tcpip_send(i32 %39, %struct.sockaddr_in* %3, i32 %53, i32 %54, i32 %15, i32 %49, i32 0, i32 %56, i32 0, i32 1500, i32* null, i32 0)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %48
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %49)
%62 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %48, %59
%64 = add i32 %49, 1
%65 = icmp ugt i32 %64, %21
br i1 %65, label %66, label %48
66: ; preds = %63, %12
%67 = call i32 @close(i32 %39)
ret i32 0
}