int foo(int s) {
  for (;;) {
    int a[32];
    int y, z;
    __asm__ __volatile__(""
                         : "=c"(y), "=D"(z)
                         : "a"(0), "0"(32), "1"(a)
                         : "memory");
    if (({
          register char r;
          __asm__ __volatile__(""
                               : "=q"(r)
                               : "r"(s % 32), "m"(a[s / 32])
                               : "cc");
          r;
        }))
      continue;
    else if (({
               register char r;
               __asm__ __volatile__("" : "=q"(r) : "r"(0), "m"(a) : "cc");
               r;
             }))
      continue;
  }
  return 0;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
xor    %eax,%eax
mov    $0x20,%ecx
mov    %ecx,-0x94(%rbp)
mov    %edi,%eax
mov    %eax,-0x98(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,-0xa0(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    -0xa0(%rbp),%edx
movslq %eax,%rcx
lea    -0x90(%rbp),%rax
shl    $0x2,%rcx
add    %rcx,%rax
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%al
mov    %al,-0x9a(%rbp)
cmpb   $0x0,-0x9a(%rbp)
je     117e <foo+0x7e>
jmp    110b <foo+0xb>
xor    %eax,%eax
mov    %al,-0x9b(%rbp)
mov    -0x9b(%rbp),%al
mov    %al,-0x9c(%rbp)
cmpb   $0x0,-0x9c(%rbp)
je     11a4 <foo+0xa4>
jmp    110b <foo+0xb>
jmp    11a9 <foo+0xa9>
jmp    110b <foo+0xb>

x86 assembly (clang, -O2):
<foo>:
push   %rax
mov    %edi,%edx
lea    0x1f(%rdx),%eax
test   %edi,%edi
cmovns %edi,%eax
mov    %eax,%ecx
and    $0xffffffe0,%ecx
sub    %ecx,%edx
sar    $0x5,%eax
movslq %eax,%rsi
xor    %r9d,%r9d
lea    -0x80(%rsp),%r8
xor    %eax,%eax
mov    %r8,%rdi
mov    $0x20,%ecx
test   %al,%al
jne    1120 <foo+0x20>
jmp    1120 <foo+0x20>

LLVM IR (-O0):
define i32 @foo(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
store i32 %0, i32* %2
br label %10
10: ; preds = %35, %33, %27, %1
%11 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%12 = call { i32, i32* } asm sideeffect "", "={cx},={di},{ax},0,1,~{memory},~{dirflag},~{fpsr},~{flags}"(i32 0, i32 32, i32* %11)
%13 = extractvalue { i32, i32* } %12, 0
%14 = extractvalue { i32, i32* } %12, 1
store i32 %13, i32* %4
%15 = ptrtoint i32* %14 to i64
%16 = trunc i64 %15 to i32
store i32 %16, i32* %5
%17 = load i32, i32* %2
%18 = srem i32 %17, 32
%19 = load i32, i32* %2
%20 = sdiv i32 %19, 32
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %21
%23 = call i8 asm sideeffect "", "=q,r,*m,~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %18, i32* elementtype(i32) %22)
store i8 %23, i8* %6
%24 = load i8, i8* %6
store i8 %24, i8* %7
%25 = load i8, i8* %7
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %10
br label %10
28: ; preds = %10
%29 = call i8 asm sideeffect "", "=q,r,*m,~{cc},~{dirflag},~{fpsr},~{flags}"(i32 0, [32 x i32]* elementtype([32 x i32]) %3)
store i8 %29, i8* %8
%30 = load i8, i8* %8
store i8 %30, i8* %9
%31 = load i8, i8* %9
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
br label %10
34: ; preds = %28
br label %35
35: ; preds = %34
br label %10
}

LLVM IR (-O2):
define i32 @foo(i32 %0) {
%2 = alloca [32 x i32]
%3 = bitcast [32 x i32]* %2 to i8*
%4 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 0
%5 = srem i32 %0, 32
%6 = sdiv i32 %0, 32
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %7
br label %9
9: ; preds = %15, %1
%10 = call { i32, i32* } asm sideeffect "", "={cx},={di},{ax},0,1,~{memory},~{dirflag},~{fpsr},~{flags}"(i32 0, i32 32, i32* %4)
%11 = call i8 asm sideeffect "", "=q,r,*m,~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %5, i32* elementtype(i32) %8)
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i8 asm sideeffect "", "=q,r,*m,~{cc},~{dirflag},~{fpsr},~{flags}"(i32 0, [32 x i32]* elementtype([32 x i32]) %2)
br label %15
15: ; preds = %13, %9
br label %9
}