#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 */
struct clientinfo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ fw_forward(char *, char *, struct clientinfo *);
scalar_t__ fw_port_mode(char *, char *, struct clientinfo *);
scalar_t__ fw_transparent(struct clientinfo *);
scalar_t__ fw_transparent_forward(struct clientinfo *);
char *quotstrtok(char const *, char const *, int *);
int set_userdest(const char *buffer, int offset, struct clientinfo *clntinfo,
                 const char *delimiters) {
  char *user, *host, *port, *mode;
  if (buffer[0] == '@') {
    user = (char *)0;
  } else {
    user = quotstrtok(buffer, delimiters, &offset);
  }
  host = quotstrtok(buffer, delimiters, &offset);
  port = quotstrtok(buffer, delimiters, &offset);
  mode = quotstrtok(buffer, delimiters, &offset);
  if (fw_forward(user, host, clntinfo) != 0) {
    free(user);
    free(host);
    free(port);
    free(mode);
    return (-2);
  }
  if (fw_transparent_forward(clntinfo) != 0) {
    free(user);
    free(host);
    free(port);
    free(mode);
    return (-2);
  }
  if (fw_transparent(clntinfo) != 0) {
    free(user);
    free(host);
    free(port);
    free(mode);
    return (-2);
  }
  if (fw_port_mode(port, mode, clntinfo) != 0) {
    free(user);
    free(host);
    free(port);
    free(mode);
    return (-2);
  }
  free(user);
  free(host);
  free(port);
  free(mode);
  return 0;
}


x86 assembly (clang, -O0):
<set_userdest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    1194 <set_userdest+0x34>
movq   $0x0,-0x30(%rbp)
jmp    11a9 <set_userdest+0x49>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <quotstrtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <quotstrtok@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <quotstrtok@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <quotstrtok@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <fw_forward@plt>
cmp    $0x0,%rax
je     1233 <set_userdest+0xd3>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    132f <set_userdest+0x1cf>
mov    -0x20(%rbp),%rdi
call   1070 <fw_transparent_forward@plt>
cmp    $0x0,%rax
je     1276 <set_userdest+0x116>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    132f <set_userdest+0x1cf>
mov    -0x20(%rbp),%rdi
call   1050 <fw_transparent@plt>
cmp    $0x0,%rax
je     12b9 <set_userdest+0x159>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    132f <set_userdest+0x1cf>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <fw_port_mode@plt>
cmp    $0x0,%rax
je     1304 <set_userdest+0x1a4>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    132f <set_userdest+0x1cf>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_userdest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdi,%rbp
mov    %esi,0xc(%rsp)
cmpb   $0x40,(%rdi)
mov    %rdx,0x10(%rsp)
jne    1187 <set_userdest+0x27>
xor    %r14d,%r14d
jmp    119a <set_userdest+0x3a>
lea    0xc(%rsp),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <quotstrtok@plt>
mov    %rax,%r14
lea    0xc(%rsp),%r15
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <quotstrtok@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <quotstrtok@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <quotstrtok@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%rbp
mov    %rbp,%rdx
call   1080 <fw_forward@plt>
test   %rax,%rax
jne    1204 <set_userdest+0xa4>
mov    %rbp,%rdi
call   1070 <fw_transparent_forward@plt>
test   %rax,%rax
jne    1204 <set_userdest+0xa4>
mov    %rbp,%rdi
call   1050 <fw_transparent@plt>
test   %rax,%rax
je     1238 <set_userdest+0xd8>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0xfffffffe,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1060 <fw_port_mode@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    -0x2(%rbp,%rbp,1),%eax
jmp    1229 <set_userdest+0xc9>

