unsigned long __unisys_extended_vmcall_gnuc(unsigned long long tuple,
                                            unsigned long long reg_ebx,
                                            unsigned long long reg_ecx,
                                            unsigned long long reg_edx) {
  unsigned long result = 0;
  unsigned int cpuid_eax, cpuid_ebx, cpuid_ecx, cpuid_edx;
  cpuid(0x00000001, &cpuid_eax, &cpuid_ebx, &cpuid_ecx, &cpuid_edx);
  if (!(cpuid_ecx & 0x80000000))
    return -1;
  __asm__ __volatile__(".byte 0x00f, 0x001, 0x0c1"
                       : "=a"(result)
                       : "a"(tuple), "b"(reg_ebx), "c"(reg_ecx), "d"(reg_edx));
  return result;
}


x86 assembly (clang, -O0):
<__unisys_extended_vmcall_gnuc>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x48,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x1,%edi
lea    -0x3c(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x44(%rbp),%rcx
lea    -0x48(%rbp),%r8
mov    $0x0,%al
call   1030 <cpuid@plt>
mov    -0x44(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
jne    116b <__unisys_extended_vmcall_gnuc+0x5b>
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
jmp    118a <__unisys_extended_vmcall_gnuc+0x7a>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rbx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%rdx
vmcall
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<__unisys_extended_vmcall_gnuc>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <cpuid@plt>
mov    $0xffffffffffffffff,%rax
cmpl   $0x0,0x8(%rsp)
jns    1164 <__unisys_extended_vmcall_gnuc+0x54>
mov    %rbx,%rax
mov    %r12,%rbx
mov    %r15,%rcx
mov    %r14,%rdx
vmcall
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @__unisys_extended_vmcall_gnuc(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i64 %0, i64* %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 0, i64* %10
%15 = call i32 (i32, i32*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @cpuid to i32 (i32, i32*, i32*, i32*, i32*, ...)*)(i32 1, i32* %11, i32* %12, i32* %13, i32* %14)
%16 = load i32, i32* %13
%17 = and i32 %16, -2147483648
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %4
store i64 -1, i64* %5
br label %27
20: ; preds = %4
%21 = load i64, i64* %6
%22 = load i64, i64* %7
%23 = load i64, i64* %8
%24 = load i64, i64* %9
%25 = call i64 asm sideeffect ".byte 0x00f, 0x001, 0x0c1", "={ax},{ax},{bx},{cx},{dx},~{dirflag},~{fpsr},~{flags}"(i64 %21, i64 %22, i64 %23, i64 %24)
store i64 %25, i64* %10
%26 = load i64, i64* %10
store i64 %26, i64* %5
br label %27
27: ; preds = %20, %19
%28 = load i64, i64* %5
ret i64 %28
}

LLVM IR (-O2):
define i64 @__unisys_extended_vmcall_gnuc(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = bitcast i32* %8 to i8*
%13 = call i32 (i32, i32*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @cpuid to i32 (i32, i32*, i32*, i32*, i32*, ...)*)(i32 1, i32* %5, i32* %6, i32* %7, i32* %8)
%14 = load i32, i32* %7
%15 = icmp sgt i32 %14, -1
br i1 %15, label %18, label %16
16: ; preds = %4
%17 = call i64 asm sideeffect ".byte 0x00f, 0x001, 0x0c1", "={ax},{ax},{bx},{cx},{dx},~{dirflag},~{fpsr},~{flags}"(i64 %0, i64 %1, i64 %2, i64 %3)
br label %18
18: ; preds = %4, %16
%19 = phi i64 [ %17, %16 ], [ -1, %4 ]
ret i64 %19
}