unsigned long lib$index(const struct dsc$descriptor_s *first_source_string,
                        const struct dsc$descriptor_s *second_source_string) {
  char *s1_ptr;
  unsigned short s1_length;
  char *s2_ptr;
  unsigned short s2_length;
  unsigned long loop;
  lib$analyze_sdesc(first_source_string, &s1_length, &s1_ptr);
  lib$analyze_sdesc(second_source_string, &s2_length, &s2_ptr);
  for (loop = 0; loop <= s1_length - s2_length; loop++) {
    if (memcmp(s1_ptr + loop, s2_ptr, s2_length) == 0) {
      return loop + 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<lib$index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x22(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <lib$analyze_sdesc@plt>
mov    -0x18(%rbp),%rdi
lea    -0x32(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1030 <lib$analyze_sdesc@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movzwl -0x22(%rbp),%ecx
movzwl -0x32(%rbp),%edx
sub    %edx,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
ja     11bf <lib$index+0x9f>
mov    -0x20(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
movzwl -0x32(%rbp),%eax
mov    %eax,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11a9 <lib$index+0x89>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <lib$index+0xa7>
jmp    11ae <lib$index+0x8e>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    115e <lib$index+0x3e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib$index>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
xor    %r14d,%r14d
lea    0x6(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1030 <lib$analyze_sdesc@plt>
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <lib$analyze_sdesc@plt>
movzwl 0x6(%rsp),%r12d
movzwl 0x4(%rsp),%r15d
sub    %r15,%r12
mov    0x10(%rsp),%rbp
mov    0x8(%rsp),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rbx,%rbp,1),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1040 <bcmp@plt>
add    $0x1,%rbx
test   %eax,%eax
je     119e <lib$index+0x7e>
cmp    %r12,%rbx
jbe    1180 <lib$index+0x60>
jmp    11a1 <lib$index+0x81>
mov    %rbx,%r14
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"lib$index"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1) {
%3 = alloca i64
%4 = alloca %"struct.dsc$descriptor_s"*
%5 = alloca %"struct.dsc$descriptor_s"*
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i16
%10 = alloca i64
store %"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"** %4
store %"struct.dsc$descriptor_s"* %1, %"struct.dsc$descriptor_s"** %5
%11 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %4
%12 = call i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...) bitcast (i32 (...)* @"lib$analyze_sdesc" to i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...)*)(%"struct.dsc$descriptor_s"* %11, i16* %7, i8** %6)
%13 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %5
%14 = call i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...) bitcast (i32 (...)* @"lib$analyze_sdesc" to i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...)*)(%"struct.dsc$descriptor_s"* %13, i16* %9, i8** %8)
store i64 0, i64* %10
br label %15
15: ; preds = %37, %2
%16 = load i64, i64* %10
%17 = load i16, i16* %7
%18 = zext i16 %17 to i32
%19 = load i16, i16* %9
%20 = zext i16 %19 to i32
%21 = sub nsw i32 %18, %20
%22 = sext i32 %21 to i64
%23 = icmp ule i64 %16, %22
br i1 %23, label %24, label %40
24: ; preds = %15
%25 = load i8*, i8** %6
%26 = load i64, i64* %10
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8*, i8** %8
%29 = load i16, i16* %9
%30 = zext i16 %29 to i64
%31 = call i32 @memcmp(i8* %27, i8* %28, i64 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i64, i64* %10
%35 = add i64 %34, 1
store i64 %35, i64* %3
br label %41
36: ; preds = %24
br label %37
37: ; preds = %36
%38 = load i64, i64* %10
%39 = add i64 %38, 1
store i64 %39, i64* %10
br label %15
40: ; preds = %15
store i64 0, i64* %3
br label %41
41: ; preds = %40, %33
%42 = load i64, i64* %3
ret i64 %42
}

LLVM IR (-O2):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"lib$index"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i8*
%6 = alloca i16
%7 = bitcast i8** %3 to i8*
%8 = bitcast i16* %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = bitcast i16* %6 to i8*
%11 = call i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...) bitcast (i32 (...)* @"lib$analyze_sdesc" to i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...)*)(%"struct.dsc$descriptor_s"* %0, i16* %4, i8** %3)
%12 = call i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...) bitcast (i32 (...)* @"lib$analyze_sdesc" to i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...)*)(%"struct.dsc$descriptor_s"* %1, i16* %6, i8** %5)
%13 = load i16, i16* %4
%14 = zext i16 %13 to i64
%15 = load i16, i16* %6
%16 = zext i16 %15 to i64
%17 = sub nsw i64 %14, %16
%18 = load i8*, i8** %3
%19 = load i8*, i8** %5
br label %20
20: ; preds = %2, %26
%21 = phi i64 [ 0, %2 ], [ %25, %26 ]
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = call i32 @bcmp(i8* %22, i8* %19, i64 %16)
%24 = icmp eq i32 %23, 0
%25 = add i64 %21, 1
br i1 %24, label %28, label %26
26: ; preds = %20
%27 = icmp ugt i64 %25, %17
br i1 %27, label %28, label %20
28: ; preds = %26, %20
%29 = phi i64 [ %25, %20 ], [ 0, %26 ]
ret i64 %29
}