#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 /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isdigit(char);
char *malloc(int);
int /*<<< orphan*/ print_usage_details();
int /*<<< orphan*/ printf(char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int parse_server_args(int argc, char **argv, int *server_port) {
  int numPortChars, counter;
  char *szPort;
  int iPort;
  if (argc < 2) {
    print_usage_details();
    printf("Starting a server\n");
    printf("Had less than 2 arguments\n.");
    return -1;
  } else if (argc == 2) {
    *server_port = 1111;
    return 0;
  }
  if (strncmp(argv[2], "--port=", 7) == 0) {
    numPortChars = strlen(argv[2]) - 7 + 1;
    szPort = malloc(numPortChars * sizeof(char));
    strncpy(szPort, argv[2] + 7, numPortChars);
    szPort[numPortChars] = '\0';
    counter = 0;
    while (szPort[counter] != '\0') {
      if (!isdigit(szPort[counter])) {
        print_usage_details();
        printf("Found a character in the port number\n");
        return -1;
      }
      counter++;
    }
    iPort = atoi(szPort);
    if (iPort > 65535) {
      print_usage_details();
      printf("Port number was greater than 65535\n");
      return -1;
    }
    *server_port = iPort;
    free(szPort);
  } else
    *server_port = 1111;
  return 0;
}


x86 assembly (clang, -O0):
<parse_server_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d8 <parse_server_args+0x48>
mov    $0x0,%al
call   1090 <print_usage_details@plt>
lea    0xe45(%rip),%rdi
call   1080 <printf@plt>
lea    0xe4c(%rip),%rdi
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <parse_server_args+0x1a0>
cmpl   $0x2,-0x8(%rbp)
jne    11f8 <parse_server_args+0x68>
mov    -0x18(%rbp),%rax
movl   $0x457,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1330 <parse_server_args+0x1a0>
jmp    11fd <parse_server_args+0x6d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe23(%rip),%rsi
mov    $0x7,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    131f <parse_server_args+0x18f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <strlen@plt>
sub    $0x7,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
add    $0x7,%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     12d0 <parse_server_args+0x140>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isdigit@plt>
cmp    $0x0,%eax
jne    12c2 <parse_server_args+0x132>
mov    $0x0,%al
call   1090 <print_usage_details@plt>
lea    0xd86(%rip),%rdi
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <parse_server_args+0x1a0>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1274 <parse_server_args+0xe4>
mov    -0x28(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffff,-0x2c(%rbp)
jle    1308 <parse_server_args+0x178>
mov    $0x0,%al
call   1090 <print_usage_details@plt>
lea    0xd66(%rip),%rdi
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <parse_server_args+0x1a0>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1329 <parse_server_args+0x199>
mov    -0x18(%rbp),%rax
movl   $0x457,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_server_args>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x1,%edi
jg     11d4 <parse_server_args+0x34>
xor    %eax,%eax
call   10a0 <print_usage_details@plt>
lea    0xeb0(%rip),%rdi
call   1070 <puts@plt>
lea    0xe38(%rip),%rdi
call   1090 <printf@plt>
mov    $0xffffffff,%eax
jmp    1202 <parse_server_args+0x62>
mov    %rdx,%r15
cmp    $0x2,%edi
je     11f9 <parse_server_args+0x59>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xe32(%rip),%rsi
mov    $0x7,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     120c <parse_server_args+0x6c>
movl   $0x457,(%r15)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x10(%rbx),%rdi
call   1080 <strlen@plt>
movslq %eax,%r13
lea    -0x6(%r13),%r12
mov    %r12d,%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rsi
add    $0x7,%rsi
mov    %rax,%rdi
mov    %r12d,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x6(%r14,%r13,1)
mov    (%r14),%al
test   %al,%al
je     1267 <parse_server_args+0xc7>
lea    0x1(%r14),%rbx
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1060 <isdigit@plt>
test   %eax,%eax
je     1286 <parse_server_args+0xe6>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1250 <parse_server_args+0xb0>
mov    %r14,%rdi
call   10c0 <atoi@plt>
cmp    $0x10000,%eax
jl     12a3 <parse_server_args+0x103>
xor    %eax,%eax
call   10a0 <print_usage_details@plt>
lea    0xda0(%rip),%rdi
jmp    1294 <parse_server_args+0xf4>
xor    %eax,%eax
call   10a0 <print_usage_details@plt>
lea    0xdb3(%rip),%rdi
call   1070 <puts@plt>
mov    $0xffffffff,%eax
jmp    1202 <parse_server_args+0x62>
mov    %eax,(%r15)
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1200 <parse_server_args+0x60>

LLVM IR (-O0):
@.str = [19 x i8] c"Starting a server\0A\00"
@.str.1 = [28 x i8] c"Had less than 2 arguments\0A.\00"
@.str.2 = [8 x i8] c"--port=\00"
@.str.3 = [38 x i8] c"Found a character in the port number\0A\00"
@.str.4 = [36 x i8] c"Port number was greater than 65535\0A\00"
define i32 @parse_server_args(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = call i32 (...) @print_usage_details()
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %91
18: ; preds = %3
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i32*, i32** %7
store i32 1111, i32* %22
store i32 0, i32* %4
br label %91
23: ; preds = %18
br label %24
24: ; preds = %23
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %88
30: ; preds = %24
%31 = load i8**, i8*** %6
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 1
%40 = trunc i64 %39 to i32
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %10
%42 = load i8*, i8** %10
%43 = load i8**, i8*** %6
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %45, i64 7
%47 = load i32, i32* %8
%48 = call i32 @strncpy(i8* %42, i8* %46, i32 %47)
%49 = load i8*, i8** %10
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
store i32 0, i32* %9
br label %53
53: ; preds = %72, %30
%54 = load i8*, i8** %10
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %75
61: ; preds = %53
%62 = load i8*, i8** %10
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i8, i8* %65
%67 = call i32 @isdigit(i8 signext %66)
%68 = icmp ne i32 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %61
%70 = call i32 (...) @print_usage_details()
%71 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
br label %91
72: ; preds = %61
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
br label %53
75: ; preds = %53
%76 = load i8*, i8** %10
%77 = call i32 @atoi(i8* %76)
store i32 %77, i32* %11
%78 = load i32, i32* %11
%79 = icmp sgt i32 %78, 65535
br i1 %79, label %80, label %83
80: ; preds = %75
%81 = call i32 (...) @print_usage_details()
%82 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %4
br label %91
83: ; preds = %75
%84 = load i32, i32* %11
%85 = load i32*, i32** %7
store i32 %84, i32* %85
%86 = load i8*, i8** %10
%87 = call i32 @free(i8* %86)
br label %90
88: ; preds = %24
%89 = load i32*, i32** %7
store i32 1111, i32* %89
br label %90
90: ; preds = %88, %83
store i32 0, i32* %4
br label %91
91: ; preds = %90, %80, %69, %21, %14
%92 = load i32, i32* %4
ret i32 %92
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"Had less than 2 arguments\0A.\00"
@.str.2 = [8 x i8] c"--port=\00"
@str = [35 x i8] c"Port number was greater than 65535\00"
@str.5 = [37 x i8] c"Found a character in the port number\00"
@str.6 = [18 x i8] c"Starting a server\00"
define i32 @parse_server_args(i32 %0, i8** nocapture %1, i32* nocapture writeonly %2) {
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = tail call i32 (...) @print_usage_details()
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %51
9: ; preds = %3
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %12
11: ; preds = %9
store i32 1111, i32* %2
br label %51
12: ; preds = %9
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %50
17: ; preds = %12
%18 = load i8*, i8** %13
%19 = tail call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, -6
%21 = sext i32 %20 to i64
%22 = tail call i8* @malloc(i32 %20)
%23 = load i8*, i8** %13
%24 = getelementptr inbounds i8, i8* %23, i64 7
%25 = tail call i32 @strncpy(i8* %22, i8* %24, i32 %20)
%26 = getelementptr inbounds i8, i8* %22, i64 %21
store i8 0, i8* %26
%27 = load i8, i8* %22
%28 = icmp eq i8 %27, 0
br i1 %28, label %42, label %33
29: ; preds = %33
%30 = getelementptr inbounds i8, i8* %22, i64 %38
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %17, %29
%34 = phi i64 [ %38, %29 ], [ 0, %17 ]
%35 = phi i8 [ %31, %29 ], [ %27, %17 ]
%36 = tail call i32 @isdigit(i8 signext %35)
%37 = icmp eq i32 %36, 0
%38 = add nuw i64 %34, 1
br i1 %37, label %39, label %29
39: ; preds = %33
%40 = tail call i32 (...) @print_usage_details()
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.5, i64 0, i64 0))
br label %51
42: ; preds = %29, %17
%43 = tail call i32 @atoi(i8* %22)
%44 = icmp sgt i32 %43, 65535
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = tail call i32 (...) @print_usage_details()
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %51
48: ; preds = %42
store i32 %43, i32* %2
%49 = tail call i32 @free(i8* %22)
br label %51
50: ; preds = %12
store i32 1111, i32* %2
br label %51
51: ; preds = %48, %50, %45, %39, %11, %5
%52 = phi i32 [ -1, %5 ], [ 0, %11 ], [ -1, %39 ], [ -1, %45 ], [ 0, %50 ], [ 0, %48 ]
ret i32 %52
}