#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 atoi(char *);
int client(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int server(int);
int main(int argc, char **argv) {
  if (argc < 3) {
    printf("Command should be: myprog s <port> or myprog c <port> <address>\n");
    return 1;
  }
  int port = atoi(argv[2]);
  if (port < 1024 || port > 65535) {
    printf("Port number should be equal to or larger than 1024 and smaller "
           "than 65535\n");
    return 1;
  }
  if (argv[1][0] == 'c') {
    if (argv[3] == NULL) {
      printf("NO IP address is given\n");
      return 1;
    }
    return client(argv[3], port);
  } else if (argv[1][0] == 's') {
    return server(port);
  } else {
    printf("unknown command type %s\nCommand should be: myprog s <port> or "
           "myprog c <port> <address>",
           argv[1]);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jl     11a4 <main+0x64>
cmpl   $0xffff,-0x14(%rbp)
jle    11be <main+0x7e>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
jne    1213 <main+0xd3>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
jne    11fb <main+0xbb>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1060 <client@plt>
mov    %eax,-0x4(%rbp)
jmp    1254 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    1237 <main+0xf7>
mov    -0x14(%rbp),%edi
call   1040 <server@plt>
mov    %eax,-0x4(%rbp)
jmp    1254 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jg     115f <main+0xf>
lea    0xebb(%rip),%rdi
jmp    1180 <main+0x30>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1060 <atoi@plt>
lea    -0x10000(%rax),%ecx
cmp    $0xffff03ff,%ecx
ja     118c <main+0x3c>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rbx),%rsi
mov    (%rsi),%cl
cmp    $0x73,%cl
je     11ad <main+0x5d>
cmp    $0x63,%cl
jne    11b5 <main+0x65>
mov    0x18(%rbx),%rdi
test   %rdi,%rdi
je     11c5 <main+0x75>
mov    %eax,%esi
pop    %rbx
jmp    1070 <client@plt>
mov    %eax,%edi
pop    %rbx
jmp    1050 <server@plt>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1185 <main+0x35>
lea    0xe8c(%rip),%rdi
jmp    1180 <main+0x30>

LLVM IR (-O0):
@.str = [65 x i8] c"Command should be: myprog s <port> or myprog c <port> <address>\0A\00"
@.str.1 = [75 x i8] c"Port number should be equal to or larger than 1024 and smaller than 65535\0A\00"
@.str.2 = [24 x i8] c"NO IP address is given\0A\00"
@.str.3 = [88 x i8] c"unknown command type %s\0ACommand should be: myprog s <port> or myprog c <port> <address>\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %60
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 1024
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 65535
br i1 %20, label %21, label %23
21: ; preds = %18, %11
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %60
23: ; preds = %18
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 99
br i1 %30, label %31, label %44
31: ; preds = %23
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %60
38: ; preds = %31
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 3
%41 = load i8*, i8** %40
%42 = load i32, i32* %6
%43 = call i32 @client(i8* %41, i32 %42)
store i32 %43, i32* %3
br label %60
44: ; preds = %23
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 115
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = load i32, i32* %6
%54 = call i32 @server(i32 %53)
store i32 %54, i32* %3
br label %60
55: ; preds = %44
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.3, i64 0, i64 0), i8* %58)
store i32 1, i32* %3
br label %60
60: ; preds = %55, %52, %38, %36, %21, %9
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str.3 = [88 x i8] c"unknown command type %s\0ACommand should be: myprog s <port> or myprog c <port> <address>\00"
@str = [23 x i8] c"NO IP address is given\00"
@str.4 = [74 x i8] c"Port number should be equal to or larger than 1024 and smaller than 65535\00"
@str.5 = [64 x i8] c"Command should be: myprog s <port> or myprog c <port> <address>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.5, i64 0, i64 0))
br label %30
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = add i32 %9, -65536
%11 = icmp ult i32 %10, -64512
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str.4, i64 0, i64 0))
br label %30
14: ; preds = %6
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
switch i8 %17, label %28 [
i8 99, label %18
i8 115, label %26
]
18: ; preds = %14
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %30
24: ; preds = %18
%25 = tail call i32 @client(i8* %20, i32 %9)
br label %30
26: ; preds = %14
%27 = tail call i32 @server(i32 %9)
br label %30
28: ; preds = %14
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %30
30: ; preds = %12, %22, %24, %26, %28, %4
%31 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 1, %22 ], [ %25, %24 ], [ %27, %26 ], [ 1, %28 ]
ret i32 %31
}