int simd_alignment(void) {
  int cpuinfo[4];
  cpuinfo[0] = 1;
  __asm__ __volatile__("mov %%ebx, %%edi;"
                       "cpuid;"
                       "mov %%ebx, %%esi;"
                       "mov %%edi, %%ebx;"
                       : "+a"(cpuinfo[0]), "=S"(cpuinfo[1]), "=c"(cpuinfo[2]),
                         "=d"(cpuinfo[3])
                       :
                       : "edi");
  if (cpuinfo[2] & (1 << 28))
    return 32;
  else if (cpuinfo[3] & (1 << 25))
    return 16;
  else
    return 4;
}


x86 assembly (clang, -O0):
<simd_alignment>:
push   %rbp
mov    %rsp,%rbp
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %ebx,%edi
cpuid
mov    %ebx,%esi
mov    %edi,%ebx
mov    %eax,-0x20(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x18(%rbp),%eax
and    $0x10000000,%eax
cmp    $0x0,%eax
je     113f <simd_alignment+0x3f>
movl   $0x20,-0x4(%rbp)
jmp    1163 <simd_alignment+0x63>
mov    -0x14(%rbp),%eax
and    $0x2000000,%eax
cmp    $0x0,%eax
je     115c <simd_alignment+0x5c>
movl   $0x10,-0x4(%rbp)
jmp    1163 <simd_alignment+0x63>
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<simd_alignment>:
mov    $0x1,%eax
mov    %ebx,%edi
cpuid
mov    %ebx,%esi
mov    %edi,%ebx
test   $0x2000000,%edx
mov    $0x4,%eax
mov    $0x10,%edx
cmove  %eax,%edx
test   $0x10000000,%ecx
mov    $0x20,%eax
cmove  %edx,%eax
ret

LLVM IR (-O0):
define i32 @simd_alignment() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
store i32 1, i32* %3
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%5 = load i32, i32* %4
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%9 = call { i32, i32, i32, i32 } asm sideeffect "mov %ebx, %edi;cpuid;mov %ebx, %esi;mov %edi, %ebx;", "={ax},={si},={cx},={dx},0,~{edi},~{dirflag},~{fpsr},~{flags}"(i32 %5)
%10 = extractvalue { i32, i32, i32, i32 } %9, 0
%11 = extractvalue { i32, i32, i32, i32 } %9, 1
%12 = extractvalue { i32, i32, i32, i32 } %9, 2
%13 = extractvalue { i32, i32, i32, i32 } %9, 3
store i32 %10, i32* %4
store i32 %11, i32* %6
store i32 %12, i32* %7
store i32 %13, i32* %8
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%15 = load i32, i32* %14
%16 = and i32 %15, 268435456
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %0
store i32 32, i32* %1
br label %26
19: ; preds = %0
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%21 = load i32, i32* %20
%22 = and i32 %21, 33554432
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 16, i32* %1
br label %26
25: ; preds = %19
store i32 4, i32* %1
br label %26
26: ; preds = %25, %24, %18
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
define i32 @simd_alignment() {
%1 = tail call { i32, i32, i32, i32 } asm sideeffect "mov %ebx, %edi;cpuid;mov %ebx, %esi;mov %edi, %ebx;", "={ax},={si},={cx},={dx},0,~{edi},~{dirflag},~{fpsr},~{flags}"(i32 1)
%2 = extractvalue { i32, i32, i32, i32 } %1, 2
%3 = and i32 %2, 268435456
%4 = icmp eq i32 %3, 0
%5 = extractvalue { i32, i32, i32, i32 } %1, 3
%6 = and i32 %5, 33554432
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i32 4, i32 16
%9 = select i1 %4, i32 %8, i32 32
ret i32 %9
}