#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int atoi(int /*<<< orphan*/);
int client_microtcp(char *, int, char *);
int client_tcp(char *, int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *);
int server_microtcp(int, char *);
int server_tcp(int, char *);
char *strdup(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int opt;
  int port;
  int exit_code = 0;
  char *filestr = NULL;
  char *ipstr = NULL;
  uint8_t is_server = 0;
  uint8_t use_microtcp = 0;
  while ((opt = getopt(argc, argv, "hsmf:p:a:")) != -1) {
    switch (opt) {
    case 's':
      is_server = 1;
      break;
    case 'm':
      use_microtcp = 1;
      break;
    case 'f':
      filestr = strdup(optarg);
      break;
    case 'p':
      port = atoi(optarg);
      break;
    case 'a':
      ipstr = strdup(optarg);
      break;
    default:
      printf("Usage: bandwidth_test [-s] [-m] -p port -f file"
             "Options:\n"
             "   -s                  If set, the program runs as server. "
             "Otherwise as client.\n"
             "   -m                  If set, the program uses the microTCP "
             "implementation. Otherwise the normal TCP.\n"
             "   -f <string>         If -s is set the -f option specifies the "
             "filename of the file that will be saved.\n"
             "                       If not, is the source file at the client "
             "side that will be sent to the server.\n"
             "   -p <int>            The listening port of the server\n"
             "   -a <string>         The IP address of the server. This option "
             "is ignored if the tool runs in server mode.\n"
             "   -h                  prints this help\n");
      exit(EXIT_FAILURE);
    }
  }
  if (is_server) {
    if (use_microtcp) {
      exit_code = server_microtcp(port, filestr);
    } else {
      exit_code = server_tcp(port, filestr);
    }
  } else {
    if (use_microtcp) {
      exit_code = client_microtcp(ipstr, port, filestr);
    } else {
      exit_code = client_tcp(ipstr, port, filestr);
    }
  }
  free(filestr);
  free(ipstr);
  return exit_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe63(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     129e <main+0xfe>
mov    -0x14(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x12,%eax
ja     127f <main+0xdf>
mov    -0x40(%rbp),%rax
lea    0xde6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x34(%rbp)
jmp    1299 <main+0xf9>
movl   $0x1,-0x38(%rbp)
jmp    1299 <main+0xf9>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   10c0 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    1299 <main+0xf9>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1299 <main+0xf9>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10c0 <strdup@plt>
mov    %rax,-0x30(%rbp)
jmp    1299 <main+0xf9>
lea    0xdd0(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    11db <main+0x3b>
cmpl   $0x0,-0x34(%rbp)
je     12da <main+0x13a>
cmpl   $0x0,-0x38(%rbp)
je     12c6 <main+0x126>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1070 <server_microtcp@plt>
mov    %eax,-0x1c(%rbp)
jmp    12d5 <main+0x135>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <server_tcp@plt>
mov    %eax,-0x1c(%rbp)
jmp    1314 <main+0x174>
cmpl   $0x0,-0x38(%rbp)
je     12fc <main+0x15c>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   10a0 <client_microtcp@plt>
mov    %eax,-0x1c(%rbp)
jmp    130f <main+0x16f>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1030 <client_tcp@plt>
mov    %eax,-0x1c(%rbp)
jmp    1314 <main+0x174>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%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,%rbp
mov    %edi,%ebx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0xe8b(%rip),%r13
lea    0xe38(%rip),%r14
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %r12d,%r12d
xor    %r15d,%r15d
mov    %r15d,%ecx
nopw   0x0(%rax,%rax,1)
mov    %ecx,%r15d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1080 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x6d,%eax
je     11e0 <main+0x40>
lea    -0x61(%rax),%ecx
cmp    $0x12,%ecx
ja     1250 <main+0xb0>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   10c0 <strdup@plt>
mov    %rax,(%rsp)
jmp    11d4 <main+0x34>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   10c0 <strdup@plt>
mov    %rax,0x8(%rsp)
jmp    11d4 <main+0x34>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,0x14(%rsp)
jmp    11d4 <main+0x34>
mov    $0x1,%r12d
jmp    11d4 <main+0x34>
cmp    $0xffffffff,%eax
jne    12e4 <main+0x144>
test   %r12d,%r12d
je     1276 <main+0xd6>
test   %r15d,%r15d
mov    0x14(%rsp),%edi
je     1295 <main+0xf5>
mov    0x8(%rsp),%rbp
mov    %rbp,%rsi
call   1070 <server_microtcp@plt>
jmp    12a2 <main+0x102>
test   %r15d,%r15d
mov    0x14(%rsp),%esi
je     12ab <main+0x10b>
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdx
call   10a0 <client_microtcp@plt>
jmp    12bf <main+0x11f>
mov    0x8(%rsp),%rbp
mov    %rbp,%rsi
call   1060 <server_tcp@plt>
mov    %eax,%r14d
mov    (%rsp),%rbx
jmp    12c2 <main+0x122>
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdx
call   1030 <client_tcp@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6b(%rip),%rdi
call   1050 <puts@plt>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"hsmf:p:a:\00"
@optarg = global i32 0
@.str.1 = [652 x i8] c"Usage: bandwidth_test [-s] [-m] -p port -f fileOptions:\0A -s If set, the program runs as server. Otherwise as client.\0A -m If set, the program uses the microTCP implementation. Otherwise the normal TCP.\0A -f <string> If -s is set the -f option specifies the filename of the file that will be saved.\0A If not, is the source file at the client side that will be sent to the server.\0A -p <int> The listening port of the server\0A -a <string> The IP address of the server. This option is ignored if the tool runs in server mode.\0A -h prints this help\0A\00"
@EXIT_FAILURE = global i32 0
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 i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i8* null, i8** %9
store i8* null, i8** %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %13
13: ; preds = %35, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %6
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %36
18: ; preds = %13
%19 = load i32, i32* %6
switch i32 %19, label %31 [
i32 115, label %20
i32 109, label %21
i32 102, label %22
i32 112, label %25
i32 97, label %28
]
20: ; preds = %18
store i32 1, i32* %11
br label %35
21: ; preds = %18
store i32 1, i32* %12
br label %35
22: ; preds = %18
%23 = load i32, i32* @optarg
%24 = call i8* @strdup(i32 %23)
store i8* %24, i8** %9
br label %35
25: ; preds = %18
%26 = load i32, i32* @optarg
%27 = call i32 @atoi(i32 %26)
store i32 %27, i32* %7
br label %35
28: ; preds = %18
%29 = load i32, i32* @optarg
%30 = call i8* @strdup(i32 %29)
store i8* %30, i8** %10
br label %35
31: ; preds = %18
%32 = call i32 @printf(i8* getelementptr inbounds ([652 x i8], [652 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %28, %25, %22, %21, %20
br label %13
36: ; preds = %13
%37 = load i32, i32* %11
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %51
39: ; preds = %36
%40 = load i32, i32* %12
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* %7
%44 = load i8*, i8** %9
%45 = call i32 @server_microtcp(i32 %43, i8* %44)
store i32 %45, i32* %8
br label %50
46: ; preds = %39
%47 = load i32, i32* %7
%48 = load i8*, i8** %9
%49 = call i32 @server_tcp(i32 %47, i8* %48)
store i32 %49, i32* %8
br label %50
50: ; preds = %46, %42
br label %65
51: ; preds = %36
%52 = load i32, i32* %12
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %51
%55 = load i8*, i8** %10
%56 = load i32, i32* %7
%57 = load i8*, i8** %9
%58 = call i32 @client_microtcp(i8* %55, i32 %56, i8* %57)
store i32 %58, i32* %8
br label %64
59: ; preds = %51
%60 = load i8*, i8** %10
%61 = load i32, i32* %7
%62 = load i8*, i8** %9
%63 = call i32 @client_tcp(i8* %60, i32 %61, i8* %62)
store i32 %63, i32* %8
br label %64
64: ; preds = %59, %54
br label %65
65: ; preds = %64, %50
%66 = load i8*, i8** %9
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %10
%69 = call i32 @free(i8* %68)
%70 = load i32, i32* %8
ret i32 %70
}

LLVM IR (-O2):
@.str = [10 x i8] c"hsmf:p:a:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@str = [651 x i8] c"Usage: bandwidth_test [-s] [-m] -p port -f fileOptions:\0A -s If set, the program runs as server. Otherwise as client.\0A -m If set, the program uses the microTCP implementation. Otherwise the normal TCP.\0A -f <string> If -s is set the -f option specifies the filename of the file that will be saved.\0A If not, is the source file at the client side that will be sent to the server.\0A -p <int> The listening port of the server\0A -a <string> The IP address of the server. This option is ignored if the tool runs in server mode.\0A -h prints this help\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %27, %2
%4 = phi i32 [ %29, %27 ], [ undef, %2 ]
%5 = phi i8* [ %10, %27 ], [ null, %2 ]
%6 = phi i8* [ %15, %27 ], [ null, %2 ]
%7 = phi i32 [ %19, %27 ], [ 0, %2 ]
%8 = phi i32 [ %22, %27 ], [ 0, %2 ]
br label %9
9: ; preds = %3, %24
%10 = phi i8* [ %5, %3 ], [ %26, %24 ]
%11 = phi i8* [ %6, %3 ], [ %15, %24 ]
%12 = phi i32 [ %7, %3 ], [ %19, %24 ]
%13 = phi i32 [ %8, %3 ], [ %22, %24 ]
br label %14
14: ; preds = %9, %30
%15 = phi i8* [ %11, %9 ], [ %32, %30 ]
%16 = phi i32 [ %12, %9 ], [ %19, %30 ]
%17 = phi i32 [ %13, %9 ], [ %22, %30 ]
br label %18
18: ; preds = %21, %14
%19 = phi i32 [ %16, %14 ], [ 1, %21 ]
%20 = phi i32 [ %17, %14 ], [ %22, %21 ]
br label %21
21: ; preds = %21, %18
%22 = phi i32 [ %20, %18 ], [ 1, %21 ]
%23 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
switch i32 %23, label %33 [
i32 -1, label %37
i32 115, label %18
i32 109, label %21
i32 102, label %24
i32 112, label %27
i32 97, label %30
]
24: ; preds = %21
%25 = load i32, i32* @optarg
%26 = tail call i8* @strdup(i32 %25)
br label %9
27: ; preds = %21
%28 = load i32, i32* @optarg
%29 = tail call i32 @atoi(i32 %28)
br label %3
30: ; preds = %21
%31 = load i32, i32* @optarg
%32 = tail call i8* @strdup(i32 %31)
br label %14
33: ; preds = %21
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([651 x i8], [651 x i8]* @str, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %21
%38 = icmp eq i32 %19, 0
%39 = icmp eq i32 %22, 0
br i1 %38, label %45, label %40
40: ; preds = %37
br i1 %39, label %43, label %41
41: ; preds = %40
%42 = tail call i32 @server_microtcp(i32 %4, i8* %10)
br label %50
43: ; preds = %40
%44 = tail call i32 @server_tcp(i32 %4, i8* %10)
br label %50
45: ; preds = %37
br i1 %39, label %48, label %46
46: ; preds = %45
%47 = tail call i32 @client_microtcp(i8* %15, i32 %4, i8* %10)
br label %50
48: ; preds = %45
%49 = tail call i32 @client_tcp(i8* %15, i32 %4, i8* %10)
br label %50
50: ; preds = %46, %48, %41, %43
%51 = phi i32 [ %42, %41 ], [ %44, %43 ], [ %47, %46 ], [ %49, %48 ]
%52 = tail call i32 @free(i8* %10)
%53 = tail call i32 @free(i8* %15)
ret i32 %51
}