#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 */
typedef int /*<<< orphan*/ words;

/* Variables and functions */
int atoi(char *);
int chopString(char *, char *, char **, int);
int /*<<< orphan*/ errAbort(char *);
char *strchr(char *, char);
int parsePasvPort(char *rs) {
  char *words[7];
  int wordCount;
  char *rsStart = strchr(rs, '(');
  char *rsEnd = strchr(rs, ')');
  int result = 0;
  rsStart++;
  *rsEnd = 0;
  wordCount =
      chopString(rsStart, ",", words, (sizeof(words) / sizeof((words)[0])));
  if (wordCount != 6)
    errAbort("PASV reply does not parse correctly");
  result = atoi(words[4]) * 256 + atoi(words[5]);
  return result;
}


x86 assembly (clang, -O0):
<parsePasvPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x28,%esi
call   1040 <strchr@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x29,%esi
call   1040 <strchr@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe67(%rip),%rsi
mov    $0x7,%ecx
call   1030 <chopString@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x6,-0x44(%rbp)
je     11bc <parsePasvPort+0x7c>
lea    0xe4b(%rip),%rdi
call   1050 <errAbort@plt>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
shl    $0x8,%eax
mov    %eax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsePasvPort>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r14
mov    $0x28,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x29,%esi
call   1040 <strchr@plt>
add    $0x1,%rbx
movb   $0x0,(%rax)
lea    0xe8e(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    $0x7,%ecx
call   1030 <chopString@plt>
cmp    $0x6,%eax
je     1193 <parsePasvPort+0x53>
lea    0xe74(%rip),%rdi
call   1050 <errAbort@plt>
mov    0x20(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
mov    0x28(%rsp),%rdi
call   1060 <atoi@plt>
add    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [36 x i8] c"PASV reply does not parse correctly\00"
define i32 @parsePasvPort(i8* %0) {
%2 = alloca i8*
%3 = alloca [7 x i8*]
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i8* @strchr(i8* %8, i8 signext 40)
store i8* %9, i8** %5
%10 = load i8*, i8** %2
%11 = call i8* @strchr(i8* %10, i8 signext 41)
store i8* %11, i8** %6
store i32 0, i32* %7
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = load i8*, i8** %6
store i8 0, i8* %14
%15 = load i8*, i8** %5
%16 = getelementptr inbounds [7 x i8*], [7 x i8*]* %3, i64 0, i64 0
%17 = call i32 @chopString(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %16, i32 7)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 6
br i1 %19, label %20, label %22
20: ; preds = %1
%21 = call i32 @errAbort(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %1
%23 = getelementptr inbounds [7 x i8*], [7 x i8*]* %3, i64 0, i64 4
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = mul nsw i32 %25, 256
%27 = getelementptr inbounds [7 x i8*], [7 x i8*]* %3, i64 0, i64 5
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
%30 = add nsw i32 %26, %29
store i32 %30, i32* %7
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [36 x i8] c"PASV reply does not parse correctly\00"
define i32 @parsePasvPort(i8* %0) {
%2 = alloca [7 x i8*]
%3 = bitcast [7 x i8*]* %2 to i8*
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 40)
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 41)
%6 = getelementptr inbounds i8, i8* %4, i64 1
store i8 0, i8* %5
%7 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 0
%8 = call i32 @chopString(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %7, i32 7)
%9 = icmp eq i32 %8, 6
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @errAbort(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 4
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
%16 = shl nsw i32 %15, 8
%17 = getelementptr inbounds [7 x i8*], [7 x i8*]* %2, i64 0, i64 5
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
%20 = add nsw i32 %19, %16
ret i32 %20
}