#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 EXIT_FAILURE;
scalar_t__ EXIT_SUCCESS;
int /*<<< orphan*/ print_err(char *, ...);
int /*<<< orphan*/ print_help();
scalar_t__ strcmp(char *, char *);
long strtol(char *, char **, int);
int parse_arguments(int argc, char *argv[], long *port) {
  char *endptr = NULL;
  if (argc == 2 && strcmp(argv[1], "--help") == EXIT_SUCCESS) {
    print_help();
    return EXIT_SUCCESS;
  } else if (argc == 3 && strcmp(argv[1], "-p") == EXIT_SUCCESS) {
    *port = strtol(argv[2], &endptr, 10);
    if (*endptr != '\0') {
      print_err("Port '%s' is not a number", argv[2]);
      return EXIT_FAILURE;
    }
  } else {
    print_err("Please enter valid arguments");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<parse_arguments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11a2 <parse_arguments+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8c(%rip),%rsi
call   1040 <strcmp@plt>
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    11a2 <parse_arguments+0x62>
mov    $0x0,%al
call   1060 <print_help@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    125d <parse_arguments+0x11d>
cmpl   $0x3,-0x8(%rbp)
jne    122c <parse_arguments+0xec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4c(%rip),%rsi
call   1040 <strcmp@plt>
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
jne    122c <parse_arguments+0xec>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1227 <parse_arguments+0xe7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <print_err@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <parse_arguments+0x11d>
jmp    124b <parse_arguments+0x10b>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <print_err@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <parse_arguments+0x11d>
jmp    1250 <parse_arguments+0x110>
mov    0x2d81(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_arguments>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
cmp    $0x3,%edi
je     1186 <parse_arguments+0x46>
cmp    $0x2,%edi
jne    11d9 <parse_arguments+0x99>
mov    0x8(%rbx),%rdi
lea    0xe96(%rip),%rsi
call   1040 <strcmp@plt>
mov    0x2e62(%rip),%rbx
cmp    (%rbx),%rax
jne    11d9 <parse_arguments+0x99>
xor    %eax,%eax
call   1060 <print_help@plt>
mov    (%rbx),%eax
jmp    11f0 <parse_arguments+0xb0>
mov    %rdx,%r14
mov    0x8(%rbx),%rdi
lea    0xe73(%rip),%rsi
call   1040 <strcmp@plt>
mov    0x2e38(%rip),%r15
cmp    (%r15),%rax
jne    11d9 <parse_arguments+0x99>
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,(%r14)
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11fa <parse_arguments+0xba>
mov    0x10(%rbx),%rsi
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1030 <print_err@plt>
jmp    11e7 <parse_arguments+0xa7>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1030 <print_err@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r15),%eax
jmp    11f0 <parse_arguments+0xb0>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@EXIT_SUCCESS = global i64 0
@.str.1 = [3 x i8] c"-p\00"
@.str.2 = [26 x i8] c"Port '%s' is not a number\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [29 x i8] c"Please enter valid arguments\00"
define i32 @parse_arguments(i32 %0, i8** %1, i64* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i8*
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
store i8* null, i8** %8
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = load i64, i64* @EXIT_SUCCESS
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = call i32 (...) @print_help()
%20 = load i64, i64* @EXIT_SUCCESS
%21 = trunc i64 %20 to i32
store i32 %21, i32* %4
br label %56
22: ; preds = %11, %3
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %49
25: ; preds = %22
%26 = load i8**, i8*** %6
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = load i64, i64* @EXIT_SUCCESS
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %49
32: ; preds = %25
%33 = load i8**, i8*** %6
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i64 @strtol(i8* %35, i8** %8, i32 10)
%37 = load i64*, i64** %7
store i64 %36, i64* %37
%38 = load i8*, i8** %8
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %32
%43 = load i8**, i8*** %6
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 (i8*, ...) @print_err(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
store i32 %47, i32* %4
br label %56
48: ; preds = %32
br label %52
49: ; preds = %25, %22
%50 = call i32 (i8*, ...) @print_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
store i32 %51, i32* %4
br label %56
52: ; preds = %48
br label %53
53: ; preds = %52
%54 = load i64, i64* @EXIT_SUCCESS
%55 = trunc i64 %54 to i32
store i32 %55, i32* %4
br label %56
56: ; preds = %53, %49, %42, %18
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@EXIT_SUCCESS = global i64 0
@.str.1 = [3 x i8] c"-p\00"
@.str.2 = [26 x i8] c"Port '%s' is not a number\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [29 x i8] c"Please enter valid arguments\00"
define i32 @parse_arguments(i32 %0, i8** nocapture %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
switch i32 %0, label %33 [
i32 2, label %6
i32 3, label %16
]
6: ; preds = %3
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = load i64, i64* @EXIT_SUCCESS
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %33
12: ; preds = %6
%13 = tail call i32 (...) @print_help()
%14 = load i64, i64* @EXIT_SUCCESS
%15 = trunc i64 %14 to i32
br label %39
16: ; preds = %3
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = load i64, i64* @EXIT_SUCCESS
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %16
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @strtol(i8* %24, i8** %4, i32 10)
store i64 %25, i64* %2
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %22
%30 = load i8*, i8** %23
%31 = tail call i32 (i8*, ...) @print_err(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
br label %39
33: ; preds = %6, %3, %16
%34 = tail call i32 (i8*, ...) @print_err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
br label %39
36: ; preds = %22
%37 = load i64, i64* @EXIT_SUCCESS
%38 = trunc i64 %37 to i32
br label %39
39: ; preds = %36, %33, %29, %12
%40 = phi i32 [ %15, %12 ], [ %32, %29 ], [ %38, %36 ], [ %35, %33 ]
ret i32 %40
}