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) {
    __asm__ __volatile__(".byte 0x00f, 0x001, 0x0c1"
                         : "=a"(result)
                         : "a"(tuple), "b"(reg_ebx), "c"(reg_ecx),
                           "d"(reg_edx));
  } else {
    result = -1;
  }
  return result;
}


x86 assembly (clang, -O0):
<__unisys_extended_vmcall_gnuc>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x38,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    $0x1,%edi
lea    -0x34(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
lea    -0x40(%rbp),%r8
mov    $0x0,%al
call   1030 <cpuid@plt>
mov    -0x3c(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     117a <__unisys_extended_vmcall_gnuc+0x6a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rbx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rdx
vmcall
mov    %rax,-0x30(%rbp)
jmp    1182 <__unisys_extended_vmcall_gnuc+0x72>
movq   $0xffffffffffffffff,-0x30(%rbp)
ff
mov    -0x30(%rbp),%rax
add    $0x38,%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 i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
store i64 0, i64* %9
%14 = call i32 (i32, i32*, i32*, i32*, i32*, ...) bitcast (i32 (...)* @cpuid to i32 (i32, i32*, i32*, i32*, i32*, ...)*)(i32 1, i32* %10, i32* %11, i32* %12, i32* %13)
%15 = load i32, i32* %12
%16 = and i32 %15, -2147483648
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %4
%19 = load i64, i64* %5
%20 = load i64, i64* %6
%21 = load i64, i64* %7
%22 = load i64, i64* %8
%23 = call i64 asm sideeffect ".byte 0x00f, 0x001, 0x0c1", "={ax},{ax},{bx},{cx},{dx},~{dirflag},~{fpsr},~{flags}"(i64 %19, i64 %20, i64 %21, i64 %22)
store i64 %23, i64* %9
br label %25
24: ; preds = %4
store i64 -1, i64* %9
br label %25
25: ; preds = %24, %18
%26 = load i64, i64* %9
ret i64 %26
}

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
}