#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 */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcp_traffic(char *, int, int);
int /*<<< orphan*/ udp_traffic(char *, int, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("    Usage: web_client PROTOCOL PACKET_SIZE\n"
           "       PROTOCOL = 0 (UDP) or 1 (TCP)\n"
           "       PACKET_SIZE = n (packet size to send)\n");
    return -1;
  }
  if (atoi(argv[1]) > 1 || atoi(argv[1]) < 0) {
    printf("    Error: PROTOCOL = 0 (UDP) or 1 (TCP)\n");
    return -1;
  }
  if (atoi(argv[2]) > 1500 || atoi(argv[2]) < 64) {
    printf("    Error: 64 <= PACKET_SIZE <= 1500\n");
    return -1;
  }
  switch (atoi(argv[1])) {
  case 0:
    udp_traffic("localhost", 8080, atoi(argv[2]));
    break;
  case 1:
    tcp_traffic("localhost", 8080, atoi(argv[2]));
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1178 <main+0x38>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <main+0x13e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
cmp    $0x1,%eax
jg     11a4 <main+0x64>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
cmp    $0x0,%eax
jge    11bc <main+0x7c>
lea    0xed3(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <main+0x13e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
cmp    $0x5dc,%eax
jg     11ea <main+0xaa>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
cmp    $0x40,%eax
jge    1202 <main+0xc2>
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127e <main+0x13e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
test   %eax,%eax
je     1232 <main+0xf2>
jmp    1221 <main+0xe1>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1257 <main+0x117>
jmp    1277 <main+0x137>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%edx
lea    0xe86(%rip),%rdi
mov    $0x1f90,%esi
call   1060 <udp_traffic@plt>
jmp    1277 <main+0x137>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%edx
lea    0xe61(%rip),%rdi
mov    $0x1f90,%esi
call   1040 <tcp_traffic@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1162 <main+0x22>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
cmp    $0x2,%eax
jb     117c <main+0x3c>
lea    0xecf(%rip),%rdi
jmp    1169 <main+0x29>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
lea    -0x5dd(%rax),%ecx
cmp    $0xfffffa62,%ecx
ja     119e <main+0x5e>
lea    0xe6e(%rip),%rdi
jmp    1169 <main+0x29>
xor    %ebx,%ebx
cmp    $0x1,%ebp
je     11be <main+0x7e>
test   %ebp,%ebp
jne    1173 <main+0x33>
lea    0xe50(%rip),%rdi
mov    $0x1f90,%esi
mov    %eax,%edx
call   1060 <udp_traffic@plt>
jmp    1173 <main+0x33>
lea    0xe3b(%rip),%rdi
mov    $0x1f90,%esi
mov    %eax,%edx
call   1040 <tcp_traffic@plt>
jmp    1173 <main+0x33>

LLVM IR (-O0):
@.str = [126 x i8] c" Usage: web_client PROTOCOL PACKET_SIZE\0A PROTOCOL = 0 (UDP) or 1 (TCP)\0A PACKET_SIZE = n (packet size to send)\0A\00"
@.str.1 = [42 x i8] c" Error: PROTOCOL = 0 (UDP) or 1 (TCP)\0A\00"
@.str.2 = [38 x i8] c" Error: 64 <= PACKET_SIZE <= 1500\0A\00"
@.str.3 = [10 x i8] c"localhost\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 3
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
%15 = icmp sgt i32 %14, 1
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16, %10
%23 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
24: ; preds = %16
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
%29 = icmp sgt i32 %28, 1500
br i1 %29, label %36, label %30
30: ; preds = %24
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
%35 = icmp slt i32 %34, 64
br i1 %35, label %36, label %38
36: ; preds = %30, %24
%37 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
38: ; preds = %30
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @atoi(i8* %41)
switch i32 %42, label %55 [
i32 0, label %43
i32 1, label %49
]
43: ; preds = %38
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
%48 = call i32 @udp_traffic(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 8080, i32 %47)
br label %55
49: ; preds = %38
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32 @atoi(i8* %52)
%54 = call i32 @tcp_traffic(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 8080, i32 %53)
br label %55
55: ; preds = %38, %49, %43
store i32 0, i32* %3
br label %56
56: ; preds = %55, %36, %22, %8
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str.3 = [10 x i8] c"localhost\00"
@str = [37 x i8] c" Error: 64 <= PACKET_SIZE <= 1500\00"
@str.4 = [41 x i8] c" Error: PROTOCOL = 0 (UDP) or 1 (TCP)\00"
@str.5 = [125 x i8] c" Usage: web_client PROTOCOL PACKET_SIZE\0A PROTOCOL = 0 (UDP) or 1 (TCP)\0A PACKET_SIZE = n (packet size to send)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([125 x i8], [125 x i8]* @str.5, i64 0, i64 0))
br label %26
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp ugt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.4, i64 0, i64 0))
br label %26
13: ; preds = %6
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = add i32 %16, -1501
%18 = icmp ult i32 %17, -1437
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %26
21: ; preds = %13
switch i32 %9, label %26 [
i32 0, label %22
i32 1, label %24
]
22: ; preds = %21
%23 = tail call i32 @udp_traffic(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 8080, i32 %16)
br label %26
24: ; preds = %21
%25 = tail call i32 @tcp_traffic(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 8080, i32 %16)
br label %26
26: ; preds = %22, %24, %21, %19, %11, %4
%27 = phi i32 [ -1, %4 ], [ -1, %11 ], [ -1, %19 ], [ 0, %21 ], [ 0, %24 ], [ 0, %22 ]
ret i32 %27
}