#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;
};
typedef int /*<<< orphan*/ si_other;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int build_packet(char *, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ diep(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/, void *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  struct sockaddr_in si_other;
  int s, len;
  char buffer[1024];
  if (argc != 4) {
    fprintf(stderr, "Usage: 'udp-stress IP PORT METRIC'\n");
    exit(-1);
  }
  srand(time(NULL));
  memset(&si_other, 0, sizeof(si_other));
  si_other.sin_family = AF_INET;
  si_other.sin_port = htons(atoi(argv[2]));
  if (inet_aton(argv[1], &si_other.sin_addr) == 0) {
    fprintf(stderr, "inet_aton() failed\n");
    exit(1);
  }
  if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    diep("socket");
  len = build_packet(buffer, argv[3]);
  sendto(s, buffer, len, 0, (void *)&si_other, sizeof(si_other));
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1212 <main+0x42>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <inet_aton@plt>
cmp    $0x0,%rax
jne    128f <main+0xbf>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    12c0 <main+0xf0>
lea    0xd7d(%rip),%rdi
call   1080 <diep@plt>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   10c0 <build_packet@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
cmp    $0x4,%edi
jne    12a0 <main+0xd0>
mov    %rsi,%rbx
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2dda(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rbx),%rdi
mov    %rbp,%rsi
call   10b0 <inet_aton@plt>
test   %rax,%rax
je     12bf <main+0xef>
mov    (%r14),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1263 <main+0x93>
lea    0xdda(%rip),%rdi
call   1080 <diep@plt>
mov    0x18(%rbx),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <build_packet@plt>
mov    %rsp,%r8
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"Usage: 'udp-stress IP PORT METRIC'\0A\00"
@AF_INET = global i32 0
@.str.1 = [20 x i8] c"inet_aton() failed\0A\00"
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = call i32 @time(i32* null)
%18 = call i32 @srand(i32 %17)
%19 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %20, i32* %21
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%32 = call i64 @inet_aton(i8* %30, i32* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %16
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %16
%39 = load i32, i32* @AF_INET
%40 = load i32, i32* @SOCK_DGRAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 @diep(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %38
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @build_packet(i8* %46, i8* %49)
store i32 %50, i32* %8
%51 = load i32, i32* %7
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%53 = load i32, i32* %8
%54 = bitcast %struct.sockaddr_in* %6 to i8*
%55 = call i32 @sendto(i32 %51, i8* %52, i32 %53, i32 0, i8* %54, i32 12)
%56 = load i32, i32* %7
%57 = call i32 @close(i32 %56)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"Usage: 'udp-stress IP PORT METRIC'\0A\00"
@AF_INET = global i32 0
@.str.1 = [20 x i8] c"inet_aton() failed\0A\00"
@SOCK_DGRAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 4
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = tail call i32 @time(i32* null)
%14 = tail call i32 @srand(i32 %13)
%15 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
%21 = call i32 @htons(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%26 = call i64 @inet_aton(i8* %24, i32* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %12
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %12
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_DGRAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @diep(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %32
%40 = getelementptr inbounds i8*, i8** %1, i64 3
%41 = load i8*, i8** %40
%42 = call i32 @build_packet(i8* %6, i8* %41)
%43 = call i32 @sendto(i32 %35, i8* %6, i32 %42, i32 0, i8* %5, i32 12)
%44 = call i32 @close(i32 %35)
ret i32 0
}