#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);
int sh_server(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *server_port = "1234";
  int sockfd;
  int o;
  while ((o = getopt(argc, argv, "p:")) != -1) {
    switch (o) {
    case 'p':
      server_port = 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\n", server_port);
  sockfd = sh_server(server_port);
  server_main(sockfd);
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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe76(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     1238 <main+0xd8>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x3f,%eax
je     11d8 <main+0x78>
jmp    11b4 <main+0x54>
mov    -0x24(%rbp),%eax
sub    $0x70,%eax
jne    1233 <main+0xd3>
jmp    11c5 <main+0x65>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1233 <main+0xd3>
mov    0x2e01(%rip),%rax
movsbl (%rax),%eax
cmp    $0x70,%eax
jne    120f <main+0xaf>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
mov    0x2dde(%rip),%rax
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    122e <main+0xce>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    0x2dba(%rip),%rax
movsbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    1233 <main+0xd3>
jmp    1181 <main+0x21>
mov    -0x18(%rbp),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <sh_server@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <server_main@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
lea    0xdea(%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
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe79(%rip),%rax
mov    %rax,(%rsp)
lea    0xe73(%rip),%r15
mov    0x2e47(%rip),%r14
mov    0x2e30(%rip),%r12
lea    0xe82(%rip),%r13
jmp    11bb <main+0x4b>
nopl   0x0(%rax)
movsbl %al,%edx
mov    %r13,%rsi
call   1070 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    $0x3f,%eax
je     11f0 <main+0x80>
cmp    $0xffffffff,%eax
je     120f <main+0x9f>
cmp    $0x70,%eax
jne    11bb <main+0x4b>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
jmp    11bb <main+0x4b>
nopw   0x0(%rax,%rax,1)
movzbl (%r14),%eax
mov    (%r12),%edi
cmp    $0x70,%al
jne    11b0 <main+0x40>
lea    0xe05(%rip),%rsi
mov    $0x70,%edx
call   1070 <fprintf@plt>
jmp    11bb <main+0x4b>
lea    0xe2a(%rip),%rdi
mov    (%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <sh_server@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <server_main@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%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 = [3 x i8] c"p:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.2 = [33 x i8] c"Option %c requires an argument.\0A\00"
@.str.3 = [23 x i8] c"Unknown argument: %c.\0A\00"
@.str.4 = [23 x i8] c"listening on port: %s\0A\00"
@.str.5 = [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 i32
%8 = 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
br label %9
9: ; preds = %31, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %12, i32* %8
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %32
14: ; preds = %9
%15 = load i32, i32* %8
switch i32 %15, label %31 [
i32 112, label %16
i32 63, label %18
]
16: ; preds = %14
%17 = load i8*, i8** @optarg
store i8* %17, i8** %6
br label %31
18: ; preds = %14
%19 = load i8, i8* @optopt
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 112
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i8, i8* @optopt
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8 signext %24)
br label %30
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = load i8, i8* @optopt
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8 signext %28)
br label %30
30: ; preds = %26, %22
br label %31
31: ; preds = %14, %30, %16
br label %9
32: ; preds = %9
%33 = load i8*, i8** %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %6
%36 = call i32 @sh_server(i8* %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = call i32 @server_main(i32 %37)
br label %39
39: ; preds = %32
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

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