LLVM IR (-O0):
%struct.clientinfo = type { i32 }
define i32 @set_userdest(i8* %0, i32 %1, %struct.clientinfo* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.clientinfo*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store %struct.clientinfo* %2, %struct.clientinfo** %8
store i8* %3, i8** %9
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 64
br i1 %18, label %19, label %20
19: ; preds = %4
store i8* null, i8** %10
br label %24
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = load i8*, i8** %9
%23 = call i8* @quotstrtok(i8* %21, i8* %22, i32* %7)
store i8* %23, i8** %10
br label %24
24: ; preds = %20, %19
%25 = load i8*, i8** %6
%26 = load i8*, i8** %9
%27 = call i8* @quotstrtok(i8* %25, i8* %26, i32* %7)
store i8* %27, i8** %11
%28 = load i8*, i8** %6
%29 = load i8*, i8** %9
%30 = call i8* @quotstrtok(i8* %28, i8* %29, i32* %7)
store i8* %30, i8** %12
%31 = load i8*, i8** %6
%32 = load i8*, i8** %9
%33 = call i8* @quotstrtok(i8* %31, i8* %32, i32* %7)
store i8* %33, i8** %13
%34 = load i8*, i8** %10
%35 = load i8*, i8** %11
%36 = load %struct.clientinfo*, %struct.clientinfo** %8
%37 = call i64 @fw_forward(i8* %34, i8* %35, %struct.clientinfo* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %24
%40 = load i8*, i8** %10
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %11
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %12
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %13
%47 = call i32 @free(i8* %46)
store i32 -2, i32* %5
br label %98
48: ; preds = %24
%49 = load %struct.clientinfo*, %struct.clientinfo** %8
%50 = call i64 @fw_transparent_forward(%struct.clientinfo* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %48
%53 = load i8*, i8** %10
%54 = call i32 @free(i8* %53)
%55 = load i8*, i8** %11
%56 = call i32 @free(i8* %55)
%57 = load i8*, i8** %12
%58 = call i32 @free(i8* %57)
%59 = load i8*, i8** %13
%60 = call i32 @free(i8* %59)
store i32 -2, i32* %5
br label %98
61: ; preds = %48
%62 = load %struct.clientinfo*, %struct.clientinfo** %8
%63 = call i64 @fw_transparent(%struct.clientinfo* %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %74
65: ; preds = %61
%66 = load i8*, i8** %10
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %11
%69 = call i32 @free(i8* %68)
%70 = load i8*, i8** %12
%71 = call i32 @free(i8* %70)
%72 = load i8*, i8** %13
%73 = call i32 @free(i8* %72)
store i32 -2, i32* %5
br label %98
74: ; preds = %61
%75 = load i8*, i8** %12
%76 = load i8*, i8** %13
%77 = load %struct.clientinfo*, %struct.clientinfo** %8
%78 = call i64 @fw_port_mode(i8* %75, i8* %76, %struct.clientinfo* %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %89
80: ; preds = %74
%81 = load i8*, i8** %10
%82 = call i32 @free(i8* %81)
%83 = load i8*, i8** %11
%84 = call i32 @free(i8* %83)
%85 = load i8*, i8** %12
%86 = call i32 @free(i8* %85)
%87 = load i8*, i8** %13
%88 = call i32 @free(i8* %87)
store i32 -2, i32* %5
br label %98
89: ; preds = %74
%90 = load i8*, i8** %10
%91 = call i32 @free(i8* %90)
%92 = load i8*, i8** %11
%93 = call i32 @free(i8* %92)
%94 = load i8*, i8** %12
%95 = call i32 @free(i8* %94)
%96 = load i8*, i8** %13
%97 = call i32 @free(i8* %96)
store i32 0, i32* %5
br label %98
98: ; preds = %89, %80, %65, %52, %39
%99 = load i32, i32* %5
ret i32 %99
}

LLVM IR (-O2):
%struct.clientinfo = type { i32 }
define i32 @set_userdest(i8* %0, i32 %1, %struct.clientinfo* %2, i8* %3) {
%5 = alloca i32
store i32 %1, i32* %5
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 64
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = call i8* @quotstrtok(i8* %0, i8* %3, i32* %5)
br label %10
10: ; preds = %4, %8
%11 = phi i8* [ %9, %8 ], [ null, %4 ]
%12 = call i8* @quotstrtok(i8* %0, i8* %3, i32* %5)
%13 = call i8* @quotstrtok(i8* %0, i8* %3, i32* %5)
%14 = call i8* @quotstrtok(i8* %0, i8* %3, i32* %5)
%15 = call i64 @fw_forward(i8* %11, i8* %12, %struct.clientinfo* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %10
%18 = call i32 @free(i8* %11)
%19 = call i32 @free(i8* %12)
%20 = call i32 @free(i8* %13)
%21 = call i32 @free(i8* %14)
br label %46
22: ; preds = %10
%23 = call i64 @fw_transparent_forward(%struct.clientinfo* %2)
%24 = icmp eq i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = call i32 @free(i8* %11)
%27 = call i32 @free(i8* %12)
%28 = call i32 @free(i8* %13)
%29 = call i32 @free(i8* %14)
br label %46
30: ; preds = %22
%31 = call i64 @fw_transparent(%struct.clientinfo* %2)
%32 = icmp eq i64 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %30
%34 = call i32 @free(i8* %11)
%35 = call i32 @free(i8* %12)
%36 = call i32 @free(i8* %13)
%37 = call i32 @free(i8* %14)
br label %46
38: ; preds = %30
%39 = call i64 @fw_port_mode(i8* %13, i8* %14, %struct.clientinfo* %2)
%40 = icmp eq i64 %39, 0
%41 = call i32 @free(i8* %11)
%42 = call i32 @free(i8* %12)
%43 = call i32 @free(i8* %13)
%44 = call i32 @free(i8* %14)
%45 = select i1 %40, i32 0, i32 -2
br label %46
46: ; preds = %38, %33, %25, %17
%47 = phi i32 [ -2, %17 ], [ -2, %25 ], [ -2, %33 ], [ %45, %38 ]
ret i32 %47
}