#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 /*<<< orphan*/ free(char *);
int iso_node_is_valid_name(char *);
scalar_t__ strcmp(char const *, char *);
char *strdup(char const *);
int strlen(char const *);
char *strtok_r(char *, char *, char **);
int iso_node_is_valid_link_dest(const char *dest) {
  int ret;
  char *ptr, *brk_info, *component;
  if (dest == NULL) {
    return 0xE830FFFB;
  }
  if (dest[0] == '\0')
    return 0xE830FE86;
  if (strlen(dest) > 1024)
    return 0xE830FE85;
  if (!strcmp(dest, "/")) {
    return 1;
  }
  ptr = strdup(dest);
  if (ptr == NULL) {
    return 0xF030FFFA;
  }
  ret = 1;
  component = strtok_r(ptr, "/", &brk_info);
  while (component) {
    if (strcmp(component, ".") && strcmp(component, "..")) {
      ret = iso_node_is_valid_name(component);
      if (ret < 0) {
        break;
      }
    }
    component = strtok_r(NULL, "/", &brk_info);
  }
  free(ptr);
  return ret;
}


x86 assembly (clang, -O0):
<iso_node_is_valid_link_dest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <iso_node_is_valid_link_dest+0x23>
movl   $0xe830fffb,-0x4(%rbp)
jmp    12b3 <iso_node_is_valid_link_dest+0x153>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119f <iso_node_is_valid_link_dest+0x3f>
movl   $0xe830fe86,-0x4(%rbp)
jmp    12b3 <iso_node_is_valid_link_dest+0x153>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x400,%eax
jle    11bf <iso_node_is_valid_link_dest+0x5f>
movl   $0xe830fe85,-0x4(%rbp)
jmp    12b3 <iso_node_is_valid_link_dest+0x153>
mov    -0x10(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e5 <iso_node_is_valid_link_dest+0x85>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <iso_node_is_valid_link_dest+0x153>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1209 <iso_node_is_valid_link_dest+0xa9>
movl   $0xf030fffa,-0x4(%rbp)
jmp    12b3 <iso_node_is_valid_link_dest+0x153>
movl   $0x1,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xde5(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12a4 <iso_node_is_valid_link_dest+0x144>
mov    -0x30(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1287 <iso_node_is_valid_link_dest+0x127>
mov    -0x30(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1287 <iso_node_is_valid_link_dest+0x127>
mov    -0x30(%rbp),%rdi
call   1070 <iso_node_is_valid_name@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1282 <iso_node_is_valid_link_dest+0x122>
jmp    12a4 <iso_node_is_valid_link_dest+0x144>
jmp    1287 <iso_node_is_valid_link_dest+0x127>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd6e(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
jmp    1228 <iso_node_is_valid_link_dest+0xc8>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso_node_is_valid_link_dest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     1255 <iso_node_is_valid_link_dest+0xf5>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     125c <iso_node_is_valid_link_dest+0xfc>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0xe830fe85,%ebp
cmp    $0x400,%eax
jg     1280 <iso_node_is_valid_link_dest+0x120>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1263 <iso_node_is_valid_link_dest+0x103>
mov    %rbx,%rdi
call   1080 <strdup@plt>
test   %rax,%rax
je     126a <iso_node_is_valid_link_dest+0x10a>
lea    0xe35(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     1271 <iso_node_is_valid_link_dest+0x111>
mov    %rax,%r14
mov    $0x1,%ebp
lea    0xe0e(%rip),%r12
lea    0xe04(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xdfa(%rip),%r13
jmp    1225 <iso_node_is_valid_link_dest+0xc5>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%r14
test   %rax,%rax
je     1276 <iso_node_is_valid_link_dest+0x116>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1210 <iso_node_is_valid_link_dest+0xb0>
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1210 <iso_node_is_valid_link_dest+0xb0>
mov    %r14,%rdi
call   1070 <iso_node_is_valid_name@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1210 <iso_node_is_valid_link_dest+0xb0>
jmp    1276 <iso_node_is_valid_link_dest+0x116>
mov    $0xe830fffb,%ebp
jmp    1280 <iso_node_is_valid_link_dest+0x120>
mov    $0xe830fe86,%ebp
jmp    1280 <iso_node_is_valid_link_dest+0x120>
mov    $0x1,%ebp
jmp    1280 <iso_node_is_valid_link_dest+0x120>
mov    $0xf030fffa,%ebp
jmp    1280 <iso_node_is_valid_link_dest+0x120>
mov    $0x1,%ebp
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @iso_node_is_valid_link_dest(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -399441925, i32* %2
br label %61
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 -399442298, i32* %2
br label %61
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = icmp sgt i32 %20, 1024
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -399442299, i32* %2
br label %61
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23
store i32 1, i32* %2
br label %61
28: ; preds = %23
%29 = load i8*, i8** %3
%30 = call i8* @strdup(i8* %29)
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 -265224198, i32* %2
br label %61
34: ; preds = %28
store i32 1, i32* %4
%35 = load i8*, i8** %5
%36 = call i8* @strtok_r(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6)
store i8* %36, i8** %7
br label %37
37: ; preds = %55, %34
%38 = load i8*, i8** %7
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %57
40: ; preds = %37
%41 = load i8*, i8** %7
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %55
44: ; preds = %40
%45 = load i8*, i8** %7
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = load i8*, i8** %7
%50 = call i32 @iso_node_is_valid_name(i8* %49)
store i32 %50, i32* %4
%51 = load i32, i32* %4
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %48
br label %57
54: ; preds = %48
br label %55
55: ; preds = %54, %44, %40
%56 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6)
store i8* %56, i8** %7
br label %37
57: ; preds = %53, %37
%58 = load i8*, i8** %5
%59 = call i32 @free(i8* %58)
%60 = load i32, i32* %4
store i32 %60, i32* %2
br label %61
61: ; preds = %57, %33, %27, %22, %17, %10
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @iso_node_is_valid_link_dest(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %38, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %38, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 1024
br i1 %10, label %38, label %11
11: ; preds = %8
%12 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %38, label %14
14: ; preds = %11
%15 = tail call i8* @strdup(i8* %0)
%16 = icmp eq i8* %15, null
br i1 %16, label %38, label %17
17: ; preds = %14
%18 = call i8* @strtok_r(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%19 = icmp eq i8* %18, null
br i1 %19, label %35, label %20
20: ; preds = %17, %31
%21 = phi i8* [ %33, %31 ], [ %18, %17 ]
%22 = phi i32 [ %32, %31 ], [ 1, %17 ]
%23 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %20
%26 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = call i32 @iso_node_is_valid_name(i8* %21)
%30 = icmp slt i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %28, %25, %20
%32 = phi i32 [ %29, %28 ], [ %22, %25 ], [ %22, %20 ]
%33 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %20
35: ; preds = %31, %28, %17
%36 = phi i32 [ 1, %17 ], [ %29, %28 ], [ %32, %31 ]
%37 = call i32 @free(i8* %15)
br label %38
38: ; preds = %14, %11, %8, %5, %1, %35
%39 = phi i32 [ %36, %35 ], [ -399441925, %1 ], [ -399442298, %5 ], [ -399442299, %8 ], [ 1, %11 ], [ -265224198, %14 ]
ret i32 %39
}