void print_result_code(char *presult, unsigned long result_code, char *cont) {
  char errmsg[80];
  unsigned short int errmsglen;
  unsigned int flags = 3;
  if (sys$$geterrno(presult) != result_code) {
    sys$$getmsg(result_code, &errmsglen, errmsg, flags);
    printf("FAILED - Unexpected Result Code \n");
    printf("Expected %s result code \n", presult);
    printf("Result code is %lu %s \n\n", result_code, errmsg);
    strcpy(cont, "P");
  } else {
    printf("Result Code .....OK ");
    sys$$getmsg(result_code, &errmsglen, errmsg, flags);
    printf(" %lu %s \n", result_code, errmsg);
  }
}


x86 assembly (clang, -O0):
<print_result_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x3,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1050 <sys$$geterrno@plt>
cltq
cmp    -0x10(%rbp),%rax
je     11d6 <print_result_code+0x96>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%ecx
lea    -0x72(%rbp),%rsi
mov    $0x0,%al
call   1040 <sys$$getmsg@plt>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1210 <print_result_code+0xd0>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%ecx
lea    -0x72(%rbp),%rsi
mov    $0x0,%al
call   1040 <sys$$getmsg@plt>
mov    -0x10(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_result_code>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <sys$$geterrno@plt>
cltq
cmp    %rbx,%rax
jne    11a2 <print_result_code+0x62>
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe(%rsp),%rsi
lea    0x10(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x3,%ecx
xor    %eax,%eax
call   1040 <sys$$getmsg@plt>
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f5 <print_result_code+0xb5>
lea    0xe(%rsp),%rsi
lea    0x10(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rdx
mov    $0x3,%ecx
xor    %eax,%eax
call   1040 <sys$$getmsg@plt>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2f(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe38(%rip),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
movw   $0x50,(%r14)
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"FAILED - Unexpected Result Code \0A\00"
@.str.1 = [26 x i8] c"Expected %s result code \0A\00"
@.str.2 = [25 x i8] c"Result code is %lu %s \0A\0A\00"
@.str.3 = [2 x i8] c"P\00"
@.str.4 = [21 x i8] c"Result Code .....OK \00"
@.str.5 = [10 x i8] c" %lu %s \0A\00"
define void @print_result_code(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca [80 x i8]
%8 = alloca i16
%9 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
store i32 3, i32* %9
%10 = load i8*, i8** %4
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @"sys$$geterrno" to i32 (i8*, ...)*)(i8* %10)
%12 = sext i32 %11 to i64
%13 = load i64, i64* %5
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %3
%16 = load i64, i64* %5
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* %9
%19 = call i32 (i64, i16*, i8*, i32, ...) bitcast (i32 (...)* @"sys$$getmsg" to i32 (i64, i16*, i8*, i32, ...)*)(i64 %16, i16* %8, i8* %17, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i64, i64* %5
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %23, i8* %24)
%26 = load i8*, i8** %6
%27 = call i8* @strcpy(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %37
28: ; preds = %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%30 = load i64, i64* %5
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%32 = load i32, i32* %9
%33 = call i32 (i64, i16*, i8*, i32, ...) bitcast (i32 (...)* @"sys$$getmsg" to i32 (i64, i16*, i8*, i32, ...)*)(i64 %30, i16* %8, i8* %31, i32 %32)
%34 = load i64, i64* %5
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i64 %34, i8* %35)
br label %37
37: ; preds = %28, %15
ret void
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"Expected %s result code \0A\00"
@.str.2 = [25 x i8] c"Result code is %lu %s \0A\0A\00"
@.str.4 = [21 x i8] c"Result Code .....OK \00"
@.str.5 = [10 x i8] c" %lu %s \0A\00"
@str = [33 x i8] c"FAILED - Unexpected Result Code \00"
define void @print_result_code(i8* %0, i64 %1, i8* nocapture writeonly %2) {
%4 = alloca [80 x i8]
%5 = alloca i16
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%7 = bitcast i16* %5 to i8*
%8 = tail call i32 (i8*, ...) bitcast (i32 (...)* @"sys$$geterrno" to i32 (i8*, ...)*)(i8* %0)
%9 = sext i32 %8 to i64
%10 = icmp eq i64 %9, %1
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = call i32 (i64, i16*, i8*, i32, ...) bitcast (i32 (...)* @"sys$$getmsg" to i32 (i64, i16*, i8*, i32, ...)*)(i64 %1, i16* %5, i8* %6, i32 3)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %1, i8* %6)
%16 = bitcast i8* %2 to i16*
store i16 80, i16* %16
br label %21
17: ; preds = %3
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 (i64, i16*, i8*, i32, ...) bitcast (i32 (...)* @"sys$$getmsg" to i32 (i64, i16*, i8*, i32, ...)*)(i64 %1, i16* %5, i8* %6, i32 3)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i64 %1, i8* %6)
br label %21
21: ; preds = %17, %11
ret void
}