#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*/ exit(int);
char getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int check_arguments(int argc, char **argv, char *bootIP, int *bootport,
                    int *ringport, char *externalIP, char *option,
                    int *DEBUG_MODE) {
  strcpy(bootIP, "tejo.tecnico.ulisboa.pt");
  *bootport = 58000;
  *ringport = 40000;
  if (argc != 1) {
    if ((argc > 8) || (argc <= 1) || argc % 2 == 0) {
      printf("\nProgram called with incorrect arguments.\n");
      printf("Invoke the program as the following: ./ddt -t ringport -i bootIP "
             "-p bootport\n\n");
      printf("From debug mode use: -h 1\n");
      exit(1);
    }
  }
  while ((*option = getopt(argc, argv, "t:i:p:e:h:")) != -1) {
    switch (*option) {
    case 't':
      *ringport = atoi(optarg);
      break;
    case 'i':
      strcpy(bootIP, optarg);
      break;
    case 'p':
      *bootport = atoi(optarg);
      break;
    case 'e':
      strcpy(externalIP, optarg);
      break;
    case 'h':
      *DEBUG_MODE = atoi(optarg);
      break;
    default:
      printf("The expected arguments don't have the proper format. Application "
             "Aborted.\n");
      exit(2);
    }
  }
  printf("\nWelcome to your favorite p2p client! You have chosen the following "
         "specifications: \n\n");
  printf("\tSelected ringport: %i\n", *ringport);
  printf("\tSelected bootIP: %s\n", bootIP);
  printf("\tSelected bootport: %i\n\n", *bootport);
  printf("Type 'help' to show the available commands.\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<check_arguments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xebe(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
movl   $0xe290,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x9c40,(%rax)
cmpl   $0x1,-0x4(%rbp)
je     1206 <check_arguments+0xb6>
cmpl   $0x8,-0x4(%rbp)
jg     11cd <check_arguments+0x7d>
cmpl   $0x1,-0x4(%rbp)
jle    11cd <check_arguments+0x7d>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1201 <check_arguments+0xb1>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1206 <check_arguments+0xb6>
jmp    120b <check_arguments+0xbb>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xed4(%rip),%rdx
call   1050 <getopt@plt>
mov    0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12fe <check_arguments+0x1ae>
mov    0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff9b,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xf,%eax
ja     12e1 <check_arguments+0x191>
mov    -0x38(%rbp),%rax
lea    0xdac(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d94(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    12f9 <check_arguments+0x1a9>
mov    -0x18(%rbp),%rdi
mov    0x2d74(%rip),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
jmp    12f9 <check_arguments+0x1a9>
mov    0x2d60(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12f9 <check_arguments+0x1a9>
mov    -0x30(%rbp),%rdi
mov    0x2d40(%rip),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
jmp    12f9 <check_arguments+0x1a9>
mov    0x2d2c(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    12f9 <check_arguments+0x1a9>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
jmp    120b <check_arguments+0xbb>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_arguments>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x20(%rsp)
mov    %r8,%r15
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xebb(%rip),%rsi
mov    %rdx,0x10(%rsp)
mov    %rdx,%rdi
call   1030 <strcpy@plt>
mov    %r14,0x18(%rsp)
movl   $0xe290,(%r14)
mov    %r15,0x8(%rsp)
movl   $0x9c40,(%r15)
cmp    $0x1,%ebp
je     11c6 <check_arguments+0x66>
lea    -0x9(%rbp),%eax
cmp    $0xfffffff9,%eax
jb     12f6 <check_arguments+0x196>
mov    %ebp,%eax
and    $0x1,%eax
je     12f6 <check_arguments+0x196>
mov    0x60(%rsp),%r14
lea    0xe86(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <getopt@plt>
mov    %al,(%r14)
cmp    $0xff,%al
je     127a <check_arguments+0x11a>
lea    0xe12(%rip),%r15
mov    0x2e03(%rip),%r13
lea    0xe5c(%rip),%r12
jmp    1222 <check_arguments+0xc2>
mov    0x0(%r13),%rdi
call   1070 <atoi@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1060 <getopt@plt>
mov    %al,(%r14)
cmp    $0xff,%al
je     127a <check_arguments+0x11a>
movsbl %al,%eax
add    $0xffffff9b,%eax
cmp    $0xf,%eax
ja     12e0 <check_arguments+0x180>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x0(%r13),%rsi
mov    0x20(%rsp),%rdi
call   1030 <strcpy@plt>
jmp    120e <check_arguments+0xae>
mov    0x0(%r13),%rsi
mov    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
jmp    120e <check_arguments+0xae>
mov    0x0(%r13),%rdi
call   1070 <atoi@plt>
mov    0x68(%rsp),%rcx
jmp    120c <check_arguments+0xac>
mov    0x0(%r13),%rdi
call   1070 <atoi@plt>
mov    0x18(%rsp),%rcx
jmp    120c <check_arguments+0xac>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%esi
lea    0xdcf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd9(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%rax
mov    (%rax),%esi
lea    0xdd5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"tejo.tecnico.ulisboa.pt\00"
@.str.1 = [43 x i8] c"\0AProgram called with incorrect arguments.\0A\00"
@.str.2 = [79 x i8] c"Invoke the program as the following: ./ddt -t ringport -i bootIP -p bootport\0A\0A\00"
@.str.3 = [27 x i8] c"From debug mode use: -h 1\0A\00"
@.str.4 = [11 x i8] c"t:i:p:e:h:\00"
@optarg = global i8* null
@.str.5 = [75 x i8] c"The expected arguments don't have the proper format. Application Aborted.\0A\00"
@.str.6 = [87 x i8] c"\0AWelcome to your favorite p2p client! You have chosen the following specifications: \0A\0A\00"
@.str.7 = [24 x i8] c"\09Selected ringport: %i\0A\00"
@.str.8 = [22 x i8] c"\09Selected bootIP: %s\0A\00"
@.str.9 = [25 x i8] c"\09Selected bootport: %i\0A\0A\00"
@.str.10 = [46 x i8] c"Type 'help' to show the available commands.\0A\0A\00"
define i32 @check_arguments(i32 %0, i8** %1, i8* %2, i32* %3, i32* %4, i8* %5, i8* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32*
store i32 %0, i32* %9
store i8** %1, i8*** %10
store i8* %2, i8** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i8* %5, i8** %14
store i8* %6, i8** %15
store i32* %7, i32** %16
%17 = load i8*, i8** %11
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%19 = load i32*, i32** %12
store i32 58000, i32* %19
%20 = load i32*, i32** %13
store i32 40000, i32* %20
%21 = load i32, i32* %9
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %39
23: ; preds = %8
%24 = load i32, i32* %9
%25 = icmp sgt i32 %24, 8
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = load i32, i32* %9
%28 = icmp sle i32 %27, 1
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* %9
%31 = srem i32 %30, 2
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29, %26, %23
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %29
br label %39
39: ; preds = %38, %8
br label %40
40: ; preds = %74, %39
%41 = load i32, i32* %9
%42 = load i8**, i8*** %10
%43 = call signext i8 @getopt(i32 %41, i8** %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%44 = load i8*, i8** %15
store i8 %43, i8* %44
%45 = sext i8 %43 to i32
%46 = icmp ne i32 %45, -1
br i1 %46, label %47, label %75
47: ; preds = %40
%48 = load i8*, i8** %15
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
switch i32 %50, label %71 [
i32 116, label %51
i32 105, label %55
i32 112, label %59
i32 101, label %63
i32 104, label %67
]
51: ; preds = %47
%52 = load i8*, i8** @optarg
%53 = call i32 @atoi(i8* %52)
%54 = load i32*, i32** %13
store i32 %53, i32* %54
br label %74
55: ; preds = %47
%56 = load i8*, i8** %11
%57 = load i8*, i8** @optarg
%58 = call i32 @strcpy(i8* %56, i8* %57)
br label %74
59: ; preds = %47
%60 = load i8*, i8** @optarg
%61 = call i32 @atoi(i8* %60)
%62 = load i32*, i32** %12
store i32 %61, i32* %62
br label %74
63: ; preds = %47
%64 = load i8*, i8** %14
%65 = load i8*, i8** @optarg
%66 = call i32 @strcpy(i8* %64, i8* %65)
br label %74
67: ; preds = %47
%68 = load i8*, i8** @optarg
%69 = call i32 @atoi(i8* %68)
%70 = load i32*, i32** %16
store i32 %69, i32* %70
br label %74
71: ; preds = %47
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.5, i64 0, i64 0))
%73 = call i32 @exit(i32 2)
unreachable
74: ; preds = %67, %63, %59, %55, %51
br label %40
75: ; preds = %40
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.6, i64 0, i64 0))
%77 = load i32*, i32** %13
%78 = load i32, i32* %77
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %78)
%80 = load i8*, i8** %11
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %80)
%82 = load i32*, i32** %12
%83 = load i32, i32* %82
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %83)
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"tejo.tecnico.ulisboa.pt\00"
@.str.4 = [11 x i8] c"t:i:p:e:h:\00"
@optarg = global i8* null
@.str.7 = [24 x i8] c"\09Selected ringport: %i\0A\00"
@.str.8 = [22 x i8] c"\09Selected bootIP: %s\0A\00"
@.str.9 = [25 x i8] c"\09Selected bootport: %i\0A\0A\00"
@str = [86 x i8] c"\0AWelcome to your favorite p2p client! You have chosen the following specifications: \0A\00"
@str.11 = [45 x i8] c"Type 'help' to show the available commands.\0A\00"
@str.12 = [74 x i8] c"The expected arguments don't have the proper format. Application Aborted.\00"
@str.13 = [42 x i8] c"\0AProgram called with incorrect arguments.\00"
@str.14 = [78 x i8] c"Invoke the program as the following: ./ddt -t ringport -i bootIP -p bootport\0A\00"
@str.15 = [26 x i8] c"From debug mode use: -h 1\00"
define i32 @check_arguments(i32 %0, i8** %1, i8* %2, i32* nocapture %3, i32* nocapture %4, i8* %5, i8* nocapture writeonly %6, i32* nocapture writeonly %7) {
%9 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 58000, i32* %3
store i32 40000, i32* %4
%10 = icmp eq i32 %0, 1
br i1 %10, label %22, label %11
11: ; preds = %8
%12 = add i32 %0, -9
%13 = icmp ult i32 %12, -7
%14 = and i32 %0, 1
%15 = icmp eq i32 %14, 0
%16 = or i1 %13, %15
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.13, i64 0, i64 0))
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.14, i64 0, i64 0))
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.15, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %11, %8
%23 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i8 %23, i8* %6
%24 = icmp eq i8 %23, -1
br i1 %24, label %49, label %25
25: ; preds = %22, %46
%26 = phi i8 [ %47, %46 ], [ %23, %22 ]
%27 = sext i8 %26 to i32
switch i32 %27, label %43 [
i32 116, label %28
i32 105, label %31
i32 112, label %34
i32 101, label %37
i32 104, label %40
]
28: ; preds = %25
%29 = load i8*, i8** @optarg
%30 = tail call i32 @atoi(i8* %29)
store i32 %30, i32* %4
br label %46
31: ; preds = %25
%32 = load i8*, i8** @optarg
%33 = tail call i32 @strcpy(i8* %2, i8* %32)
br label %46
34: ; preds = %25
%35 = load i8*, i8** @optarg
%36 = tail call i32 @atoi(i8* %35)
store i32 %36, i32* %3
br label %46
37: ; preds = %25
%38 = load i8*, i8** @optarg
%39 = tail call i32 @strcpy(i8* %5, i8* %38)
br label %46
40: ; preds = %25
%41 = load i8*, i8** @optarg
%42 = tail call i32 @atoi(i8* %41)
store i32 %42, i32* %7
br label %46
43: ; preds = %25
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str.12, i64 0, i64 0))
%45 = tail call i32 @exit(i32 2)
unreachable
46: ; preds = %40, %37, %34, %31, %28
%47 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i8 %47, i8* %6
%48 = icmp eq i8 %47, -1
br i1 %48, label %49, label %25
49: ; preds = %46, %22
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @str, i64 0, i64 0))
%51 = load i32, i32* %4
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %51)
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %2)
%54 = load i32, i32* %3
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i32 %54)
%56 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.11, i64 0, i64 0))
ret i32 0
}