#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*/ client(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ server(int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  const char usage[] = "Usage:  for server: _chat [-p PORT]\n\tfor client: "
                       "_chat [-p PORT] hostname\n";
  int port = 50543;
  if (argc == 3 || argc == 4) {
    if (strcmp(argv[1], "-p")) {
      fprintf(stderr, usage);
      return -1;
    }
    sscanf(argv[2], "%d", &port);
    printf("connection port is %d\n", port);
  }
  if (argc == 2 || argc == 4) {
    if (argc == 2)
      client(port, argv[1]);
    else
      client(port, argv[3]);
  } else if (argc == 1 || argc == 3) {
    server(port);
  } else
    fprintf(stderr, usage);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x4b,%edx
call   1060 <memcpy@plt>
movl   $0xc56f,-0x64(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b6 <main+0x46>
cmpl   $0x4,-0x8(%rbp)
jne    1219 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe86(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11f2 <main+0x82>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a0 <main+0x130>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4d(%rip),%rsi
lea    -0x64(%rbp),%rdx
call   1080 <sscanf@plt>
mov    -0x64(%rbp),%esi
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     122d <main+0xbd>
cmpl   $0x4,-0x8(%rbp)
jne    1261 <main+0xf1>
cmpl   $0x2,-0x8(%rbp)
jne    124c <main+0xdc>
mov    -0x64(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1090 <client@plt>
jmp    125c <main+0xec>
mov    -0x64(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1090 <client@plt>
jmp    1299 <main+0x129>
cmpl   $0x1,-0x8(%rbp)
je     1275 <main+0x105>
cmpl   $0x3,-0x8(%rbp)
jne    1282 <main+0x112>
mov    -0x64(%rbp),%edi
call   1070 <server@plt>
jmp    1294 <main+0x124>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
call   1050 <fprintf@plt>
jmp    1299 <main+0x129>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
movups 0xec8(%rip),%xmm0
movups %xmm0,0x4b(%rsp)
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe79(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe5d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0xc56f,0xc(%rsp)
lea    -0x3(%rbx),%eax
cmp    $0x1,%eax
ja     120c <main+0xac>
mov    0x8(%r14),%rdi
lea    0xe88(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e7 <main+0x87>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    125c <main+0xfc>
mov    0x10(%r14),%rdi
lea    0xe5c(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
mov    0xc(%rsp),%esi
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
cmp    $0x4,%ebx
je     1225 <main+0xc5>
cmp    $0x2,%ebx
jne    1234 <main+0xd4>
mov    0xc(%rsp),%edi
mov    0x8(%r14),%rsi
call   1080 <client@plt>
jmp    125a <main+0xfa>
mov    0xc(%rsp),%edi
mov    0x18(%r14),%rsi
call   1080 <client@plt>
jmp    125a <main+0xfa>
and    $0xfffffffd,%ebx
cmp    $0x1,%ebx
jne    1247 <main+0xe7>
mov    0xc(%rsp),%edi
call   1060 <server@plt>
jmp    125a <main+0xfa>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.usage = [75 x i8] c"Usage: for server: _chat [-p PORT]\0A\09for client: _chat [-p PORT] hostname\0A\00"
@.str = [3 x i8] c"-p\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"connection port is %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [75 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [75 x i8]* %6 to i8*
store i32 50543, i32* %7
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 3
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 4
br i1 %13, label %14, label %31
14: ; preds = %11, %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds [75 x i8], [75 x i8]* %6, i64 0, i64 0
%23 = call i32 @fprintf(i32 %21, i8* %22)
store i32 -1, i32* %3
br label %68
24: ; preds = %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%29 = load i32, i32* %7
%30 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %24, %11
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 2
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 4
br i1 %36, label %37, label %53
37: ; preds = %34, %31
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 2
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load i32, i32* %7
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @client(i32 %41, i8* %44)
br label %52
46: ; preds = %37
%47 = load i32, i32* %7
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = call i32 @client(i32 %47, i8* %50)
br label %52
52: ; preds = %46, %40
br label %67
53: ; preds = %34
%54 = load i32, i32* %4
%55 = icmp eq i32 %54, 1
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = load i32, i32* %4
%58 = icmp eq i32 %57, 3
br i1 %58, label %59, label %62
59: ; preds = %56, %53
%60 = load i32, i32* %7
%61 = call i32 @server(i32 %60)
br label %66
62: ; preds = %56
%63 = load i32, i32* @stderr
%64 = getelementptr inbounds [75 x i8], [75 x i8]* %6, i64 0, i64 0
%65 = call i32 @fprintf(i32 %63, i8* %64)
br label %66
66: ; preds = %62, %59
br label %67
67: ; preds = %66, %52
store i32 0, i32* %3
br label %68
68: ; preds = %67, %20
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@__const.main.usage = [75 x i8] c"Usage: for server: _chat [-p PORT]\0A\09for client: _chat [-p PORT] hostname\0A\00"
@.str = [3 x i8] c"-p\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [23 x i8] c"connection port is %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [75 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [75 x i8], [75 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 50543, i32* %4
%7 = add i32 %0, -3
%8 = icmp ult i32 %7, 2
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* %5)
br label %43
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%21 = load i32, i32* %4
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %2, %17
switch i32 %0, label %34 [
i32 2, label %24
i32 4, label %29
]
24: ; preds = %23
%25 = load i32, i32* %4
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @client(i32 %25, i8* %27)
br label %43
29: ; preds = %23
%30 = load i32, i32* %4
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = call i32 @client(i32 %30, i8* %32)
br label %43
34: ; preds = %23
%35 = and i32 %0, -3
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %4
%39 = call i32 @server(i32 %38)
br label %43
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* %5)
br label %43
43: ; preds = %29, %24, %40, %37, %14
%44 = phi i32 [ -1, %14 ], [ 0, %37 ], [ 0, %40 ], [ 0, %24 ], [ 0, %29 ]
ret i32 %44
}