#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 create_socket(char *, unsigned int);
int /*<<< orphan*/ exit(int);
char *get_ip_from_hostname(char *);
unsigned int get_servers_amount(char **);
char **get_servers_hosts(char **, unsigned int);
char **get_servers_list(int, char **);
int *get_servers_ports(char **, unsigned int);
char *get_udp_load_balancer_host(int, char **);
unsigned int get_udp_load_balancer_port(int, char **);
scalar_t__ is_help_required(int, char **);
scalar_t__ is_ip(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ run_dispatcher(char **, int);
int /*<<< orphan*/ show_help();
int main(int argc, char **argv) {
  if (is_help_required(argc, argv)) {
    show_help();
    exit(0);
  }
  unsigned int udp_load_balancer_port = get_udp_load_balancer_port(argc, argv);
  char **servers_list = get_servers_list(argc, argv);
  if (udp_load_balancer_port == 0 || servers_list == NULL) {
    show_help();
    exit(2);
  }
  unsigned int servers_amount = get_servers_amount(servers_list);
  char *udp_load_balancer_ip = get_udp_load_balancer_host(argc, argv);
  printf("Listening on %s:%d", udp_load_balancer_ip, udp_load_balancer_port);
  if (is_ip(udp_load_balancer_ip) == 0) {
    udp_load_balancer_ip = get_ip_from_hostname(udp_load_balancer_ip);
    printf(" (%s:%d)", udp_load_balancer_ip, udp_load_balancer_port);
  }
  printf("\n\nBalancing to servers:\n");
  char **servers_hosts = get_servers_hosts(servers_list, servers_amount);
  int *servers_ports = get_servers_ports(servers_list, servers_amount);
  unsigned int i;
  for (i = 0; i < servers_amount; ++i) {
    printf("    %s", servers_list[i]);
    if (is_ip(servers_hosts[i]) == 0) {
      printf(" (%s:%d)", get_ip_from_hostname(servers_hosts[i]),
             servers_ports[i]);
    }
    printf("\n");
  }
  int socket_ = create_socket(udp_load_balancer_ip, udp_load_balancer_port);
  run_dispatcher(servers_list, socket_);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <is_help_required@plt>
cmp    $0x0,%rax
je     121a <main+0x3a>
mov    $0x0,%al
call   1090 <show_help@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <get_udp_load_balancer_port@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10f0 <get_servers_list@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     124e <main+0x6e>
cmpq   $0x0,-0x20(%rbp)
jne    125f <main+0x7f>
mov    $0x0,%al
call   1090 <show_help@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <get_servers_amount@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10d0 <get_udp_load_balancer_host@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <is_ip@plt>
cmp    $0x0,%rax
jne    12c5 <main+0xe5>
mov    -0x30(%rbp),%rdi
call   10b0 <get_ip_from_hostname@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <get_servers_hosts@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10a0 <get_servers_ports@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1380 <main+0x1a0>
mov    -0x20(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1040 <is_ip@plt>
cmp    $0x0,%rax
jne    1364 <main+0x184>
mov    -0x38(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   10b0 <get_ip_from_hostname@plt>
mov    %rax,%rsi
mov    -0x40(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xcc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    12fa <main+0x11a>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10c0 <create_socket@plt>
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%esi
call   1060 <run_dispatcher@plt>
xor    %eax,%eax
add    $0x50,%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,%r14
mov    %edi,%ebp
call   1070 <is_help_required@plt>
test   %rax,%rax
jne    136b <main+0x16b>
mov    %ebp,%edi
mov    %r14,%rsi
call   10a0 <get_udp_load_balancer_port@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %r14,%rsi
call   1110 <get_servers_list@plt>
test   %r15d,%r15d
je     1379 <main+0x179>
mov    %rax,%rbx
test   %rax,%rax
je     1379 <main+0x179>
mov    %rbx,%rdi
call   1100 <get_servers_amount@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %r14,%rsi
call   10f0 <get_udp_load_balancer_host@plt>
mov    %rax,%rbp
lea    0xd94(%rip),%rdi
mov    %rax,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1060 <is_ip@plt>
test   %rax,%rax
mov    %r15d,0xc(%rsp)
je     1292 <main+0x92>
mov    %rbp,0x10(%rsp)
jmp    12b3 <main+0xb3>
mov    %rbp,%rdi
call   10d0 <get_ip_from_hostname@plt>
lea    0xd72(%rip),%rdi
mov    %rax,0x10(%rsp)
mov    %rax,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd69(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1090 <get_servers_hosts@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r12d,%esi
call   10c0 <get_servers_ports@plt>
test   %r12d,%r12d
je     1342 <main+0x142>
mov    %rax,%r13
mov    %r12d,%r15d
lea    0xd32(%rip),%r12
xor    %r14d,%r14d
jmp    1303 <main+0x103>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
cmp    %r14,%r15
je     1342 <main+0x142>
mov    (%rbx,%r14,8),%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp,%r14,8),%rdi
call   1060 <is_ip@plt>
test   %rax,%rax
jne    12f0 <main+0xf0>
mov    0x0(%rbp,%r14,8),%rdi
call   10d0 <get_ip_from_hostname@plt>
mov    0x0(%r13,%r14,4),%edx
lea    0xcdd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12f0 <main+0xf0>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   10e0 <create_socket@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <run_dispatcher@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   10b0 <show_help@plt>
xor    %edi,%edi
call   1120 <exit@plt>
xor    %eax,%eax
call   10b0 <show_help@plt>
mov    $0x2,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Listening on %s:%d\00"
@.str.1 = [9 x i8] c" (%s:%d)\00"
@.str.2 = [25 x i8] c"\0A\0ABalancing to servers:\0A\00"
@.str.3 = [7 x i8] c" %s\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8**
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i64 @is_help_required(i32 %14, i8** %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (...) @show_help()
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %2
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i32 @get_udp_load_balancer_port(i32 %22, i8** %23)
store i32 %24, i32* %6
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = call i8** @get_servers_list(i32 %25, i8** %26)
store i8** %27, i8*** %7
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %21
%31 = load i8**, i8*** %7
%32 = icmp eq i8** %31, null
br i1 %32, label %33, label %36
33: ; preds = %30, %21
%34 = call i32 (...) @show_help()
%35 = call i32 @exit(i32 2)
unreachable
36: ; preds = %30
%37 = load i8**, i8*** %7
%38 = call i32 @get_servers_amount(i8** %37)
store i32 %38, i32* %8
%39 = load i32, i32* %4
%40 = load i8**, i8*** %5
%41 = call i8* @get_udp_load_balancer_host(i32 %39, i8** %40)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %42, i32 %43)
%45 = load i8*, i8** %9
%46 = call i64 @is_ip(i8* %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %36
%49 = load i8*, i8** %9
%50 = call i8* @get_ip_from_hostname(i8* %49)
store i8* %50, i8** %9
%51 = load i8*, i8** %9
%52 = load i32, i32* %6
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %51, i32 %52)
br label %54
54: ; preds = %48, %36
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%56 = load i8**, i8*** %7
%57 = load i32, i32* %8
%58 = call i8** @get_servers_hosts(i8** %56, i32 %57)
store i8** %58, i8*** %10
%59 = load i8**, i8*** %7
%60 = load i32, i32* %8
%61 = call i32* @get_servers_ports(i8** %59, i32 %60)
store i32* %61, i32** %11
store i32 0, i32* %12
br label %62
62: ; preds = %95, %54
%63 = load i32, i32* %12
%64 = load i32, i32* %8
%65 = icmp ult i32 %63, %64
br i1 %65, label %66, label %98
66: ; preds = %62
%67 = load i8**, i8*** %7
%68 = load i32, i32* %12
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %71)
%73 = load i8**, i8*** %10
%74 = load i32, i32* %12
%75 = zext i32 %74 to i64
%76 = getelementptr inbounds i8*, i8** %73, i64 %75
%77 = load i8*, i8** %76
%78 = call i64 @is_ip(i8* %77)
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %93
80: ; preds = %66
%81 = load i8**, i8*** %10
%82 = load i32, i32* %12
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds i8*, i8** %81, i64 %83
%85 = load i8*, i8** %84
%86 = call i8* @get_ip_from_hostname(i8* %85)
%87 = load i32*, i32** %11
%88 = load i32, i32* %12
%89 = zext i32 %88 to i64
%90 = getelementptr inbounds i32, i32* %87, i64 %89
%91 = load i32, i32* %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %86, i32 %91)
br label %93
93: ; preds = %80, %66
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %95
95: ; preds = %93
%96 = load i32, i32* %12
%97 = add i32 %96, 1
store i32 %97, i32* %12
br label %62
98: ; preds = %62
%99 = load i8*, i8** %9
%100 = load i32, i32* %6
%101 = call i32 @create_socket(i8* %99, i32 %100)
store i32 %101, i32* %13
%102 = load i8**, i8*** %7
%103 = load i32, i32* %13
%104 = call i32 @run_dispatcher(i8** %102, i32 %103)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Listening on %s:%d\00"
@.str.1 = [9 x i8] c" (%s:%d)\00"
@.str.3 = [7 x i8] c" %s\00"
@str = [24 x i8] c"\0A\0ABalancing to servers:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @is_help_required(i32 %0, i8** %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 (...) @show_help()
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = tail call i32 @get_udp_load_balancer_port(i32 %0, i8** %1)
%10 = tail call i8** @get_servers_list(i32 %0, i8** %1)
%11 = icmp eq i32 %9, 0
%12 = icmp eq i8** %10, null
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = tail call i32 (...) @show_help()
%16 = tail call i32 @exit(i32 2)
unreachable
17: ; preds = %8
%18 = tail call i32 @get_servers_amount(i8** %10)
%19 = tail call i8* @get_udp_load_balancer_host(i32 %0, i8** %1)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %9)
%21 = tail call i64 @is_ip(i8* %19)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = tail call i8* @get_ip_from_hostname(i8* %19)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 %9)
br label %26
26: ; preds = %23, %17
%27 = phi i8* [ %24, %23 ], [ %19, %17 ]
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%29 = tail call i8** @get_servers_hosts(i8** %10, i32 %18)
%30 = tail call i32* @get_servers_ports(i8** %10, i32 %18)
%31 = icmp eq i32 %18, 0
br i1 %31, label %53, label %32
32: ; preds = %26
%33 = zext i32 %18 to i64
br label %34
34: ; preds = %32, %49
%35 = phi i64 [ 0, %32 ], [ %51, %49 ]
%36 = getelementptr inbounds i8*, i8** %10, i64 %35
%37 = load i8*, i8** %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds i8*, i8** %29, i64 %35
%40 = load i8*, i8** %39
%41 = tail call i64 @is_ip(i8* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %34
%44 = load i8*, i8** %39
%45 = tail call i8* @get_ip_from_hostname(i8* %44)
%46 = getelementptr inbounds i32, i32* %30, i64 %35
%47 = load i32, i32* %46
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %45, i32 %47)
br label %49
49: ; preds = %43, %34
%50 = tail call i32 @putchar(i32 10)
%51 = add nuw nsw i64 %35, 1
%52 = icmp eq i64 %51, %33
br i1 %52, label %53, label %34
53: ; preds = %49, %26
%54 = tail call i32 @create_socket(i8* %27, i32 %9)
%55 = tail call i32 @run_dispatcher(i8** %10, i32 %54)
ret i32 0
}