unsigned long lib$locc(const struct dsc$descriptor_s *char_string,
                       const struct dsc$descriptor_s *source_string) {
  char *s1_ptr, *s2_ptr;
  unsigned short s1_len, s2_len;
  unsigned long i;
  lib$analyze_sdesc(char_string, &s1_len, &s1_ptr);
  lib$analyze_sdesc(source_string, &s2_len, &s2_ptr);
  if (s1_len > 0) {
    for (i = 0; i < s2_len; i++) {
      if (s1_ptr[0] == s2_ptr[i])
        return i + 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<lib$locc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <lib$analyze_sdesc@plt>
mov    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1030 <lib$analyze_sdesc@plt>
movzwl -0x2a(%rbp),%eax
cmp    $0x0,%eax
jle    11b3 <lib$locc+0xa3>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movzwl -0x2c(%rbp),%ecx
cmp    %rcx,%rax
jae    11ae <lib$locc+0x9e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1198 <lib$locc+0x88>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11bb <lib$locc+0xab>
jmp    119d <lib$locc+0x8d>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    115b <lib$locc+0x4b>
jmp    11b3 <lib$locc+0xa3>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib$locc>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
xor    %ebx,%ebx
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    %r14,%rdi
xor    %eax,%eax
call   1030 <lib$analyze_sdesc@plt>
cmpw   $0x0,0x6(%rsp)
je     118a <lib$locc+0x7a>
movzwl 0x4(%rsp),%eax
test   %rax,%rax
je     1188 <lib$locc+0x78>
mov    0x10(%rsp),%rcx
mov    (%rcx),%cl
mov    0x8(%rsp),%rdx
neg    %rax
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
cmp    -0x1(%rdx,%rbx,1),%cl
je     118a <lib$locc+0x7a>
lea    (%rax,%rbx,1),%rsi
add    $0x1,%rsi
add    $0x1,%rbx
cmp    $0x1,%rsi
jne    1170 <lib$locc+0x60>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"lib$locc"(%"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 i8*
%8 = alloca i16
%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* %8, 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** %7)
%15 = load i16, i16* %8
%16 = zext i16 %15 to i32
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %43
18: ; preds = %2
store i64 0, i64* %10
br label %19
19: ; preds = %39, %18
%20 = load i64, i64* %10
%21 = load i16, i16* %9
%22 = zext i16 %21 to i64
%23 = icmp ult i64 %20, %22
br i1 %23, label %24, label %42
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i8*, i8** %7
%30 = load i64, i64* %10
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %28, %33
br i1 %34, label %35, label %38
35: ; preds = %24
%36 = load i64, i64* %10
%37 = add i64 %36, 1
store i64 %37, i64* %3
br label %44
38: ; preds = %24
br label %39
39: ; preds = %38
%40 = load i64, i64* %10
%41 = add i64 %40, 1
store i64 %41, i64* %10
br label %19
42: ; preds = %19
br label %43
43: ; preds = %42, %2
store i64 0, i64* %3
br label %44
44: ; preds = %43, %35
%45 = load i64, i64* %3
ret i64 %45
}

LLVM IR (-O2):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"lib$locc"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i16
%7 = bitcast i8** %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = bitcast i16* %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* %5, 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** %4)
%13 = load i16, i16* %5
%14 = icmp eq i16 %13, 0
br i1 %14, label %31, label %15
15: ; preds = %2
%16 = load i16, i16* %6
%17 = zext i16 %16 to i64
%18 = icmp eq i16 %16, 0
br i1 %18, label %31, label %19
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i8, i8* %20
%22 = load i8*, i8** %4
br label %23
23: ; preds = %19, %29
%24 = phi i64 [ 0, %19 ], [ %28, %29 ]
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %21, %26
%28 = add nuw i64 %24, 1
br i1 %27, label %31, label %29
29: ; preds = %23
%30 = icmp eq i64 %28, %17
br i1 %30, label %31, label %23
31: ; preds = %29, %23, %15, %2
%32 = phi i64 [ 0, %2 ], [ 0, %15 ], [ 0, %29 ], [ %28, %23 ]
ret i64 %32
}