#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void parse_arguments(int argc, char **argv, int *server_port,
                     char **forward_name, int *forward_port) {
  if (argc < 3) {
    fprintf(stderr, "Not enough arguments\n");
    fprintf(stderr, "Syntax:  %s listen_port forward_host [forward_port]\n",
            argv[0]);
    exit(1);
  }
  *server_port = atoi(argv[1]);
  if (*server_port < 1) {
    fprintf(stderr, "Listen port is invalid\n");
    exit(1);
  }
  *forward_name = argv[2];
  if (argc == 3) {
    *forward_port = *server_port;
  } else {
    *forward_port = atoi(argv[3]);
    if (*forward_port < 1) {
      fprintf(stderr, "Forwarding port is invalid\n");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<parse_arguments>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x3,-0x4(%rbp)
jge    1194 <parse_arguments+0x64>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jge    11d7 <parse_arguments+0xa7>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x3,-0x4(%rbp)
jne    1201 <parse_arguments+0xd1>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    1249 <parse_arguments+0x119>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0x1,(%rax)
jge    1244 <parse_arguments+0x114>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1249 <parse_arguments+0x119>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_arguments>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    1186 <parse_arguments+0x56>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %edi,%ebp
mov    0x8(%rbx),%rdi
call   1040 <atoi@plt>
mov    %eax,(%r12)
test   %eax,%eax
jle    11bc <parse_arguments+0x8c>
mov    0x10(%rbx),%rcx
mov    %rcx,(%r15)
cmp    $0x3,%ebp
jne    116d <parse_arguments+0x3d>
mov    %eax,(%r14)
jmp    117d <parse_arguments+0x4d>
mov    0x18(%rbx),%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14)
test   %eax,%eax
jle    11ce <parse_arguments+0x9e>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e53(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe69(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
jmp    11de <parse_arguments+0xae>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Not enough arguments\0A\00"
@.str.1 = [53 x i8] c"Syntax: %s listen_port forward_host [forward_port]\0A\00"
@.str.2 = [24 x i8] c"Listen port is invalid\0A\00"
@.str.3 = [28 x i8] c"Forwarding port is invalid\0A\00"
define void @parse_arguments(i32 %0, i8** %1, i32* %2, i8** %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i8**
%10 = alloca i32*
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i8** %3, i8*** %9
store i32* %4, i32** %10
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %22
13: ; preds = %5
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %7
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %5
%23 = load i8**, i8*** %7
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
%27 = load i32*, i32** %8
store i32 %26, i32* %27
%28 = load i32*, i32** %8
%29 = load i32, i32* %28
%30 = icmp slt i32 %29, 1
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %22
%36 = load i8**, i8*** %7
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = load i8**, i8*** %9
store i8* %38, i8** %39
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, 3
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32*, i32** %8
%44 = load i32, i32* %43
%45 = load i32*, i32** %10
store i32 %44, i32* %45
br label %60
46: ; preds = %35
%47 = load i8**, i8*** %7
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
%51 = load i32*, i32** %10
store i32 %50, i32* %51
%52 = load i32*, i32** %10
%53 = load i32, i32* %52
%54 = icmp slt i32 %53, 1
br i1 %54, label %55, label %59
55: ; preds = %46
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %46
br label %60
60: ; preds = %59, %42
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Not enough arguments\0A\00"
@.str.1 = [53 x i8] c"Syntax: %s listen_port forward_host [forward_port]\0A\00"
@.str.2 = [24 x i8] c"Listen port is invalid\0A\00"
@.str.3 = [28 x i8] c"Forwarding port is invalid\0A\00"
define void @parse_arguments(i32 %0, i8** nocapture %1, i32* nocapture %2, i8** nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %14
7: ; preds = %5
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
store i32 %17, i32* %2
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %14
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %3
%26 = icmp eq i32 %0, 3
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 %17, i32* %4
br label %37
28: ; preds = %23
%29 = getelementptr inbounds i8*, i8** %1, i64 3
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
store i32 %31, i32* %4
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %28, %27
ret void
}