unsigned long str$upcase(struct dsc$descriptor_s *destination_string,
                         const struct dsc$descriptor_s *source_string) {
  char *s1_ptr;
  unsigned short s1_length;
  unsigned long result;
  result = str$copy_dx(destination_string, source_string);
  if ((result & 1) == 1) {
    str$analyze_sdesc(destination_string, &s1_length, &s1_ptr);
    while (s1_length > 0) {
      *s1_ptr = toupper(*s1_ptr);
      s1_ptr++;
      s1_length--;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<str$upcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1030 <str$copy_dx@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
and    $0x1,%rax
cmp    $0x1,%rax
jne    11bd <str$upcase+0x8d>
mov    -0x8(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <str$analyze_sdesc@plt>
movzwl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jle    11b8 <str$upcase+0x88>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1a(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0x1a(%rbp)
jmp    117a <str$upcase+0x4a>
jmp    11bd <str$upcase+0x8d>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str$upcase>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <str$copy_dx@plt>
movslq %eax,%r14
test   $0x1,%r14b
je     1190 <str$upcase+0x60>
lea    0xe(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <str$analyze_sdesc@plt>
cmpw   $0x0,0xe(%rsp)
je     1190 <str$upcase+0x60>
mov    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <toupper@plt>
mov    %al,(%rbx)
mov    0x10(%rsp),%rbx
add    $0x1,%rbx
mov    %rbx,0x10(%rsp)
addw   $0xffff,0xe(%rsp)
jne    1170 <str$upcase+0x40>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%"struct.dsc$descriptor_s" = type opaque
define i64 @"str$upcase"(%"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"* %1) {
%3 = alloca %"struct.dsc$descriptor_s"*
%4 = alloca %"struct.dsc$descriptor_s"*
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i64
store %"struct.dsc$descriptor_s"* %0, %"struct.dsc$descriptor_s"** %3
store %"struct.dsc$descriptor_s"* %1, %"struct.dsc$descriptor_s"** %4
%8 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %3
%9 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %4
%10 = call i32 (%"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"*, ...) bitcast (i32 (...)* @"str$copy_dx" to i32 (%"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"*, ...)*)(%"struct.dsc$descriptor_s"* %8, %"struct.dsc$descriptor_s"* %9)
%11 = sext i32 %10 to i64
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = and i64 %12, 1
%14 = icmp eq i64 %13, 1
br i1 %14, label %15, label %34
15: ; preds = %2
%16 = load %"struct.dsc$descriptor_s"*, %"struct.dsc$descriptor_s"** %3
%17 = 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"* %16, i16* %6, i8** %5)
br label %18
18: ; preds = %22, %15
%19 = load i16, i16* %6
%20 = zext i16 %19 to i32
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = call i32 @toupper(i32 %25)
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %5
store i8 %27, i8* %28
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
%31 = load i16, i16* %6
%32 = add i16 %31, -1
store i16 %32, i16* %6
br label %18
33: ; preds = %18
br label %34
34: ; preds = %33, %2
%35 = load i64, i64* %7
ret i64 %35
}

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