#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*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ ntohs(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  printf("running udp client\n");
  if (argc != 5) {
    fprintf(stderr, "usage: %s <IP> <port> <MBs> <bytes per>\n", argv[0]);
    return 1;
  }
  struct sockaddr_in servaddr;
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = ntohs(atoi(argv[2]));
  if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) != 1) {
    fprintf(stderr, "invalid IP address\n");
    return 1;
  }
  int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    perror("cannot create socket");
  }
  int total = atoi(argv[3]) << 20;
  int unit = atoi(argv[4]);
  char buf[unit];
  int i;
  for (i = 0; i < unit; ++i) {
    buf[i] = 1;
  }
  int current;
  for (current = 0; current < total;) {
    int ret = sendto(sockfd, buf, unit, 0, (struct sockaddr *)&servaddr,
                     sizeof(servaddr));
    if (ret < 0) {
      break;
    }
    current += ret;
  }
  close(sockfd);
  printf("sent %d bytes\n", current);
  return 0;
}


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)
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x5,-0x8(%rbp)
je     11f8 <main+0x58>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138c <main+0x1ec>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1080 <ntohs@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <inet_pton@plt>
cmp    $0x1,%eax
je     126f <main+0xcf>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    138c <main+0x1ec>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12a1 <main+0x101>
lea    0xdb5(%rip),%rdi
call   1090 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
shl    $0x14,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1317 <main+0x177>
mov    -0x58(%rbp),%rax
movslq -0x44(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12f1 <main+0x151>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1365 <main+0x1c5>
mov    -0x58(%rbp),%rsi
mov    -0x24(%rbp),%edi
mov    -0x2c(%rbp),%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1040 <sendto@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    1357 <main+0x1b7>
jmp    1365 <main+0x1c5>
mov    -0x4c(%rbp),%eax
add    -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    131e <main+0x17e>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x48(%rbp),%esi
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x5,%ebx
jne    12e9 <main+0x129>
lea    -0x38(%rbp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2de5(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,-0x30(%rbp)
mov    0x10(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   10a0 <ntohs@plt>
mov    %eax,-0x34(%rbp)
mov    (%rbx),%edi
mov    0x8(%r14),%rsi
mov    %r15,%rdx
call   1090 <inet_pton@plt>
cmp    $0x1,%eax
jne    1305 <main+0x145>
mov    (%rbx),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
js     1334 <main+0x174>
mov    0x18(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r12d
mov    0x20(%r14),%rdi
call   10d0 <atoi@plt>
mov    %rsp,-0x40(%rbp)
mov    %eax,%r14d
mov    %rsp,%r13
lea    0xf(%r14),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
test   %eax,%eax
jle    1290 <main+0xd0>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
shl    $0x14,%r12d
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%ebx
cmp    %r12d,%ecx
jge    12c8 <main+0x108>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
lea    -0x38(%rbp),%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
lea    (%rax,%rbx,1),%ecx
test   %eax,%eax
jns    12a0 <main+0xe0>
mov    %r15d,%edi
call   1070 <close@plt>
lea    0xd7b(%rip),%rdi
xor    %r14d,%r14d
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsp
jmp    1322 <main+0x162>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd04(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    131c <main+0x15c>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xd14(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd02(%rip),%rdi
call   10b0 <perror@plt>
jmp    124f <main+0x8f>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"running udp client\0A\00"
@stderr = global i32 0
@.str.1 = [41 x i8] c"usage: %s <IP> <port> <MBs> <bytes per>\0A\00"
@AF_INET = global i32 0
@.str.2 = [20 x i8] c"invalid IP address\0A\00"
@SOCK_DGRAM = global i32 0
@.str.3 = [21 x i8] c"cannot create socket\00"
@.str.4 = [15 x i8] c"sent %d bytes\0A\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 i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 5
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %100
24: ; preds = %2
%25 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %26, i32* %27
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = call i32 @ntohs(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* @AF_INET
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%39 = call i32 @inet_pton(i32 %34, i8* %37, i32* %38)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %44
41: ; preds = %24
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %100
44: ; preds = %24
%45 = load i32, i32* @AF_INET
%46 = load i32, i32* @SOCK_DGRAM
%47 = call i32 @socket(i32 %45, i32 %46, i32 0)
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %50, %44
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 3
%55 = load i8*, i8** %54
%56 = call i32 @atoi(i8* %55)
%57 = shl i32 %56, 20
store i32 %57, i32* %8
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 4
%60 = load i8*, i8** %59
%61 = call i32 @atoi(i8* %60)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = zext i32 %62 to i64
%64 = call i8* @llvm.stacksave()
store i8* %64, i8** %10
%65 = alloca i8, i64 %63
store i64 %63, i64* %11
store i32 0, i32* %12
br label %66
66: ; preds = %74, %52
%67 = load i32, i32* %12
%68 = load i32, i32* %9
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %77
70: ; preds = %66
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %65, i64 %72
store i8 1, i8* %73
br label %74
74: ; preds = %70
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
br label %66
77: ; preds = %66
store i32 0, i32* %13
br label %78
78: ; preds = %90, %77
%79 = load i32, i32* %13
%80 = load i32, i32* %8
%81 = icmp slt i32 %79, %80
br i1 %81, label %82, label %94
82: ; preds = %78
%83 = load i32, i32* %7
%84 = load i32, i32* %9
%85 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%86 = call i32 @sendto(i32 %83, i8* %65, i32 %84, i32 0, %struct.sockaddr* %85, i32 12)
store i32 %86, i32* %14
%87 = load i32, i32* %14
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %82
br label %94
90: ; preds = %82
%91 = load i32, i32* %14
%92 = load i32, i32* %13
%93 = add nsw i32 %92, %91
store i32 %93, i32* %13
br label %78
94: ; preds = %89, %78
%95 = load i32, i32* %7
%96 = call i32 @close(i32 %95)
%97 = load i32, i32* %13
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %97)
store i32 0, i32* %3
%99 = load i8*, i8** %10
br label %100
100: ; preds = %94, %41, %18
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str.1 = [41 x i8] c"usage: %s <IP> <port> <MBs> <bytes per>\0A\00"
@AF_INET = global i32 0
@.str.2 = [20 x i8] c"invalid IP address\0A\00"
@SOCK_DGRAM = global i32 0
@.str.3 = [21 x i8] c"cannot create socket\00"
@.str.4 = [15 x i8] c"sent %d bytes\0A\00"
@str = [19 x i8] c"running udp client\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%5 = icmp eq i32 %0, 5
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %63
10: ; preds = %2
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = tail call i32 @ntohs(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%24 = call i32 @inet_pton(i32 %20, i8* %22, i32* %23)
%25 = icmp eq i32 %24, 1
br i1 %25, label %29, label %26
26: ; preds = %10
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %61
29: ; preds = %10
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_DGRAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = shl i32 %39, 20
%41 = getelementptr inbounds i8*, i8** %1, i64 4
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = zext i32 %43 to i64
%45 = call i8* @llvm.stacksave()
%46 = alloca i8, i64 %44
%47 = icmp sgt i32 %43, 0
br i1 %47, label %48, label %49
48: ; preds = %36
br label %49
49: ; preds = %48, %36
%50 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %51
51: ; preds = %49, %54
%52 = phi i32 [ %57, %54 ], [ 0, %49 ]
%53 = icmp slt i32 %52, %40
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = call i32 @sendto(i32 %32, i8* %46, i32 %43, i32 0, %struct.sockaddr* %50, i32 12)
%56 = icmp slt i32 %55, 0
%57 = add nsw i32 %55, %52
br i1 %56, label %58, label %51
58: ; preds = %54, %51
%59 = call i32 @close(i32 %32)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %52)
br label %61
61: ; preds = %58, %26
%62 = phi i32 [ 1, %26 ], [ 0, %58 ]
br label %63
63: ; preds = %61, %6
%64 = phi i32 [ 1, %6 ], [ %62, %61 ]
ret i32 %64
}