#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 BUFSIZ;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int strlcpy(char *, char *, int);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int prepare_fwds(char *cmd, char *first_fwd, char *tunnel_fwd, char *last_fwd) {
  char type, colcount, i;
  char *s, *tok;
  char buf[BUFSIZ], source[BUFSIZ], dest[BUFSIZ];
  unsigned int lport;
  s = cmd;
  if (*s == '-')
    s++;
  type = *s;
  if (type != 'L' && type != 'R' && type != 'D')
    goto parse_error;
  s++;
  if (type == 'D') {
    strlcpy(source, s, BUFSIZ);
    tok = s;
    if ((tok = strchr(tok, ':')))
      s = tok + 1;
    if ((lport = strtoul(s, NULL, 10)) == 0)
      goto parse_error;
    snprintf(first_fwd, BUFSIZ, "-L%s:127.0.0.1:%u\r", source, lport);
    snprintf(tunnel_fwd, BUFSIZ, "-L%u:127.0.0.1:%u\r", lport, lport);
    snprintf(last_fwd, BUFSIZ, "-D:%u\r", lport);
    return 0;
  }
  tok = s;
  colcount = 0;
  while ((tok = strchr(tok, ':'))) {
    tok++;
    colcount++;
  }
  if (colcount < 2 || colcount > 3)
    goto parse_error;
  strlcpy(source, s, BUFSIZ);
  tok = s;
  for (i = 0; i < colcount - 2; i++) {
    tok = strchr(tok, ':');
    tok++;
  }
  if (strlcpy(buf, tok, BUFSIZ) >= BUFSIZ)
    goto parse_error;
  tok = strchr(tok, ':');
  *tok = '\0';
  *(source + (tok - s)) = '\0';
  if ((lport = strtoul(s, NULL, 10)) == 0)
    goto parse_error;
  strlcpy(dest, tok + 1, BUFSIZ);
  if (type == 'L') {
    snprintf(first_fwd, BUFSIZ, "-L%s:127.0.0.1:%u\r", source, lport);
    snprintf(tunnel_fwd, BUFSIZ, "-L%u:127.0.0.1:%u\r", lport, lport);
    snprintf(last_fwd, BUFSIZ, "-L%u:%s\r", lport, dest);
  } else if (type == 'R') {
    snprintf(first_fwd, BUFSIZ, "-R%u:%s\r", lport, dest);
    snprintf(tunnel_fwd, BUFSIZ, "-R%u:127.0.0.1:%u\r", lport, lport);
    snprintf(last_fwd, BUFSIZ, "-R%s:127.0.0.1:%u\r", source, lport);
  }
  return 0;
parse_error:
  fprintf(stderr, "Invalid command.");
  return 1;
}


