unsigned long str$trim(struct dsc$descriptor_s *destination_string,
                       const struct dsc$descriptor_s *source_string,
                       unsigned short *resultant_length) {
  char *s2_ptr;
  unsigned short s2_length;
  unsigned long result;
  str$analyze_sdesc(source_string, &s2_length, &s2_ptr);
  while ((s2_length > 0) &&
         ((s2_ptr[s2_length - 1] == ' ') || (s2_ptr[s2_length - 1] == '\t'))) {
    s2_length--;
  }
  result = str$copy_r(destination_string, &s2_length, s2_ptr);
  *resultant_length = s2_length;
  return result;
}


x86 assembly (clang, -O0):
<str$trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%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),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
jle    119a <str$trim+0x7a>
mov    -0x20(%rbp),%rax
movzwl -0x22(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x32(%rbp)
je     1194 <str$trim+0x74>
mov    -0x20(%rbp),%rax
movzwl -0x22(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11aa <str$trim+0x8a>
jmp    11bb <str$trim+0x9b>
mov    -0x22(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0x22(%rbp)
jmp    1147 <str$trim+0x27>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    -0x22(%rbp),%rsi
mov    $0x0,%al
call   1030 <str$copy_r@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x22(%rbp),%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str$trim>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rax
mov    %rdi,%rbx
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    0x10(%rsp),%rdx
test   %rax,%rax
je     117f <str$trim+0x5f>
mov    $0xffffffff,%ecx
add    %rcx,%rax
jmp    116f <str$trim+0x4f>
nopl   (%rax)
mov    %ax,0xe(%rsp)
add    $0xffffffffffffffff,%rax
cmp    $0xffff,%ax
je     117f <str$trim+0x5f>
mov    %eax,%ecx
movzbl (%rdx,%rcx,1),%ecx
cmp    $0x20,%cl
je     1160 <str$trim+0x40>
cmp    $0x9,%cl
je     1160 <str$trim+0x40>
lea    0xe(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <str$copy_r@plt>
cltq
movzwl 0xe(%rsp),%ecx
mov    %cx,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"str$trim"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1, i16* %2) {
%4 = alloca %"struct.dsc$descriptor_s"*
%5 = alloca %"struct.dsc$descriptor_s"*
%6 = alloca i16*
%7 = alloca i8*
%8 = alloca i16
%9 = 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 i16* %2, i16** %6
%10 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %5
%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"* %10, i16* %8, i8** %7)
br label %12
12: ; preds = %40, %3
%13 = load i16, i16* %8
%14 = zext i16 %13 to i32
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = load i16, i16* %8
%19 = zext i16 %18 to i32
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %17, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 32
br i1 %25, label %36, label %26
26: ; preds = %16
%27 = load i8*, i8** %7
%28 = load i16, i16* %8
%29 = zext i16 %28 to i32
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 9
br label %36
36: ; preds = %26, %16
%37 = phi i1 [ true, %16 ], [ %35, %26 ]
br label %38
38: ; preds = %36, %12
%39 = phi i1 [ false, %12 ], [ %37, %36 ]
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i16, i16* %8
%42 = add i16 %41, -1
store i16 %42, i16* %8
br label %12
43: ; preds = %38
%44 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %4
%45 = load i8*, i8** %7
%46 = 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"* %44, i16* %8, i8* %45)
%47 = sext i32 %46 to i64
store i64 %47, i64* %9
%48 = load i16, i16* %8
%49 = load i16*, i16** %6
store i16 %48, i16* %49
%50 = load i64, i64* %9
ret i64 %50
}

LLVM IR (-O2):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"str$trim"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1, i16* nocapture writeonly %2) {
%4 = alloca i8*
%5 = alloca i16
%6 = bitcast i8** %4 to i8*
%7 = bitcast i16* %5 to i8*
%8 = 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)
%9 = load i16, i16* %5
%10 = icmp eq i16 %9, 0
%11 = load i8*, i8** %4
br i1 %10, label %24, label %12
12: ; preds = %3
%13 = zext i16 %9 to i64
br label %14
14: ; preds = %12, %20
%15 = phi i64 [ %13, %12 ], [ %21, %20 ]
%16 = add nuw nsw i64 %15, 4294967295
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds i8, i8* %11, i64 %17
%19 = load i8, i8* %18
switch i8 %19, label %24 [
i8 32, label %20
i8 9, label %20
]
20: ; preds = %14, %14
%21 = add nsw i64 %15, -1
%22 = trunc i64 %21 to i16
store i16 %22, i16* %5
%23 = icmp eq i16 %22, 0
br i1 %23, label %24, label %14
24: ; preds = %20, %14, %3
%25 = 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* %5, i8* %11)
%26 = sext i32 %25 to i64
%27 = load i16, i16* %5
store i16 %27, i16* %2
ret i64 %26
}