# Summary:
  # Argument Usage:
  # Return Value:

  upvar $b_cxl_arg b_cxl

  # initialize flag
  set b_cxl 0

  # default full path
  set sub_lib_path $src_lib_dir_arg
  
  # is sim dir empty? return default full path
  if { "" == $sim_dir } {
    return $sub_lib_path
  }

  # normalize and split into sub-dirs
  set sim_sub_dirs  [file split [file normalize $sim_dir]]
  set path_sub_dirs [file split [file normalize $sub_lib_path]]

  # sub-dirs length
  set sim_len [llength $sim_sub_dirs]
  set path_len [llength $path_sub_dirs]

  # if sim_dir path equal to or greater than the lib path, no need to resolve
  if { ($sim_len == $path_len) || ($sim_len > $path_len) } {
    return $sub_lib_path
  }

  # increment index for each sub-dir match till end of sim sub-dir
  set index 0
  set b_found_match 0
  while { [lindex $sim_sub_dirs $index] == [lindex $path_sub_dirs $index] } {
    incr index
    # index matches with sim sub-dir length (got exact match of all sim sub-dirs)
    if { $index == $sim_len } {
      set b_found_match 1
      break
    }
  }
 
  # if exact match found, set the remaining library directory path and return it, else return default library path
  if { $b_found_match } {
    set sub_lib_path [join [lrange $path_sub_dirs $index end] "/"]
    set b_cxl 1
  }
  return $sub_lib_path
}

proc xcs_resolve_sim_model_dir { lib_path clib_dir cpt_dir ext_dir b_resolved_arg } {
  # Summary:
  # Argument Usage:
  # Return Value:

  upvar $b_resolved_arg b_resolved
  
  set b_resolved 0
  set resolved_path {}

  set sub_lib_path [xcs_resolve_sim_lib_dir $clib_dir $lib_path b_resolved]
  if { $b_resolved } {
    if {$::tcl_platform(platform) == "unix"} {
      set resolved_path "\$xv_cxl_lib_path/$sub_lib_path"
    } else {
      set resolved_path "%xv_cxl_lib_path%/$sub_lib_path"
    }
  } else {
    set sub_lib_path [xcs_resolve_sim_lib_dir $cpt_dir $lib_path b_resolved]
    if { $b_resolved } {
      if {$::tcl_platform(platform) == "unix"} {
        set resolved_path "\$xv_cpt_lib_path/$sub_lib_path"
      }