unsigned long str$pos_extr(struct dsc$descriptor_s *destination_string,
                           const struct dsc$descriptor_s *source_string,
                           const long *start_position,
                           const long *end_position) {
  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 = 2393097;
  }
  str$analyze_sdesc(source_string, &s2_length, &s2_ptr);
  final_length = s2_length - start_offset + 1;
  if (final_length > *end_position - *start_position + 1) {
    final_length = (*end_position - *start_position + 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$pos_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$pos_extr+0x43>
movl   $0x1,-0x54(%rbp)
movq   $0x248409,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x32(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1040 <str$analyze_sdesc@plt>
movzwl -0x32(%rbp),%eax
sub    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rcx
mov    -0x20(%rbp),%rdx
sub    (%rdx),%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jle    11b7 <str$pos_extr+0x97>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
sub    (%rcx),%rax
add    $0x1,%rax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    11d4 <str$pos_extr+0xb4>
movw   $0x0,-0x3a(%rbp)
movq   $0x248074,-0x50(%rbp)
jmp    11db <str$pos_extr+0xbb>
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    1220 <str$pos_extr+0x100>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1228 <str$pos_extr+0x108>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str$pos_extr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    (%rdx),%edx
test   %edx,%edx
mov    $0x248409,%eax
mov    $0x1,%ebx
cmovle %rax,%rbx
mov    %rcx,%r15
mov    %rsi,%rax
mov    %rdi,%r14
mov    $0x1,%ebp
cmovg  %edx,%ebp
xor    %r13d,%r13d
lea    0xe(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <str$analyze_sdesc@plt>
movzwl 0xe(%rsp),%eax
movslq %ebp,%rdx
mov    %rdx,%rcx
neg    %rcx
add    %rcx,%rax
add    $0x1,%rax
mov    (%r15),%rcx
sub    (%r12),%rcx
add    $0x1,%rcx
cmp    %rax,%rcx
cmovge %eax,%ecx
test   %ecx,%ecx
cmovle %r13d,%ecx
mov    $0x248074,%ebp
cmovns %rbx,%rbp
mov    %cx,0xc(%rsp)
add    $0xffffffff,%edx
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  %rbp,%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 @"str$pos_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 2393097, 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 i16, i16* %11
%27 = zext i16 %26 to i32
%28 = load i32, i32* %16
%29 = sub nsw i32 %27, %28
%30 = add nsw i32 %29, 1
store i32 %30, i32* %12
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = load i64*, i64** %9
%34 = load i64, i64* %33
%35 = load i64*, i64** %8
%36 = load i64, i64* %35
%37 = sub nsw i64 %34, %36
%38 = add nsw i64 %37, 1
%39 = icmp sgt i64 %32, %38
br i1 %39, label %40, label %48
40: ; preds = %23
%41 = load i64*, i64** %9
%42 = load i64, i64* %41
%43 = load i64*, i64** %8
%44 = load i64, i64* %43
%45 = sub nsw i64 %42, %44
%46 = add nsw i64 %45, 1
%47 = trunc i64 %46 to i32
store i32 %47, i32* %12
br label %48
48: ; preds = %40, %23
%49 = load i32, i32* %12
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %48
store i16 0, i16* %13
store i64 2392180, i64* %15
br label %55
52: ; preds = %48
%53 = load i32, i32* %12
%54 = trunc i32 %53 to i16
store i16 %54, i16* %13
br label %55
55: ; preds = %52, %51
%56 = load i32, i32* %16
%57 = sub nsw i32 %56, 1
%58 = load i8*, i8** %10
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds i8, i8* %58, i64 %59
store i8* %60, i8** %10
%61 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %6
%62 = load i8*, i8** %10
%63 = 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"* %61, i16* %13, i8* %62)
%64 = sext i32 %63 to i64
store i64 %64, i64* %14
%65 = load i64, i64* %14
%66 = icmp eq i64 %65, 1
br i1 %66, label %67, label %69
67: ; preds = %55
%68 = load i64, i64* %15
store i64 %68, i64* %5
br label %71
69: ; preds = %55
%70 = load i64, i64* %14
store i64 %70, i64* %5
br label %71
71: ; preds = %69, %67
%72 = load i64, i64* %5
ret i64 %72
}

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