x86 assembly (clang, -O0):
<prepare_fwds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x80(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x50(%rbp)
mov    (%rax),%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x78(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x58(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11f7 <prepare_fwds+0xa7>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x4c,%eax
je     122c <prepare_fwds+0xdc>
movsbl -0x29(%rbp),%eax
cmp    $0x52,%eax
je     122c <prepare_fwds+0xdc>
movsbl -0x29(%rbp),%eax
cmp    $0x44,%eax
je     122c <prepare_fwds+0xdc>
jmp    157f <prepare_fwds+0x42f>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x44,%eax
jne    1324 <prepare_fwds+0x1d4>
mov    -0x78(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
call   1060 <strlcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     128b <prepare_fwds+0x13b>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jne    12ae <prepare_fwds+0x15e>
jmp    157f <prepare_fwds+0x42f>
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%rdi
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%r8d
lea    0xd36(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%ecx
mov    -0x64(%rbp),%r8d
lea    0xd27(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2cda(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%ecx
lea    0xd1c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    15a2 <prepare_fwds+0x452>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
movb   $0x0,-0x2a(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1365 <prepare_fwds+0x215>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x2a(%rbp),%al
add    $0x1,%al
mov    %al,-0x2a(%rbp)
jmp    1330 <prepare_fwds+0x1e0>
movsbl -0x2a(%rbp),%eax
cmp    $0x2,%eax
jl     137f <prepare_fwds+0x22f>
movsbl -0x2a(%rbp),%eax
cmp    $0x3,%eax
jle    1384 <prepare_fwds+0x234>
jmp    157f <prepare_fwds+0x42f>
mov    -0x78(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2c45(%rip),%rax
mov    (%rax),%edx
call   1060 <strlcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
movb   $0x0,-0x2b(%rbp)
movsbl -0x2b(%rbp),%eax
movsbl -0x2a(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    13e4 <prepare_fwds+0x294>
mov    -0x40(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x2b(%rbp),%al
add    $0x1,%al
mov    %al,-0x2b(%rbp)
jmp    13a6 <prepare_fwds+0x256>
mov    -0x80(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    0x2be5(%rip),%rax
mov    (%rax),%edx
call   1060 <strlcpy@plt>
mov    0x2bd7(%rip),%rcx
cmp    (%rcx),%eax
jl     140e <prepare_fwds+0x2be>
jmp    157f <prepare_fwds+0x42f>
mov    -0x40(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
mov    %rcx,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
movb   $0x0,(%rcx)
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jne    1460 <prepare_fwds+0x310>
jmp    157f <prepare_fwds+0x42f>
mov    -0x70(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x1,%rsi
mov    0x2b65(%rip),%rax
mov    (%rax),%edx
call   1060 <strlcpy@plt>
movsbl -0x29(%rbp),%eax
cmp    $0x4c,%eax
jne    14f3 <prepare_fwds+0x3a3>
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%rdi
mov    0x2b42(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%r8d
lea    0xb5d(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2b23(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%ecx
mov    -0x64(%rbp),%r8d
lea    0xb4e(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x70(%rbp),%r8
mov    -0x28(%rbp),%rdi
mov    0x2afd(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%ecx
lea    0xb46(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    156c <prepare_fwds+0x41c>
movsbl -0x29(%rbp),%eax
cmp    $0x52,%eax
jne    1567 <prepare_fwds+0x417>
mov    -0x70(%rbp),%r8
mov    -0x18(%rbp),%rdi
mov    0x2ac9(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%ecx
lea    0xb1b(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2aab(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%ecx
mov    -0x64(%rbp),%r8d
lea    0xb02(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x78(%rbp),%rcx
mov    -0x28(%rbp),%rdi
mov    0x2a85(%rip),%rax
mov    (%rax),%esi
mov    -0x64(%rbp),%r8d
lea    0xaf2(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    156c <prepare_fwds+0x41c>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
jmp    15a2 <prepare_fwds+0x452>
mov    0x2a5a(%rip),%rax
mov    (%rax),%edi
lea    0xad6(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x68(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_fwds>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,-0x48(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x38(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r13
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
xor    %eax,%eax
cmpb   $0x2d,(%rdi)
sete   %al
mov    (%rdi,%rax,1),%sil
lea    -0x44(%rsi),%ecx
cmp    $0xe,%cl
ja     13f2 <prepare_fwds+0x2a2>
movzbl %cl,%ecx
mov    $0x4101,%edx
bt     %rcx,%rdx
jae    13f2 <prepare_fwds+0x2a2>
mov    %rdi,%r14
add    %rax,%r14
add    $0x1,%r14
cmp    $0x44,%sil
jne    1279 <prepare_fwds+0x129>
mov    -0x30(%rbp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <strlcpy@plt>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %r14,%rdi
xor    %r15d,%r15d
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtoul@plt>
test   %eax,%eax
je     13f2 <prepare_fwds+0x2a2>
mov    %eax,%ebx
mov    0x2db1(%rip),%r14
mov    (%r14),%esi
lea    0xdcf(%rip),%rdx
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    (%r14),%esi
lea    0xdc6(%rip),%rdx
mov    -0x40(%rbp),%rdi
mov    %ebx,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    (%r14),%esi
lea    0xdbf(%rip),%rdx
mov    -0x48(%rbp),%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    140d <prepare_fwds+0x2bd>
mov    %r14,%rdi
mov    %rsi,-0x50(%rbp)
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     13f2 <prepare_fwds+0x2a2>
mov    $0xfc,%r12b
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
add    $0x1,%r12b
test   %rax,%rax
jne    12a0 <prepare_fwds+0x150>
cmp    $0xfe,%r12b
jb     13f2 <prepare_fwds+0x2a2>
add    $0x4,%r12b
mov    -0x30(%rbp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1060 <strlcpy@plt>
mov    %r14,%rbx
cmp    $0x3,%r12b
jb     1311 <prepare_fwds+0x1c1>
movzbl %r12b,%r15d
add    $0xfffffffe,%r15d
mov    $0x1,%r12b
mov    %r14,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
add    $0x1,%rbx
movsbl %r12b,%eax
lea    0x1(%rax),%r12d
cmp    %eax,%r15d
jg     12f0 <prepare_fwds+0x1a0>
mov    0x2cc0(%rip),%r15
mov    (%r15),%edx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <strlcpy@plt>
cmp    (%r15),%eax
jge    13f2 <prepare_fwds+0x2a2>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
sub    %r14,%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rcx,%rax,1)
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtoul@plt>
test   %eax,%eax
je     13f2 <prepare_fwds+0x2a2>
mov    %eax,%r14d
add    $0x1,%rbx
mov    0x2c63(%rip),%r12
mov    (%r12),%edx
mov    -0x58(%rbp),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <strlcpy@plt>
mov    -0x50(%rbp),%rax
cmp    $0x52,%al
je     141f <prepare_fwds+0x2cf>
cmp    $0x4c,%al
jne    140d <prepare_fwds+0x2bd>
mov    (%r12),%esi
lea    0xc5d(%rip),%rdx
xor    %r15d,%r15d
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    (%r12),%esi
lea    0xc50(%rip),%rdx
mov    -0x40(%rbp),%rdi
mov    %r14d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    (%r12),%esi
lea    0xc4e(%rip),%rdx
mov    -0x48(%rbp),%rdi
mov    %r14d,%ecx
mov    %r13,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    140d <prepare_fwds+0x2bd>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%esi
lea    0xc0c(%rip),%rdx
xor    %r15d,%r15d
mov    -0x38(%rbp),%rdi
mov    %r14d,%ecx
mov    %r13,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    (%r12),%esi
lea    0xbf6(%rip),%rdx
mov    -0x40(%rbp),%rdi
mov    %r14d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    (%r12),%esi
lea    0xbed(%rip),%rdx
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    140d <prepare_fwds+0x2bd>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [19 x i8] c"-L%s:127.0.0.1:%u\0D\00"
@.str.1 = [19 x i8] c"-L%u:127.0.0.1:%u\0D\00"
@.str.2 = [7 x i8] c"-D:%u\0D\00"
@.str.3 = [9 x i8] c"-L%u:%s\0D\00"
@.str.4 = [9 x i8] c"-R%u:%s\0D\00"
@.str.5 = [19 x i8] c"-R%u:127.0.0.1:%u\0D\00"
@.str.6 = [19 x i8] c"-R%s:127.0.0.1:%u\0D\00"
@stderr = global i32 0
@.str.7 = [17 x i8] c"Invalid command.\00"
define i32 @prepare_fwds(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%21 = load i32, i32* @BUFSIZ
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %15
%24 = alloca i8, i64 %22
store i64 %22, i64* %16
%25 = load i32, i32* @BUFSIZ
%26 = zext i32 %25 to i64
%27 = alloca i8, i64 %26
store i64 %26, i64* %17
%28 = load i32, i32* @BUFSIZ
%29 = zext i32 %28 to i64
%30 = alloca i8, i64 %29
store i64 %29, i64* %18
%31 = load i8*, i8** %6
store i8* %31, i8** %13
%32 = load i8*, i8** %13
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 45
br i1 %35, label %36, label %39
36: ; preds = %4
%37 = load i8*, i8** %13
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %13
br label %39
39: ; preds = %36, %4
%40 = load i8*, i8** %13
%41 = load i8, i8* %40
store i8 %41, i8* %10
%42 = load i8, i8* %10
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 76
br i1 %44, label %45, label %54
45: ; preds = %39
%46 = load i8, i8* %10
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 82
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = load i8, i8* %10
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 68
br i1 %52, label %53, label %54
53: ; preds = %49
br label %193
54: ; preds = %49, %45, %39
%55 = load i8*, i8** %13
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %13
%57 = load i8, i8* %10
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 68
br i1 %59, label %60, label %90
60: ; preds = %54
%61 = load i8*, i8** %13
%62 = load i32, i32* @BUFSIZ
%63 = call i32 @strlcpy(i8* %27, i8* %61, i32 %62)
%64 = load i8*, i8** %13
store i8* %64, i8** %14
%65 = load i8*, i8** %14
%66 = call i8* @strchr(i8* %65, i8 signext 58)
store i8* %66, i8** %14
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %71
68: ; preds = %60
%69 = load i8*, i8** %14
%70 = getelementptr inbounds i8, i8* %69, i64 1
store i8* %70, i8** %13
br label %71
71: ; preds = %68, %60
%72 = load i8*, i8** %13
%73 = call i32 @strtoul(i8* %72, i32* null, i32 10)
store i32 %73, i32* %19
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %71
br label %193
76: ; preds = %71
%77 = load i8*, i8** %7
%78 = load i32, i32* @BUFSIZ
%79 = load i32, i32* %19
%80 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %77, i32 %78, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %27, i32 %79)
%81 = load i8*, i8** %8
%82 = load i32, i32* @BUFSIZ
%83 = load i32, i32* %19
%84 = load i32, i32* %19
%85 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %81, i32 %82, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %83, i32 %84)
%86 = load i8*, i8** %9
%87 = load i32, i32* @BUFSIZ
%88 = load i32, i32* %19
%89 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %86, i32 %87, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %88)
store i32 0, i32* %5
store i32 1, i32* %20
br label %196
90: ; preds = %54
%91 = load i8*, i8** %13
store i8* %91, i8** %14
store i8 0, i8* %11
br label %92
92: ; preds = %96, %90
%93 = load i8*, i8** %14
%94 = call i8* @strchr(i8* %93, i8 signext 58)
store i8* %94, i8** %14
%95 = icmp ne i8* %94, null
br i1 %95, label %96, label %101
96: ; preds = %92
%97 = load i8*, i8** %14
%98 = getelementptr inbounds i8, i8* %97, i32 1
store i8* %98, i8** %14
%99 = load i8, i8* %11
%100 = add i8 %99, 1
store i8 %100, i8* %11
br label %92
101: ; preds = %92
%102 = load i8, i8* %11
%103 = sext i8 %102 to i32
%104 = icmp slt i32 %103, 2
br i1 %104, label %109, label %105
105: ; preds = %101
%106 = load i8, i8* %11
%107 = sext i8 %106 to i32
%108 = icmp sgt i32 %107, 3
br i1 %108, label %109, label %110
109: ; preds = %105, %101
br label %193
110: ; preds = %105
%111 = load i8*, i8** %13
%112 = load i32, i32* @BUFSIZ
%113 = call i32 @strlcpy(i8* %27, i8* %111, i32 %112)
%114 = load i8*, i8** %13
store i8* %114, i8** %14
store i8 0, i8* %12
br label %115
115: ; preds = %127, %110
%116 = load i8, i8* %12
%117 = sext i8 %116 to i32
%118 = load i8, i8* %11
%119 = sext i8 %118 to i32
%120 = sub nsw i32 %119, 2
%121 = icmp slt i32 %117, %120
br i1 %121, label %122, label %130
122: ; preds = %115
%123 = load i8*, i8** %14
%124 = call i8* @strchr(i8* %123, i8 signext 58)
store i8* %124, i8** %14
%125 = load i8*, i8** %14
%126 = getelementptr inbounds i8, i8* %125, i32 1
store i8* %126, i8** %14
br label %127
127: ; preds = %122
%128 = load i8, i8* %12
%129 = add i8 %128, 1
store i8 %129, i8* %12
br label %115
130: ; preds = %115
%131 = load i8*, i8** %14
%132 = load i32, i32* @BUFSIZ
%133 = call i32 @strlcpy(i8* %24, i8* %131, i32 %132)
%134 = load i32, i32* @BUFSIZ
%135 = icmp sge i32 %133, %134
br i1 %135, label %136, label %137
136: ; preds = %130
br label %193
137: ; preds = %130
%138 = load i8*, i8** %14
%139 = call i8* @strchr(i8* %138, i8 signext 58)
store i8* %139, i8** %14
%140 = load i8*, i8** %14
store i8 0, i8* %140
%141 = load i8*, i8** %14
%142 = load i8*, i8** %13
%143 = ptrtoint i8* %141 to i64
%144 = ptrtoint i8* %142 to i64
%145 = sub i64 %143, %144
%146 = getelementptr inbounds i8, i8* %27, i64 %145
store i8 0, i8* %146
%147 = load i8*, i8** %13
%148 = call i32 @strtoul(i8* %147, i32* null, i32 10)
store i32 %148, i32* %19
%149 = icmp eq i32 %148, 0
br i1 %149, label %150, label %151
150: ; preds = %137
br label %193
151: ; preds = %137
%152 = load i8*, i8** %14
%153 = getelementptr inbounds i8, i8* %152, i64 1
%154 = load i32, i32* @BUFSIZ
%155 = call i32 @strlcpy(i8* %30, i8* %153, i32 %154)
%156 = load i8, i8* %10
%157 = sext i8 %156 to i32
%158 = icmp eq i32 %157, 76
br i1 %158, label %159, label %173
159: ; preds = %151
%160 = load i8*, i8** %7
%161 = load i32, i32* @BUFSIZ
%162 = load i32, i32* %19
%163 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %160, i32 %161, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %27, i32 %162)
%164 = load i8*, i8** %8
%165 = load i32, i32* @BUFSIZ
%166 = load i32, i32* %19
%167 = load i32, i32* %19
%168 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %164, i32 %165, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %166, i32 %167)
%169 = load i8*, i8** %9
%170 = load i32, i32* @BUFSIZ
%171 = load i32, i32* %19
%172 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %169, i32 %170, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %171, i8* %30)
br label %192
173: ; preds = %151
%174 = load i8, i8* %10
%175 = sext i8 %174 to i32
%176 = icmp eq i32 %175, 82
br i1 %176, label %177, label %191
177: ; preds = %173
%178 = load i8*, i8** %7
%179 = load i32, i32* @BUFSIZ
%180 = load i32, i32* %19
%181 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %178, i32 %179, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %180, i8* %30)
%182 = load i8*, i8** %8
%183 = load i32, i32* @BUFSIZ
%184 = load i32, i32* %19
%185 = load i32, i32* %19
%186 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %182, i32 %183, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %184, i32 %185)
%187 = load i8*, i8** %9
%188 = load i32, i32* @BUFSIZ
%189 = load i32, i32* %19
%190 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %187, i32 %188, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %27, i32 %189)
br label %191
191: ; preds = %177, %173
br label %192
192: ; preds = %191, %159
store i32 0, i32* %5
store i32 1, i32* %20
br label %196
193: ; preds = %150, %136, %109, %75, %53
%194 = load i32, i32* @stderr
%195 = call i32 @fprintf(i32 %194, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %5
store i32 1, i32* %20
br label %196
196: ; preds = %193, %192, %76
%197 = load i8*, i8** %15
%198 = load i32, i32* %5
ret i32 %198
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [19 x i8] c"-L%s:127.0.0.1:%u\0D\00"
@.str.1 = [19 x i8] c"-L%u:127.0.0.1:%u\0D\00"
@.str.2 = [7 x i8] c"-D:%u\0D\00"
@.str.3 = [9 x i8] c"-L%u:%s\0D\00"
@.str.4 = [9 x i8] c"-R%u:%s\0D\00"
@.str.5 = [19 x i8] c"-R%u:127.0.0.1:%u\0D\00"
@.str.6 = [19 x i8] c"-R%s:127.0.0.1:%u\0D\00"
@stderr = global i32 0
@.str.7 = [17 x i8] c"Invalid command.\00"
define i32 @prepare_fwds(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = alloca i8, i64 %6
%9 = alloca i8, i64 %6
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 45
%12 = zext i1 %11 to i64
%13 = getelementptr i8, i8* %0, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %91 [
i8 82, label %15
i8 76, label %15
i8 68, label %15
]
15: ; preds = %4, %4, %4
%16 = getelementptr inbounds i8, i8* %13, i64 1
%17 = icmp eq i8 %14, 68
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call i8* @strchr(i8* %16, i8 signext 58)
%20 = icmp eq i8* %19, null
br i1 %20, label %91, label %36
21: ; preds = %15
%22 = call i32 @strlcpy(i8* %8, i8* %16, i32 %5)
%23 = call i8* @strchr(i8* %16, i8 signext 58)
%24 = icmp eq i8* %23, null
%25 = getelementptr inbounds i8, i8* %23, i64 1
%26 = select i1 %24, i8* %16, i8* %25
%27 = call i32 @strtoul(i8* nocapture %26, i32* null, i32 10)
%28 = icmp eq i32 %27, 0
br i1 %28, label %91, label %29
29: ; preds = %21
%30 = load i32, i32* @BUFSIZ
%31 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %27)
%32 = load i32, i32* @BUFSIZ
%33 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %27)
%34 = load i32, i32* @BUFSIZ
%35 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %94
36: ; preds = %18, %36
%37 = phi i8* [ %41, %36 ], [ %19, %18 ]
%38 = phi i8 [ %40, %36 ], [ 0, %18 ]
%39 = getelementptr inbounds i8, i8* %37, i64 1
%40 = add i8 %38, 1
%41 = tail call i8* @strchr(i8* %39, i8 signext 58)
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %36
43: ; preds = %36
%44 = add i8 %38, -3
%45 = icmp ult i8 %44, -2
br i1 %45, label %91, label %46
46: ; preds = %43
%47 = zext i8 %40 to i32
%48 = call i32 @strlcpy(i8* %8, i8* %16, i32 %5)
%49 = add nsw i32 %47, -2
%50 = icmp ugt i8 %40, 2
br i1 %50, label %51, label %59
51: ; preds = %46, %51
%52 = phi i8 [ %56, %51 ], [ 0, %46 ]
%53 = phi i8* [ %55, %51 ], [ %16, %46 ]
%54 = call i8* @strchr(i8* %53, i8 signext 58)
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = add i8 %52, 1
%57 = sext i8 %56 to i32
%58 = icmp sgt i32 %49, %57
br i1 %58, label %51, label %59
59: ; preds = %51, %46
%60 = phi i8* [ %16, %46 ], [ %55, %51 ]
%61 = load i32, i32* @BUFSIZ
%62 = call i32 @strlcpy(i8* %7, i8* %60, i32 %61)
%63 = load i32, i32* @BUFSIZ
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %91
65: ; preds = %59
%66 = call i8* @strchr(i8* %60, i8 signext 58)
store i8 0, i8* %66
%67 = ptrtoint i8* %66 to i64
%68 = ptrtoint i8* %16 to i64
%69 = sub i64 %67, %68
%70 = getelementptr inbounds i8, i8* %8, i64 %69
store i8 0, i8* %70
%71 = call i32 @strtoul(i8* nocapture %16, i32* null, i32 10)
%72 = icmp eq i32 %71, 0
br i1 %72, label %91, label %73
73: ; preds = %65
%74 = getelementptr inbounds i8, i8* %66, i64 1
%75 = load i32, i32* @BUFSIZ
%76 = call i32 @strlcpy(i8* %9, i8* %74, i32 %75)
switch i8 %14, label %94 [
i8 76, label %77
i8 82, label %84
]
77: ; preds = %73
%78 = load i32, i32* @BUFSIZ
%79 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %78, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %71)
%80 = load i32, i32* @BUFSIZ
%81 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %80, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %71, i32 %71)
%82 = load i32, i32* @BUFSIZ
%83 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %82, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %71, i8* %9)
br label %94
84: ; preds = %73
%85 = load i32, i32* @BUFSIZ
%86 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 %85, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %71, i8* %9)
%87 = load i32, i32* @BUFSIZ
%88 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 %87, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %71, i32 %71)
%89 = load i32, i32* @BUFSIZ
%90 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 %89, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %8, i32 %71)
br label %94
91: ; preds = %18, %4, %65, %59, %43, %21
%92 = load i32, i32* @stderr
%93 = call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %94
94: ; preds = %77, %84, %73, %91, %29
%95 = phi i32 [ 1, %91 ], [ 0, %29 ], [ 0, %73 ], [ 0, %84 ], [ 0, %77 ]
ret i32 %95
}