#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(char *, char *);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ server();
int main(int argc, char **argv) {
  int c;
  int opt_count = 0;
  char *port = 0;
  char *ip = 0;
  while ((c = getopt(argc, argv, "s:p:")) != -1) {
    switch (c) {
    case 'p':
      port = optarg;
      opt_count++;
      break;
    case 's':
      ip = optarg;
      opt_count++;
      break;
    default:
      return 1;
    }
  }
  if (optind < argc) {
    printf("./chat: invalid parameters -- ");
    while (optind < argc)
      printf("'%s' ", argv[optind++]);
    printf("\n");
    return 1;
  }
  if (opt_count != 0 && opt_count != 2) {
    printf("Both port and server address are needed.\n");
    return 1;
  }
  if (opt_count == 0) {
    server();
  } else {
    client(ip, port);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11fa <main+0xba>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x70,%eax
je     11b1 <main+0x71>
jmp    11a0 <main+0x60>
mov    -0x2c(%rbp),%eax
sub    $0x73,%eax
je     11cd <main+0x8d>
jmp    11e9 <main+0xa9>
mov    0x2e40(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f5 <main+0xb5>
mov    0x2e24(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f5 <main+0xb5>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x193>
jmp    116d <main+0x2d>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    127b <main+0x13b>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1261 <main+0x121>
mov    -0x10(%rbp),%rax
mov    0x2da9(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d9b(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <main+0xda>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x193>
cmpl   $0x0,-0x18(%rbp)
je     12a9 <main+0x169>
cmpl   $0x2,-0x18(%rbp)
je     12a9 <main+0x169>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x193>
cmpl   $0x0,-0x18(%rbp)
jne    12bf <main+0x17f>
mov    $0x0,%al
call   1040 <server@plt>
jmp    12cc <main+0x18c>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <client@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0xe87(%rip),%r12
mov    0x2e78(%rip),%r14
xor    %eax,%eax
mov    %rax,(%rsp)
xor    %r15d,%r15d
jmp    119a <main+0x3a>
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rax
mov    %rax,(%rsp)
add    $0x1,%ebx
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1070 <getopt@plt>
cmp    $0x70,%eax
je     1190 <main+0x30>
cmp    $0x73,%eax
jne    11b9 <main+0x59>
mov    (%r14),%r15
add    $0x1,%ebx
jmp    119a <main+0x3a>
cmp    $0xffffffff,%eax
jne    1230 <main+0xd0>
mov    0x2e1b(%rip),%r12
cmp    %ebp,(%r12)
jge    121c <main+0xbc>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%eax
cmp    %ebp,%eax
jge    1210 <main+0xb0>
lea    0xe3c(%rip),%r14
nopl   0x0(%rax,%rax,1)
lea    0x1(%rax),%ecx
mov    %ecx,(%r12)
cltq
mov    0x0(%r13,%rax,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%eax
cmp    %ebp,%eax
jl     11f0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1230 <main+0xd0>
test   $0x7ffffffd,%ebx
je     1246 <main+0xe6>
lea    0xdff(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebx,%ebx
je     125a <main+0xfa>
mov    %r15,%rdi
mov    (%rsp),%rsi
call   1080 <client@plt>
xor    %ebx,%ebx
jmp    1235 <main+0xd5>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <server@plt>
jmp    1235 <main+0xd5>

LLVM IR (-O0):
@.str = [5 x i8] c"s:p:\00"
@optarg = global i8* null
@optind = global i32 0
@.str.1 = [31 x i8] c"./chat: invalid parameters -- \00"
@.str.2 = [6 x i8] c"'%s' \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [42 x i8] c"Both port and server address are needed.\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i8* null, i8** %8
store i8* null, i8** %9
br label %10
10: ; preds = %26, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %25 [
i32 112, label %17
i32 115, label %21
]
17: ; preds = %15
%18 = load i8*, i8** @optarg
store i8* %18, i8** %8
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %26
21: ; preds = %15
%22 = load i8*, i8** @optarg
store i8* %22, i8** %9
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %26
25: ; preds = %15
store i32 1, i32* %3
br label %65
26: ; preds = %21, %17
br label %10
27: ; preds = %10
%28 = load i32, i32* @optind
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %37, %31
%34 = load i32, i32* @optind
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = load i32, i32* @optind
%40 = add nsw i32 %39, 1
store i32 %40, i32* @optind
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8*, i8** %38, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %33
45: ; preds = %33
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %65
47: ; preds = %27
%48 = load i32, i32* %7
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i32, i32* %7
%52 = icmp ne i32 %51, 2
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %65
55: ; preds = %50, %47
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 (...) @server()
br label %64
60: ; preds = %55
%61 = load i8*, i8** %9
%62 = load i8*, i8** %8
%63 = call i32 @client(i8* %61, i8* %62)
br label %64
64: ; preds = %60, %58
store i32 0, i32* %3
br label %65
65: ; preds = %64, %53, %45, %25
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [5 x i8] c"s:p:\00"
@optarg = global i8* null
@optind = global i32 0
@.str.1 = [31 x i8] c"./chat: invalid parameters -- \00"
@.str.2 = [6 x i8] c"'%s' \00"
@str = [41 x i8] c"Both port and server address are needed.\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %12, %2
%4 = phi i32 [ 0, %2 ], [ %15, %12 ]
%5 = phi i8* [ null, %2 ], [ %13, %12 ]
%6 = phi i8* [ null, %2 ], [ %14, %12 ]
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %7, label %45 [
i32 -1, label %16
i32 112, label %8
i32 115, label %10
]
8: ; preds = %3
%9 = load i8*, i8** @optarg
br label %12
10: ; preds = %3
%11 = load i8*, i8** @optarg
br label %12
12: ; preds = %10, %8
%13 = phi i8* [ %5, %10 ], [ %9, %8 ]
%14 = phi i8* [ %11, %10 ], [ %6, %8 ]
%15 = add nuw nsw i32 %4, 1
br label %3
16: ; preds = %3
%17 = load i32, i32* @optind
%18 = icmp slt i32 %17, %0
br i1 %18, label %19, label %34
19: ; preds = %16
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @optind
%22 = icmp slt i32 %21, %0
br i1 %22, label %23, label %32
23: ; preds = %19, %23
%24 = phi i32 [ %30, %23 ], [ %21, %19 ]
%25 = add nsw i32 %24, 1
store i32 %25, i32* @optind
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @optind
%31 = icmp slt i32 %30, %0
br i1 %31, label %23, label %32
32: ; preds = %23, %19
%33 = tail call i32 @putchar(i32 10)
br label %45
34: ; preds = %16
%35 = and i32 %4, 2147483645
%36 = icmp eq i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %45
39: ; preds = %34
%40 = icmp eq i32 %4, 0
br i1 %40, label %41, label %43
41: ; preds = %39
%42 = tail call i32 (...) @server()
br label %45
43: ; preds = %39
%44 = tail call i32 @client(i8* %6, i8* %5)
br label %45
45: ; preds = %3, %41, %43, %37, %32
%46 = phi i32 [ 1, %32 ], [ 1, %37 ], [ 0, %43 ], [ 0, %41 ], [ 1, %3 ]
ret i32 %46
}