#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*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_udp(int, struct sockaddr *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *targetaddr;
  int tgtPort = 11223;
  int pktCnt = 4;
  int sockfd;
  struct sockaddr_in servaddr;
  if (argc < 2) {
    printf("usage: udbstorm <IP addr> [num pkts] [port]\n");
    exit(1);
  }
  targetaddr = argv[1];
  if (argc > 2) {
    pktCnt = atoi(argv[2]);
  }
  if (argc > 3) {
    tgtPort = atoi(argv[3]);
  }
  printf("Targeting %s:%d with %d packets.\n", targetaddr, tgtPort, pktCnt);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(tgtPort);
  inet_pton(AF_INET, targetaddr, &servaddr.sin_addr);
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  send_udp(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr), pktCnt);
  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)
movl   $0x2bd7,-0x1c(%rbp)
movl   $0x4,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c6 <main+0x46>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11ec <main+0x6c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1206 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <inet_pton@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%ecx
mov    $0xc,%edx
call   1030 <send_udp@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jle    1262 <main+0xd2>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%r14
mov    $0x2bd7,%r13d
mov    $0x4,%r12d
cmp    $0x2,%edi
je     11de <main+0x4e>
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
cmp    $0x4,%ebp
jb     11de <main+0x4e>
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r13d
lea    0xe1b(%rip),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2dda(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%rbx),%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <inet_pton@plt>
mov    (%rbx),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%edi
mov    %r15,%rsi
mov    $0xc,%edx
mov    %r12d,%ecx
call   1040 <send_udp@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [45 x i8] c"usage: udbstorm <IP addr> [num pkts] [port]\0A\00"
@.str.1 = [34 x i8] c"Targeting %s:%d with %d packets.\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 11223, i32* %7
store i32 4, i32* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 2
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %8
br label %27
27: ; preds = %22, %16
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 3
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
br label %35
35: ; preds = %30, %27
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %36, i32 %37, i32 %38)
%40 = call i32 @bzero(%struct.sockaddr_in* %10, i32 12)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %41, i32* %42
%43 = load i32, i32* %7
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %44, i32* %45
%46 = load i32, i32* @AF_INET
%47 = load i8*, i8** %6
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%49 = call i32 @inet_pton(i32 %46, i8* %47, i32* %48)
%50 = load i32, i32* @AF_INET
%51 = load i32, i32* @SOCK_DGRAM
%52 = call i32 @socket(i32 %50, i32 %51, i32 0)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%55 = load i32, i32* %8
%56 = call i32 @send_udp(i32 %53, %struct.sockaddr* %54, i32 12, i32 %55)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [34 x i8] c"Targeting %s:%d with %d packets.\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@str = [44 x i8] c"usage: udbstorm <IP addr> [num pkts] [port]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = icmp eq i32 %0, 2
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp ugt i32 %0, 3
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
br label %22
22: ; preds = %9, %18, %13
%23 = phi i32 [ %16, %18 ], [ %16, %13 ], [ 4, %9 ]
%24 = phi i32 [ %21, %18 ], [ 11223, %13 ], [ 11223, %9 ]
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %24, i32 %23)
%26 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %27, i32* %28
%29 = tail call i32 @htons(i32 %24)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %29, i32* %30
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%33 = call i32 @inet_pton(i32 %31, i8* %11, i32* %32)
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_DGRAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i32 @send_udp(i32 %36, %struct.sockaddr* %37, i32 12, i32 %23)
ret i32 0
}