unsigned long str$left(struct dsc$descriptor_s *destination_string,
                       const struct dsc$descriptor_s *source_string,
                       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;
  str$analyze_sdesc(source_string, &s2_length, &s2_ptr);
  final_length =
      ((s2_length) < (*end_position) ? (s2_length) : (*end_position));
  if (final_length < 0) {
    real_final_length = 0;
    second_result = 2392180;
  } else {
    real_final_length = (unsigned short)final_length;
  }
  result = str$copy_r(destination_string, &real_final_length, s2_ptr);
  return result;
}


x86 assembly (clang, -O0):
<str$left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x1,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x22(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <str$analyze_sdesc@plt>
movzwl -0x22(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jge    116d <str$left+0x4d>
movzwl -0x22(%rbp),%eax
mov    %rax,-0x48(%rbp)
jmp    1178 <str$left+0x58>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    119c <str$left+0x7c>
movw   $0x0,-0x2a(%rbp)
movq   $0x248074,-0x40(%rbp)
jmp    11a3 <str$left+0x83>
mov    -0x28(%rbp),%eax
mov    %ax,-0x2a(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    -0x2a(%rbp),%rsi
mov    $0x0,%al
call   1030 <str$copy_r@plt>
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str$left>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <str$analyze_sdesc@plt>
movzwl 0xe(%rsp),%eax
mov    (%rbx),%rcx
cmp    %rax,%rcx
cmovg  %rax,%rcx
test   $0x80000000,%ecx
mov    $0x0,%eax
cmove  %ecx,%eax
mov    %ax,0xc(%rsp)
mov    0x10(%rsp),%rdx
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <str$copy_r@plt>
cltq
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"str$left"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1, i64* %2) {
%4 = alloca %"struct.dsc$descriptor_s"*
%5 = alloca %"struct.dsc$descriptor_s"*
%6 = alloca i64*
%7 = alloca i8*
%8 = alloca i16
%9 = alloca i32
%10 = alloca i16
%11 = alloca i64
%12 = alloca i64
store %"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"** %4
store %"struct.dsc$descriptor_s"* %1, %"struct.dsc$descriptor_s"** %5
store i64* %2, i64** %6
store i64 1, i64* %12
%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* %8, i8** %7)
%15 = load i16, i16* %8
%16 = zext i16 %15 to i64
%17 = load i64*, i64** %6
%18 = load i64, i64* %17
%19 = icmp slt i64 %16, %18
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = load i16, i16* %8
%22 = zext i16 %21 to i64
br label %26
23: ; preds = %3
%24 = load i64*, i64** %6
%25 = load i64, i64* %24
br label %26
26: ; preds = %23, %20
%27 = phi i64 [ %22, %20 ], [ %25, %23 ]
%28 = trunc i64 %27 to i32
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i16 0, i16* %10
store i64 2392180, i64* %12
br label %35
32: ; preds = %26
%33 = load i32, i32* %9
%34 = trunc i32 %33 to i16
store i16 %34, i16* %10
br label %35
35: ; preds = %32, %31
%36 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %4
%37 = load i8*, i8** %7
%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"* %36, i16* %10, i8* %37)
%39 = sext i32 %38 to i64
store i64 %39, i64* %11
%40 = load i64, i64* %11
ret i64 %40
}

LLVM IR (-O2):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"str$left"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1, i64* nocapture %2) {
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i16
%7 = bitcast i8** %4 to i8*
%8 = bitcast i16* %5 to i8*
%9 = bitcast i16* %6 to i8*
%10 = 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* %5, i8** %4)
%11 = load i16, i16* %5
%12 = zext i16 %11 to i64
%13 = load i64, i64* %2
%14 = icmp sgt i64 %13, %12
%15 = select i1 %14, i64 %12, i64 %13
%16 = and i64 %15, 2147483648
%17 = icmp eq i64 %16, 0
%18 = trunc i64 %15 to i16
%19 = select i1 %17, i16 %18, i16 0
store i16 %19, i16* %6
%20 = load i8*, i8** %4
%21 = 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* %6, i8* %20)
%22 = sext i32 %21 to i64
ret i64 %22
}