#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 /*<<< orphan*/ convert_to_lowercase(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ is_valid_hostname(char *);
int /*<<< orphan*/ is_valid_ip(char *);
int /*<<< orphan*/ is_valid_port(char *);
int /*<<< orphan*/ print_cla(int, char **);
int /*<<< orphan*/ print_error_exit();
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, int /*<<< orphan*/);
int handle_input(int argc, char *argv[]) {
  int mode;
  if (argc < 2 || argc > 4) {
    print_cla(argc, argv);
    print_error_exit();
  } else {
    if (strcmp("client", convert_to_lowercase(argv[1])) == 0) {
      mode = 0;
      if (argc == 3) {
        if (!is_valid_ip(argv[2]) && !is_valid_hostname(argv[2])) {
          fprintf(stderr, "Not valid IP or hostname: %s\n", argv[2]);
          print_error_exit();
        }
      } else if (argc == 4) {
        if (!is_valid_ip(argv[2]) && !is_valid_hostname(argv[2])) {
          fprintf(stderr, "Not valid IP or hostname: %s\n", argv[2]);
          print_error_exit();
        }
        if (!is_valid_port(argv[3])) {
          fprintf(stderr,
                  "Not valid port number: %s. Enter port "
                  "number in range: %d - %d\n",
                  argv[3], 1024, 49151);
          print_error_exit();
        }
      } else {
        print_cla(argc, argv);
        print_error_exit();
      }
    } else if (strcmp("server", convert_to_lowercase(argv[1])) == 0) {
      mode = 1;
      if (argc == 3 && !is_valid_port(argv[2])) {
        fprintf(stderr,
                "Not valid port number: %s. Enter port "
                "number in range: %d - %d\n",
                argv[2], 1024, 49151);
        print_error_exit();
      }
    } else {
      fprintf(stderr, "Not a valid mode: %s\n", argv[1]);
      print_error_exit();
    }
  }
  return mode;
}


