#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*/ endwin();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void error_handler(int error_no, int mode) {
  endwin();
  switch (error_no) {
  case -1:
    perror("Error creating socket");
    break;
  case -29:
    perror("Closing socket failed!");
    break;
  case -2:
    perror("Error binding. Port not free");
    break;
  case -3:
    perror("Error launching listener");
    break;
  case -4:
    perror("Error when forking");
    break;
  case -11:
    perror("Error connecting");
    break;
  case -12:
    perror("Error disconnecting");
    break;
  case -8:
    perror("Error: connection to peer lost!");
  case -13:
    perror("Error sending");
    break;
  case -14:
    perror("Error receiving");
    break;
  case -21:
    printf("ERROR: Invalid argument!\n\tUsage: server -p <port>\n");
    break;
  case -22:
    printf("ERROR: Maximum number of games\n");
    break;
  case -31:
    printf("ERROR: Invalid argument!\n\tUsage: client [-i <server ip>] [-p "
           "<server port>] [-n <player name>]\n");
    break;
  case -32:
    printf("ERROR: Invalid port! Port has to be between %d and %d.\n", 1024,
           65535);
    break;
  case -33:
    printf("Error: Your playername must not be longer than %d characters\n",
           10);
    break;
  default:
    printf("ERROR\n");
  }
  if (mode == 1)
    exit(1);
}


