#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 */
scalar_t__ client(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ server(char *);
int main(int argc, char *argv[]) {
  if (argc == 2) {
    if (server(argv[1]) == 0)
      printf("Server: exited with success\n");
    else {
      printf("Errors with server\n");
      return -1;
    }
  } else if (argc == 3) {
    if (client(argv[1], argv[2]) == 0)
      printf("Client: exited with success\n");
    else {
      printf("Errors with client\n");
      return -1;
    }
  } else {
    printf("Invalid amount of arguments.\nUsage:\n      server: %s "
           "<portnumber>\n      client: %s <portnumber> <server ip>\n",
           argv[0], argv[0]);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1199 <main+0x69>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <server@plt>
cmp    $0x0,%rax
jne    117a <main+0x4a>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1194 <main+0x64>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1228 <main+0xf8>
jmp    1221 <main+0xf1>
cmpl   $0x3,-0x8(%rbp)
jne    11f4 <main+0xc4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <client@plt>
cmp    $0x0,%rax
jne    11d5 <main+0xa5>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ef <main+0xbf>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1228 <main+0xf8>
jmp    121c <main+0xec>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1228 <main+0xf8>
jmp    1221 <main+0xf1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x3,%edi
je     1167 <main+0x27>
cmp    $0x2,%edi
jne    1187 <main+0x47>
mov    0x8(%rsi),%rdi
call   1050 <server@plt>
test   %rax,%rax
je     11a2 <main+0x62>
lea    0xf3c(%rip),%rdi
call   1030 <puts@plt>
jmp    119b <main+0x5b>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1060 <client@plt>
test   %rax,%rax
je     11ab <main+0x6b>
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
jmp    119b <main+0x5b>
mov    (%rsi),%rdx
lea    0xe6f(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
lea    0xf06(%rip),%rdi
jmp    11b2 <main+0x72>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Server: exited with success\0A\00"
@.str.1 = [20 x i8] c"Errors with server\0A\00"
@.str.2 = [29 x i8] c"Client: exited with success\0A\00"
@.str.3 = [20 x i8] c"Errors with client\0A\00"
@.str.4 = [109 x i8] c"Invalid amount of arguments.\0AUsage:\0A server: %s <portnumber>\0A client: %s <portnumber> <server ip>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @server(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %46
18: ; preds = %14
br label %45
19: ; preds = %2
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %36
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @client(i8* %25, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %35
33: ; preds = %22
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %46
35: ; preds = %31
br label %44
36: ; preds = %19
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([109 x i8], [109 x i8]* @.str.4, i64 0, i64 0), i8* %39, i8* %42)
store i32 -1, i32* %3
br label %46
44: ; preds = %35
br label %45
45: ; preds = %44, %18
store i32 0, i32* %3
br label %46
46: ; preds = %45, %36, %33, %16
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str.4 = [109 x i8] c"Invalid amount of arguments.\0AUsage:\0A server: %s <portnumber>\0A client: %s <portnumber> <server ip>\0A\00"
@str = [19 x i8] c"Errors with client\00"
@str.5 = [28 x i8] c"Client: exited with success\00"
@str.6 = [19 x i8] c"Errors with server\00"
@str.7 = [28 x i8] c"Server: exited with success\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %23 [
i32 2, label %3
i32 3, label %12
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i64 @server(i8* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0))
br label %26
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
br label %26
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i64 @client(i8* %14, i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0))
br label %26
21: ; preds = %12
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %26
23: ; preds = %2
%24 = load i8*, i8** %1
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([109 x i8], [109 x i8]* @.str.4, i64 0, i64 0), i8* %24, i8* %24)
br label %26
26: ; preds = %8, %19, %23, %21, %10
%27 = phi i32 [ -1, %10 ], [ -1, %21 ], [ -1, %23 ], [ 0, %19 ], [ 0, %8 ]
ret i32 %27
}