x86 assembly (clang, -O0):
<handle_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jl     11a3 <handle_input+0x23>
cmpl   $0x4,-0x4(%rbp)
jle    11bb <handle_input+0x3b>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <print_cla@plt>
mov    $0x0,%al
call   1030 <print_error_exit@plt>
jmp    13bf <handle_input+0x23f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <convert_to_lowercase@plt>
mov    %eax,%esi
lea    0xe2f(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    130d <handle_input+0x18d>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x4(%rbp)
jne    1248 <handle_input+0xc8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <is_valid_ip@plt>
cmp    $0x0,%eax
jne    1243 <handle_input+0xc3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <is_valid_hostname@plt>
cmp    $0x0,%eax
jne    1243 <handle_input+0xc3>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <print_error_exit@plt>
jmp    1308 <handle_input+0x188>
cmpl   $0x4,-0x4(%rbp)
jne    12f0 <handle_input+0x170>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <is_valid_ip@plt>
cmp    $0x0,%eax
jne    12a4 <handle_input+0x124>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <is_valid_hostname@plt>
cmp    $0x0,%eax
jne    12a4 <handle_input+0x124>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <print_error_exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <is_valid_port@plt>
cmp    $0x0,%eax
jne    12eb <handle_input+0x16b>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xd53(%rip),%rsi
mov    $0x400,%ecx
mov    $0xbfff,%r8d
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <print_error_exit@plt>
jmp    1303 <handle_input+0x183>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <print_cla@plt>
mov    $0x0,%al
call   1030 <print_error_exit@plt>
jmp    1308 <handle_input+0x188>
jmp    13ba <handle_input+0x23a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <convert_to_lowercase@plt>
mov    %eax,%esi
lea    0xd42(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    138f <handle_input+0x20f>
movl   $0x1,-0x14(%rbp)
cmpl   $0x3,-0x4(%rbp)
jne    138a <handle_input+0x20a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <is_valid_port@plt>
cmp    $0x0,%eax
jne    138a <handle_input+0x20a>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xcb4(%rip),%rsi
mov    $0x400,%ecx
mov    $0xbfff,%r8d
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <print_error_exit@plt>
jmp    13b5 <handle_input+0x235>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcc5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <print_error_exit@plt>
jmp    13ba <handle_input+0x23a>
jmp    13bf <handle_input+0x23f>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_input>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x5(%rbp),%eax
cmp    $0xfffffffc,%eax
ja     119d <handle_input+0x1d>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <print_cla@plt>
jmp    11f0 <handle_input+0x70>
mov    0x8(%rbx),%rdi
call   1090 <convert_to_lowercase@plt>
lea    0xe53(%rip),%rdi
mov    %eax,%esi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ff <handle_input+0x7f>
mov    0x8(%rbx),%rdi
call   1090 <convert_to_lowercase@plt>
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
call   1060 <strcmp@plt>
test   %rax,%rax
je     124e <handle_input+0xce>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe83(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1030 <print_error_exit@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x4,%ebp
je     1297 <handle_input+0x117>
cmp    $0x3,%ebp
jne    1315 <handle_input+0x195>
mov    0x10(%rbx),%rdi
call   10a0 <is_valid_ip@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    11f7 <handle_input+0x77>
mov    0x10(%rbx),%rdi
call   1040 <is_valid_hostname@plt>
test   %eax,%eax
jne    11f7 <handle_input+0x77>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xdc5(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    11f0 <handle_input+0x70>
mov    $0x1,%r14d
cmp    $0x3,%ebp
jne    11f7 <handle_input+0x77>
mov    0x10(%rbx),%rdi
call   1050 <is_valid_port@plt>
test   %eax,%eax
jne    11f7 <handle_input+0x77>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xdab(%rip),%rsi
mov    $0x400,%ecx
mov    $0xbfff,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%r14d
jmp    11f0 <handle_input+0x70>
mov    0x10(%rbx),%rdi
call   10a0 <is_valid_ip@plt>
test   %eax,%eax
jne    12d3 <handle_input+0x153>
mov    0x10(%rbx),%rdi
call   1040 <is_valid_hostname@plt>
test   %eax,%eax
jne    12d3 <handle_input+0x153>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xd42(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1030 <print_error_exit@plt>
mov    0x18(%rbx),%rdi
call   1050 <is_valid_port@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    11f7 <handle_input+0x77>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rbx),%rdx
lea    0xd2a(%rip),%rsi
xor    %r14d,%r14d
mov    $0x400,%ecx
mov    $0xbfff,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    11f0 <handle_input+0x70>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <print_cla@plt>
xor    %r14d,%r14d
jmp    11f0 <handle_input+0x70>

LLVM IR (-O0):
@.str = [7 x i8] c"client\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Not valid IP or hostname: %s\0A\00"
@.str.2 = [64 x i8] c"Not valid port number: %s. Enter port number in range: %d - %d\0A\00"
@.str.3 = [7 x i8] c"server\00"
@.str.4 = [22 x i8] c"Not a valid mode: %s\0A\00"
define i32 @handle_input(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 4
br i1 %10, label %11, label %16
11: ; preds = %8, %2
%12 = load i32, i32* %3
%13 = load i8**, i8*** %4
%14 = call i32 @print_cla(i32 %12, i8** %13)
%15 = call i32 (...) @print_error_exit()
br label %122
16: ; preds = %8
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @convert_to_lowercase(i8* %19)
%21 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %89
23: ; preds = %16
store i32 0, i32* %5
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %46
26: ; preds = %23
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @is_valid_ip(i8* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %45, label %32
32: ; preds = %26
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @is_valid_hostname(i8* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %32
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %4
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = call i32 (...) @print_error_exit()
br label %45
45: ; preds = %38, %32, %26
br label %88
46: ; preds = %23
%47 = load i32, i32* %3
%48 = icmp eq i32 %47, 4
br i1 %48, label %49, label %82
49: ; preds = %46
%50 = load i8**, i8*** %4
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32 @is_valid_ip(i8* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %68, label %55
55: ; preds = %49
%56 = load i8**, i8*** %4
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i32 @is_valid_hostname(i8* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %68, label %61
61: ; preds = %55
%62 = load i32, i32* @stderr
%63 = load i8**, i8*** %4
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %65)
%67 = call i32 (...) @print_error_exit()
br label %68
68: ; preds = %61, %55, %49
%69 = load i8**, i8*** %4
%70 = getelementptr inbounds i8*, i8** %69, i64 3
%71 = load i8*, i8** %70
%72 = call i32 @is_valid_port(i8* %71)
%73 = icmp ne i32 %72, 0
br i1 %73, label %81, label %74
74: ; preds = %68
%75 = load i32, i32* @stderr
%76 = load i8**, i8*** %4
%77 = getelementptr inbounds i8*, i8** %76, i64 3
%78 = load i8*, i8** %77
%79 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* %78, i32 1024, i32 49151)
%80 = call i32 (...) @print_error_exit()
br label %81
81: ; preds = %74, %68
br label %87
82: ; preds = %46
%83 = load i32, i32* %3
%84 = load i8**, i8*** %4
%85 = call i32 @print_cla(i32 %83, i8** %84)
%86 = call i32 (...) @print_error_exit()
br label %87
87: ; preds = %82, %81
br label %88
88: ; preds = %87, %45
br label %121
89: ; preds = %16
%90 = load i8**, i8*** %4
%91 = getelementptr inbounds i8*, i8** %90, i64 1
%92 = load i8*, i8** %91
%93 = call i32 @convert_to_lowercase(i8* %92)
%94 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %93)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %113
96: ; preds = %89
store i32 1, i32* %5
%97 = load i32, i32* %3
%98 = icmp eq i32 %97, 3
br i1 %98, label %99, label %112
99: ; preds = %96
%100 = load i8**, i8*** %4
%101 = getelementptr inbounds i8*, i8** %100, i64 2
%102 = load i8*, i8** %101
%103 = call i32 @is_valid_port(i8* %102)
%104 = icmp ne i32 %103, 0
br i1 %104, label %112, label %105
105: ; preds = %99
%106 = load i32, i32* @stderr
%107 = load i8**, i8*** %4
%108 = getelementptr inbounds i8*, i8** %107, i64 2
%109 = load i8*, i8** %108
%110 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* %109, i32 1024, i32 49151)
%111 = call i32 (...) @print_error_exit()
br label %112
112: ; preds = %105, %99, %96
br label %120
113: ; preds = %89
%114 = load i32, i32* @stderr
%115 = load i8**, i8*** %4
%116 = getelementptr inbounds i8*, i8** %115, i64 1
%117 = load i8*, i8** %116
%118 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %117)
%119 = call i32 (...) @print_error_exit()
br label %120
120: ; preds = %113, %112
br label %121
121: ; preds = %120, %88
br label %122
122: ; preds = %121, %11
%123 = load i32, i32* %5
ret i32 %123
}

LLVM IR (-O2):
@.str = [7 x i8] c"client\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Not valid IP or hostname: %s\0A\00"
@.str.2 = [64 x i8] c"Not valid port number: %s. Enter port number in range: %d - %d\0A\00"
@.str.3 = [7 x i8] c"server\00"
@.str.4 = [22 x i8] c"Not a valid mode: %s\0A\00"
define i32 @handle_input(i32 %0, i8** %1) {
%3 = add i32 %0, -5
%4 = icmp ult i32 %3, -3
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @print_cla(i32 %0, i8** %1)
br label %72
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @convert_to_lowercase(i8* %9)
%11 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %52
13: ; preds = %7
switch i32 %0, label %50 [
i32 3, label %14
i32 4, label %27
]
14: ; preds = %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @is_valid_ip(i8* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %75
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = tail call i32 @is_valid_hostname(i8* %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %75
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %15
%26 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %72
27: ; preds = %13
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i32 @is_valid_ip(i8* %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i8*, i8** %28
%34 = tail call i32 @is_valid_hostname(i8* %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %28
%39 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = tail call i32 (...) @print_error_exit()
br label %41
41: ; preds = %36, %32, %27
%42 = getelementptr inbounds i8*, i8** %1, i64 3
%43 = load i8*, i8** %42
%44 = tail call i32 @is_valid_port(i8* %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %75
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %42
%49 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* %48, i32 1024, i32 49151)
br label %72
50: ; preds = %13
%51 = tail call i32 @print_cla(i32 %0, i8** %1)
br label %72
52: ; preds = %7
%53 = load i8*, i8** %8
%54 = tail call i32 @convert_to_lowercase(i8* %53)
%55 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %52
%58 = icmp eq i32 %0, 3
br i1 %58, label %59, label %75
59: ; preds = %57
%60 = getelementptr inbounds i8*, i8** %1, i64 2
%61 = load i8*, i8** %60
%62 = tail call i32 @is_valid_port(i8* %61)
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %75
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = load i8*, i8** %60
%67 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), i8* %66, i32 1024, i32 49151)
br label %72
68: ; preds = %52
%69 = load i32, i32* @stderr
%70 = load i8*, i8** %8
%71 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %5, %68, %64, %23, %46, %50
%73 = phi i32 [ undef, %68 ], [ 1, %64 ], [ 0, %50 ], [ 0, %46 ], [ 0, %23 ], [ undef, %5 ]
%74 = tail call i32 (...) @print_error_exit()
br label %75
75: ; preds = %72, %41, %14, %19, %57, %59
%76 = phi i32 [ 0, %14 ], [ 0, %19 ], [ 0, %41 ], [ 1, %59 ], [ 1, %57 ], [ %73, %72 ]
ret i32 %76
}