unsigned long str$len_extr(struct dsc$descriptor_s *destination_string,
                           const struct dsc$descriptor_s *source_string,
                           const long *start_position,
                           const long *longword_integer_length) {
  char *s2_ptr;
  unsigned short s2_length;
  int final_length;
  unsigned short real_final_length;
  unsigned long result;
  unsigned long second_result = 1;
  int start_offset = *start_position;
  if (start_offset <= 0) {
    start_offset = 1;
    second_result = 2392180;
  }
  str$analyze_sdesc(source_string, &s2_length, &s2_ptr);
  if (*longword_integer_length < s2_length - (start_offset - 1)) {
    final_length = *longword_integer_length;
  } else {
    final_length = s2_length - (start_offset - 1);
  }
  if (final_length < 0) {
    real_final_length = 0;
    second_result = 2392180;
  } else {
    real_final_length = (unsigned short)final_length;
  }
  s2_ptr += start_offset - 1;
  result = str$copy_r(destination_string, &real_final_length, s2_ptr);
  if (result == 1) {
    return second_result;
  } else {
    return result;
  }
}


x86 assembly (clang, -O0):
<str$len_extr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x1,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jg     1163 <str$len_extr+0x43>
movl   $0x1,-0x54(%rbp)
movq   $0x248074,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x32(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1040 <str$analyze_sdesc@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movzwl -0x32(%rbp),%ecx
mov    -0x54(%rbp),%edx
sub    $0x1,%edx
sub    %edx,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    11a4 <str$len_extr+0x84>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x38(%rbp)
jmp    11b3 <str$len_extr+0x93>
movzwl -0x32(%rbp),%eax
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11d0 <str$len_extr+0xb0>
movw   $0x0,-0x3a(%rbp)
movq   $0x248074,-0x50(%rbp)
jmp    11d7 <str$len_extr+0xb7>
mov    -0x38(%rbp),%eax
mov    %ax,-0x3a(%rbp)
mov    -0x54(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    -0x3a(%rbp),%rsi
mov    $0x0,%al
call   1030 <str$copy_r@plt>
cltq
mov    %rax,-0x48(%rbp)
cmpq   $0x1,-0x48(%rbp)
jne    121c <str$len_extr+0xfc>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1224 <str$len_extr+0x104>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str$len_extr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rsi,%rax
mov    %rdi,%r14
mov    (%rdx),%ebp
xor    %r15d,%r15d
lea    0xe(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <str$analyze_sdesc@plt>
lea    -0x1(%rbp),%edx
test   %ebp,%ebp
mov    (%rbx),%rax
movzwl 0xe(%rsp),%ecx
cmovle %r15d,%edx
movslq %edx,%rsi
mov    $0x248074,%edi
mov    $0x1,%ebx
cmovle %rdi,%rbx
sub    %rsi,%rcx
cmp    %rcx,%rax
cmovge %ecx,%eax
test   %eax,%eax
cmovle %r15d,%eax
cmovs  %rdi,%rbx
mov    %ax,0xc(%rsp)
add    0x10(%rsp),%rdx
mov    %rdx,0x10(%rsp)
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <str$copy_r@plt>
cmp    $0x1,%eax
cltq
cmove  %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"str$len_extr"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1, i64* %2, i64* %3) {
%5 = alloca i64
%6 = alloca %"struct.dsc$descriptor_s"*
%7 = alloca %"struct.dsc$descriptor_s"*
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i16
%12 = alloca i32
%13 = alloca i16
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
store %"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"** %6
store %"struct.dsc$descriptor_s"* %1, %"struct.dsc$descriptor_s"** %7
store i64* %2, i64** %8
store i64* %3, i64** %9
store i64 1, i64* %15
%17 = load i64*, i64** %8
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %16
%20 = load i32, i32* %16
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %4
store i32 1, i32* %16
store i64 2392180, i64* %15
br label %23
23: ; preds = %22, %4
%24 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %7
%25 = 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"* %24, i16* %11, i8** %10)
%26 = load i64*, i64** %9
%27 = load i64, i64* %26
%28 = load i16, i16* %11
%29 = zext i16 %28 to i32
%30 = load i32, i32* %16
%31 = sub nsw i32 %30, 1
%32 = sub nsw i32 %29, %31
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %27, %33
br i1 %34, label %35, label %39
35: ; preds = %23
%36 = load i64*, i64** %9
%37 = load i64, i64* %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %12
br label %45
39: ; preds = %23
%40 = load i16, i16* %11
%41 = zext i16 %40 to i32
%42 = load i32, i32* %16
%43 = sub nsw i32 %42, 1
%44 = sub nsw i32 %41, %43
store i32 %44, i32* %12
br label %45
45: ; preds = %39, %35
%46 = load i32, i32* %12
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45
store i16 0, i16* %13
store i64 2392180, i64* %15
br label %52
49: ; preds = %45
%50 = load i32, i32* %12
%51 = trunc i32 %50 to i16
store i16 %51, i16* %13
br label %52
52: ; preds = %49, %48
%53 = load i32, i32* %16
%54 = sub nsw i32 %53, 1
%55 = load i8*, i8** %10
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8, i8* %55, i64 %56
store i8* %57, i8** %10
%58 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %6
%59 = load i8*, i8** %10
%60 = call i32 (%"struct.dsc$descriptor_s"*, i16*, i8*, ...) bitcast (i32 (...)* @"str$copy_r" to i32 (%"struct.dsc$descriptor_s"*, i16*, i8*, ...)*)(%"struct.dsc$descriptor_s"* %58, i16* %13, i8* %59)
%61 = sext i32 %60 to i64
store i64 %61, i64* %14
%62 = load i64, i64* %14
%63 = icmp eq i64 %62, 1
br i1 %63, label %64, label %66
64: ; preds = %52
%65 = load i64, i64* %15
store i64 %65, i64* %5
br label %68
66: ; preds = %52
%67 = load i64, i64* %14
store i64 %67, i64* %5
br label %68
68: ; preds = %66, %64
%69 = load i64, i64* %5
ret i64 %69
}

LLVM IR (-O2):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"str$len_extr"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1, i64* nocapture %2, i64* nocapture %3) {
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i16
%8 = bitcast i8** %5 to i8*
%9 = bitcast i16* %6 to i8*
%10 = bitcast i16* %7 to i8*
%11 = load i64, i64* %2
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %12, 1
%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"* %1, i16* %6, i8** %5)
%15 = load i64, i64* %3
%16 = load i16, i16* %6
%17 = zext i16 %16 to i32
%18 = add nsw i32 %12, -1
%19 = select i1 %13, i32 0, i32 %18
%20 = sub nsw i32 %17, %19
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %15, %21
%23 = trunc i64 %15 to i32
%24 = select i1 %22, i32 %23, i32 %20
%25 = icmp slt i32 %24, 0
%26 = icmp sgt i32 %24, 0
%27 = select i1 %26, i32 %24, i32 0
%28 = trunc i32 %27 to i16
%29 = select i1 %25, i1 true, i1 %13
%30 = select i1 %29, i64 2392180, i64 1
store i16 %28, i16* %7
%31 = load i8*, i8** %5
%32 = zext i32 %19 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %5
%34 = call i32 (%"struct.dsc$descriptor_s"*, i16*, i8*, ...) bitcast (i32 (...)* @"str$copy_r" to i32 (%"struct.dsc$descriptor_s"*, i16*, i8*, ...)*)(%"struct.dsc$descriptor_s"* %0, i16* %7, i8* %33)
%35 = icmp eq i32 %34, 1
%36 = sext i32 %34 to i64
%37 = select i1 %35, i64 %30, i64 %36
ret i64 %37
}