#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*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int getopt(int, char **, char *);
char *optarg;
char optopt;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ server_main(int, char *);
int sh_server(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *server_port = "1234";
  char *thread_number = "2";
  int sockfd;
  int o;
  while ((o = getopt(argc, argv, "p:n:")) != -1) {
    switch (o) {
    case 'p':
      server_port = optarg;
      break;
    case 'n':
      thread_number = optarg;
      break;
    case '?':
      if (optopt == 'p') {
        fprintf(stderr, "Option %c requires an argument.\n", optopt);
      } else {
        fprintf(stderr, "Unknown argument: %c.\n", optopt);
      }
      break;
    }
  }
  printf("listening on port: %s, thread number %s\n", server_port,
         thread_number);
  sockfd = sh_server(server_port);
  server_main(sockfd, thread_number);
out:
  close(sockfd);
  printf("Done.\n");
  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)
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
je     1267 <main+0x107>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x3f,%eax
je     1207 <main+0xa7>
jmp    11bf <main+0x5f>
mov    -0x2c(%rbp),%eax
sub    $0x6e,%eax
je     11f4 <main+0x94>
jmp    11d0 <main+0x70>
mov    -0x2c(%rbp),%eax
sub    $0x70,%eax
jne    1262 <main+0x102>
jmp    11e1 <main+0x81>
mov    0x2e10(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1262 <main+0x102>
mov    0x2dfd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1262 <main+0x102>
mov    0x2dd2(%rip),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
jne    123e <main+0xde>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
mov    0x2daf(%rip),%rax
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    125d <main+0xfd>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
mov    0x2d8b(%rip),%rax
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    1262 <main+0x102>
jmp    118c <main+0x2c>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <sh_server@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <server_main@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe76(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe6f(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe65(%rip),%r12
mov    0x2e37(%rip),%r15
mov    0x2e20(%rip),%r13
lea    0xe76(%rip),%r14
jmp    11cb <main+0x5b>
nopl   0x0(%rax)
movsbl %al,%edx
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
cmp    $0x6d,%eax
jg     1210 <main+0xa0>
cmp    $0x3f,%eax
jne    1230 <main+0xc0>
movzbl (%r15),%eax
mov    0x0(%r13),%edi
cmp    $0x70,%al
jne    11c0 <main+0x50>
lea    0xe17(%rip),%rsi
mov    $0x70,%edx
call   1070 <fprintf@plt>
jmp    11cb <main+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x6e,%eax
je     1237 <main+0xc7>
cmp    $0x70,%eax
jne    11cb <main+0x5b>
mov    0x2dd7(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    11cb <main+0x5b>
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
jne    11cb <main+0x5b>
jmp    1248 <main+0xd8>
mov    0x2dba(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    11cb <main+0x5b>
lea    0xdf5(%rip),%rdi
mov    0x8(%rsp),%rbx
mov    %rbx,%rsi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <sh_server@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %rbp,%rsi
call   1080 <server_main@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xde5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"1234\00"
@.str.1 = [2 x i8] c"2\00"
@.str.2 = [5 x i8] c"p:n:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.4 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.5 = [41 x i8] c"listening on port: %s, thread number %s\0A\00"
@.str.6 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %10
10: ; preds = %34, %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.2, i64 0, i64 0))
store i32 %13, i32* %9
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %35
15: ; preds = %10
%16 = load i32, i32* %9
switch i32 %16, label %34 [
i32 112, label %17
i32 110, label %19
i32 63, label %21
]
17: ; preds = %15
%18 = load i8*, i8** @optarg
store i8* %18, i8** %6
br label %34
19: ; preds = %15
%20 = load i8*, i8** @optarg
store i8* %20, i8** %7
br label %34
21: ; preds = %15
%22 = load i8, i8* @optopt
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 112
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8, i8* @optopt
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8 signext %27)
br label %33
29: ; preds = %21
%30 = load i32, i32* @stderr
%31 = load i8, i8* @optopt
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8 signext %31)
br label %33
33: ; preds = %29, %25
br label %34
34: ; preds = %15, %33, %19, %17
br label %10
35: ; preds = %10
%36 = load i8*, i8** %6
%37 = load i8*, i8** %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %36, i8* %37)
%39 = load i8*, i8** %6
%40 = call i32 @sh_server(i8* %39)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = load i8*, i8** %7
%43 = call i32 @server_main(i32 %41, i8* %42)
br label %44
44: ; preds = %35
%45 = load i32, i32* %8
%46 = call i32 @close(i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"1234\00"
@.str.1 = [2 x i8] c"2\00"
@.str.2 = [5 x i8] c"p:n:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.4 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.5 = [41 x i8] c"listening on port: %s, thread number %s\0A\00"
@str = [6 x i8] c"Done.\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %13, %2
%4 = phi i8* [ %14, %13 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %2 ]
%5 = phi i8* [ %7, %13 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
br label %6
6: ; preds = %3, %11
%7 = phi i8* [ %5, %3 ], [ %12, %11 ]
br label %8
8: ; preds = %10, %6
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
switch i32 %9, label %10 [
i32 -1, label %23
i32 112, label %11
i32 110, label %13
i32 63, label %15
]
10: ; preds = %8, %19, %21
br label %8
11: ; preds = %8
%12 = load i8*, i8** @optarg
br label %6
13: ; preds = %8
%14 = load i8*, i8** @optarg
br label %3
15: ; preds = %8
%16 = load i8, i8* @optopt
%17 = icmp eq i8 %16, 112
%18 = load i32, i32* @stderr
br i1 %17, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8 signext 112)
br label %10
21: ; preds = %15
%22 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8 signext %16)
br label %10
23: ; preds = %8
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %7, i8* %4)
%25 = tail call i32 @sh_server(i8* %7)
%26 = tail call i32 @server_main(i32 %25, i8* %4)
%27 = tail call i32 @close(i32 %25)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret i32 0
}