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


x86 assembly (clang, -O0):
<lib$matchc>:
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 <str$analyze_sdesc@plt>
mov    -0x18(%rbp),%rdi
lea    -0x32(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1030 <str$analyze_sdesc@plt>
movzwl -0x32(%rbp),%eax
cmp    $0x0,%eax
jne    117d <lib$matchc+0x5d>
movzwl -0x22(%rbp),%eax
cmp    $0x0,%eax
je     117d <lib$matchc+0x5d>
movq   $0x0,-0x8(%rbp)
jmp    1208 <lib$matchc+0xe8>
movzwl -0x22(%rbp),%eax
cmp    $0x0,%eax
jne    1197 <lib$matchc+0x77>
movq   $0x1,-0x8(%rbp)
jmp    1208 <lib$matchc+0xe8>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movzwl -0x32(%rbp),%ecx
movzwl -0x22(%rbp),%edx
sub    %edx,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jg     1200 <lib$matchc+0xe0>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    -0x40(%rbp),%rsi
movzwl -0x22(%rbp),%eax
mov    %eax,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11ea <lib$matchc+0xca>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <lib$matchc+0xe8>
jmp    11ef <lib$matchc+0xcf>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    119f <lib$matchc+0x7f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lib$matchc>:
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 <str$analyze_sdesc@plt>
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <str$analyze_sdesc@plt>
movzwl 0x4(%rsp),%ebx
movzwl 0x6(%rsp),%eax
test   %rbx,%rbx
jne    116d <lib$matchc+0x4d>
test   %ax,%ax
jne    11c3 <lib$matchc+0xa3>
movzwl %ax,%r12d
test   %r12,%r12
je     1181 <lib$matchc+0x61>
cmp    %r12w,%bx
jae    1189 <lib$matchc+0x69>
xor    %r14d,%r14d
jmp    11c3 <lib$matchc+0xa3>
mov    $0x1,%r14d
jmp    11c3 <lib$matchc+0xa3>
mov    0x10(%rsp),%r15
mov    0x8(%rsp),%r13
sub    %r12,%rbx
add    $0x1,%rbx
xor    %r14d,%r14d
xor    %ebp,%ebp
nop
mov    %r13,%rsi
add    %rbp,%rsi
mov    %r15,%rdi
mov    %r12,%rdx
call   1040 <bcmp@plt>
add    $0x1,%rbp
test   %eax,%eax
je     11c0 <lib$matchc+0xa0>
cmp    %rbp,%rbx
jne    11a0 <lib$matchc+0x80>
jmp    11c3 <lib$matchc+0xa3>
mov    %rbp,%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$matchc"(%"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 (...)* @"str$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 (...)* @"str$analyze_sdesc" to i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...)*)(%"struct.dsc$descriptor_s"* %13, i16* %9, i8** %8)
%15 = load i16, i16* %9
%16 = zext i16 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i16, i16* %7
%20 = zext i16 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i64 0, i64* %3
br label %55
23: ; preds = %18, %2
%24 = load i16, i16* %7
%25 = zext i16 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i64 1, i64* %3
br label %55
28: ; preds = %23
store i64 0, i64* %10
br label %29
29: ; preds = %51, %28
%30 = load i64, i64* %10
%31 = load i16, i16* %9
%32 = zext i16 %31 to i32
%33 = load i16, i16* %7
%34 = zext i16 %33 to i32
%35 = sub nsw i32 %32, %34
%36 = sext i32 %35 to i64
%37 = icmp sle i64 %30, %36
br i1 %37, label %38, label %54
38: ; preds = %29
%39 = load i8*, i8** %6
%40 = load i8*, i8** %8
%41 = load i64, i64* %10
%42 = getelementptr inbounds i8, i8* %40, i64 %41
%43 = load i16, i16* %7
%44 = zext i16 %43 to i64
%45 = call i32 @memcmp(i8* %39, i8* %42, i64 %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %38
%48 = load i64, i64* %10
%49 = add nsw i64 %48, 1
store i64 %49, i64* %3
br label %55
50: ; preds = %38
br label %51
51: ; preds = %50
%52 = load i64, i64* %10
%53 = add nsw i64 %52, 1
store i64 %53, i64* %10
br label %29
54: ; preds = %29
store i64 0, i64* %3
br label %55
55: ; preds = %54, %47, %27, %22
%56 = load i64, i64* %3
ret i64 %56
}

LLVM IR (-O2):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"lib$matchc"(%"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 (...)* @"str$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 (...)* @"str$analyze_sdesc" to i32 (%"struct.dsc$descriptor_s"*, i16*, i8**, ...)*)(%"struct.dsc$descriptor_s"* %1, i16* %6, i8** %5)
%13 = load i16, i16* %6
%14 = icmp eq i16 %13, 0
%15 = load i16, i16* %4
%16 = icmp ne i16 %15, 0
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %37, label %18
18: ; preds = %2
%19 = icmp eq i16 %15, 0
br i1 %19, label %37, label %20
20: ; preds = %18
%21 = zext i16 %15 to i64
%22 = icmp ult i16 %13, %15
br i1 %22, label %37, label %23
23: ; preds = %20
%24 = zext i16 %13 to i64
%25 = load i8*, i8** %3
%26 = load i8*, i8** %5
%27 = add nuw nsw i64 %24, 1
%28 = sub nsw i64 %27, %21
br label %29
29: ; preds = %23, %35
%30 = phi i64 [ 0, %23 ], [ %34, %35 ]
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = call i32 @bcmp(i8* %25, i8* %31, i64 %21)
%33 = icmp eq i32 %32, 0
%34 = add nuw nsw i64 %30, 1
br i1 %33, label %37, label %35
35: ; preds = %29
%36 = icmp eq i64 %34, %28
br i1 %36, label %37, label %29
37: ; preds = %35, %29, %20, %18, %2
%38 = phi i64 [ 0, %2 ], [ 1, %18 ], [ 0, %20 ], [ 0, %35 ], [ %34, %29 ]
ret i64 %38
}