x86 assembly (clang, -O0):
<error_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
xor    %eax,%eax
call   1040 <endwin@plt>
mov    -0x4(%rbp),%eax
add    $0x21,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x20,%eax
ja     1291 <error_handler+0x151>
mov    -0x10(%rbp),%rax
lea    0xe8b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeff(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf04(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf0a(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf16(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf1e(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf20(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf20(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf23(%rip),%rdi
call   1050 <perror@plt>
lea    0xf37(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf34(%rip),%rdi
call   1050 <perror@plt>
jmp    129f <error_handler+0x15f>
lea    0xf33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129f <error_handler+0x15f>
lea    0xf53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129f <error_handler+0x15f>
lea    0xf60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129f <error_handler+0x15f>
lea    0xfad(%rip),%rdi
mov    $0x400,%esi
mov    $0xffff,%edx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129f <error_handler+0x15f>
lea    0xfc8(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129f <error_handler+0x15f>
lea    0xfee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    12b3 <error_handler+0x173>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<error_handler>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <endwin@plt>
add    $0x21,%ebx
cmp    $0x20,%ebx
ja     11ae <error_handler+0x5e>
lea    0xe93(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0x1018(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cc <error_handler+0x7c>
lea    0xfcb(%rip),%rdi
mov    $0x400,%esi
mov    $0xffff,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cc <error_handler+0x7c>
lea    0x1027(%rip),%rdi
jmp    11c7 <error_handler+0x77>
lea    0x10ce(%rip),%rdi
jmp    11c7 <error_handler+0x77>
lea    0x1074(%rip),%rdi
jmp    11c7 <error_handler+0x77>
lea    0x108a(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebp
je     126c <error_handler+0x11c>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xeb7(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
lea    0xf5c(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
lea    0xf0c(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
lea    0xeed(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
lea    0xf04(%rip),%rdi
call   1060 <perror@plt>
lea    0xf18(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
lea    0xeb2(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
lea    0xe8b(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
lea    0xe22(%rip),%rdi
call   1060 <perror@plt>
jmp    11cc <error_handler+0x7c>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Error creating socket\00"
@.str.1 = [23 x i8] c"Closing socket failed!\00"
@.str.2 = [29 x i8] c"Error binding. Port not free\00"
@.str.3 = [25 x i8] c"Error launching listener\00"
@.str.4 = [19 x i8] c"Error when forking\00"
@.str.5 = [17 x i8] c"Error connecting\00"
@.str.6 = [20 x i8] c"Error disconnecting\00"
@.str.7 = [32 x i8] c"Error: connection to peer lost!\00"
@.str.8 = [14 x i8] c"Error sending\00"
@.str.9 = [16 x i8] c"Error receiving\00"
@.str.10 = [51 x i8] c"ERROR: Invalid argument!\0A\09Usage: server -p <port>\0A\00"
@.str.11 = [32 x i8] c"ERROR: Maximum number of games\0A\00"
@.str.12 = [96 x i8] c"ERROR: Invalid argument!\0A\09Usage: client [-i <server ip>] [-p <server port>] [-n <player name>]\0A\00"
@.str.13 = [56 x i8] c"ERROR: Invalid port! Port has to be between %d and %d.\0A\00"
@.str.14 = [62 x i8] c"Error: Your playername must not be longer than %d characters\0A\00"
@.str.15 = [7 x i8] c"ERROR\0A\00"
define void @error_handler(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = call i32 (...) @endwin()
%6 = load i32, i32* %3
switch i32 %6, label %37 [
i32 -1, label %7
i32 -29, label %9
i32 -2, label %11
i32 -3, label %13
i32 -4, label %15
i32 -11, label %17
i32 -12, label %19
i32 -8, label %21
i32 -13, label %23
i32 -14, label %25
i32 -21, label %27
i32 -22, label %29
i32 -31, label %31
i32 -32, label %33
i32 -33, label %35
]
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %39
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %39
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %39
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %39
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %39
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %39
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
br label %23
23: ; preds = %2, %21
%24 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %39
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %39
27: ; preds = %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.10, i64 0, i64 0))
br label %39
29: ; preds = %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0))
br label %39
31: ; preds = %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.12, i64 0, i64 0))
br label %39
33: ; preds = %2
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.13, i64 0, i64 0), i32 1024, i32 65535)
br label %39
35: ; preds = %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.14, i64 0, i64 0), i32 10)
br label %39
37: ; preds = %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
br label %39
39: ; preds = %37, %35, %33, %31, %29, %27, %25, %23, %19, %17, %15, %13, %11, %9, %7
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %39
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Error creating socket\00"
@.str.1 = [23 x i8] c"Closing socket failed!\00"
@.str.2 = [29 x i8] c"Error binding. Port not free\00"
@.str.3 = [25 x i8] c"Error launching listener\00"
@.str.4 = [19 x i8] c"Error when forking\00"
@.str.5 = [17 x i8] c"Error connecting\00"
@.str.6 = [20 x i8] c"Error disconnecting\00"
@.str.7 = [32 x i8] c"Error: connection to peer lost!\00"
@.str.8 = [14 x i8] c"Error sending\00"
@.str.9 = [16 x i8] c"Error receiving\00"
@.str.13 = [56 x i8] c"ERROR: Invalid port! Port has to be between %d and %d.\0A\00"
@.str.14 = [62 x i8] c"Error: Your playername must not be longer than %d characters\0A\00"
@str = [95 x i8] c"ERROR: Invalid argument!\0A\09Usage: client [-i <server ip>] [-p <server port>] [-n <player name>]\00"
@str.16 = [31 x i8] c"ERROR: Maximum number of games\00"
@str.17 = [50 x i8] c"ERROR: Invalid argument!\0A\09Usage: server -p <port>\00"
@str.18 = [6 x i8] c"ERROR\00"
define void @error_handler(i32 %0, i32 %1) {
%3 = tail call i32 (...) @endwin()
switch i32 %0, label %34 [
i32 -1, label %4
i32 -29, label %6
i32 -2, label %8
i32 -3, label %10
i32 -4, label %12
i32 -11, label %14
i32 -12, label %16
i32 -8, label %18
i32 -13, label %20
i32 -14, label %22
i32 -21, label %24
i32 -22, label %26
i32 -31, label %28
i32 -32, label %30
i32 -33, label %32
]
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %36
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %36
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %36
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %36
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %36
14: ; preds = %2
%15 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %36
16: ; preds = %2
%17 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %36
18: ; preds = %2
%19 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
br label %20
20: ; preds = %2, %18
%21 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %36
22: ; preds = %2
%23 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %36
24: ; preds = %2
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.17, i64 0, i64 0))
br label %36
26: ; preds = %2
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.16, i64 0, i64 0))
br label %36
28: ; preds = %2
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([95 x i8], [95 x i8]* @str, i64 0, i64 0))
br label %36
30: ; preds = %2
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.13, i64 0, i64 0), i32 1024, i32 65535)
br label %36
32: ; preds = %2
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.14, i64 0, i64 0), i32 10)
br label %36
34: ; preds = %2
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.18, i64 0, i64 0))
br label %36
36: ; preds = %34, %32, %30, %28, %26, %24, %22, %20, %16, %14, %12, %10, %8, %6, %4
%37 = icmp eq i32 %1, 1
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %36
ret void
}