#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__ atoi(char *);
int /*<<< orphan*/ client(char *, char *, scalar_t__);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char **fileAsArray(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ server(scalar_t__);
int main(int argc, char **argv) {
  if (argc < 3)
    printf("Insufficient arguments. Usage %s 0(server)/1(client) "
           "TCP_PORT_NUMBER <msg>\n",
           argv[0]);
  int s;
  int dstport;
  char *dsthost;
  char **nodes = fileAsArray("NODES");
  char **ports = fileAsArray("PORTS");
  if (atoi(argv[1]) == 0)
    server(atoi(argv[2]));
  else {
    if (argc < 4) {
      printf("Message not recieved\n");
      exit(0);
    } else {
      char *msg = argv[3];
      client(msg, nodes[0], atoi(argv[2]));
    }
  }
}


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)
cmpl   $0x3,-0x8(%rbp)
jge    1195 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
call   1070 <fileAsArray@plt>
mov    %rax,-0x28(%rbp)
lea    0xea6(%rip),%rdi
call   1070 <fileAsArray@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
cmp    $0x0,%rax
jne    11e6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %rax,%rdi
call   1040 <server@plt>
jmp    1246 <main+0xe6>
cmpl   $0x4,-0x8(%rbp)
jge    1205 <main+0xa5>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
call   1060 <client@plt>
jmp    1246 <main+0xe6>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x2,%edi
jg     118f <main+0x1f>
mov    (%rbx),%rsi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1080 <fileAsArray@plt>
mov    %rax,%r14
lea    0xead(%rip),%rdi
call   1080 <fileAsArray@plt>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
test   %rax,%rax
je     11dd <main+0x6d>
cmp    $0x3,%ebp
jle    11f5 <main+0x85>
mov    0x10(%rbx),%rdi
mov    0x18(%rbx),%rbx
mov    (%r14),%rbp
call   1060 <atoi@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1070 <client@plt>
jmp    11ee <main+0x7e>
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rax,%rdi
call   1050 <server@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [76 x i8] c"Insufficient arguments. Usage %s 0(server)/1(client) TCP_PORT_NUMBER <msg>\0A\00"
@.str.1 = [6 x i8] c"NODES\00"
@.str.2 = [6 x i8] c"PORTS\00"
@.str.3 = [22 x i8] c"Message not recieved\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8**
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %14, %2
%20 = call i8** @fileAsArray(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8** %20, i8*** %9
%21 = call i8** @fileAsArray(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8** %21, i8*** %10
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @atoi(i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i64 @atoi(i8* %30)
%32 = call i32 @server(i64 %31)
br label %53
33: ; preds = %19
%34 = load i32, i32* %4
%35 = icmp slt i32 %34, 4
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %33
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
store i8* %42, i8** %11
%43 = load i8*, i8** %11
%44 = load i8**, i8*** %9
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i64 @atoi(i8* %49)
%51 = call i32 @client(i8* %43, i8* %46, i64 %50)
br label %52
52: ; preds = %39
br label %53
53: ; preds = %52, %27
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [76 x i8] c"Insufficient arguments. Usage %s 0(server)/1(client) TCP_PORT_NUMBER <msg>\0A\00"
@.str.1 = [6 x i8] c"NODES\00"
@.str.2 = [6 x i8] c"PORTS\00"
@str = [21 x i8] c"Message not recieved\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %7
7: ; preds = %4, %2
%8 = tail call i8** @fileAsArray(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i8** @fileAsArray(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @atoi(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %7
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i64 @atoi(i8* %16)
%18 = tail call i32 @server(i64 %17)
br label %32
19: ; preds = %7
%20 = icmp slt i32 %0, 4
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %19
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i64 @atoi(i8* %29)
%31 = tail call i32 @client(i8* %26, i8* %27, i64 %30)
br label %32
32: ; preds = %24, %14
ret i32 0
}