#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int generate(unsigned int);
int movmask(int const);
int /*<<< orphan*/ printf(char *, int const, int const, unsigned int);
int test32() {
  for (unsigned mask = 0; mask < 16; mask++) {
    const uint32_t input = generate(mask);
    assert((input & 0x7f7f7f7f) == 0);
    const uint32_t result = movmask(input);
    if (result != mask) {
      printf("%08x => %x (expected %x)\n", input, result, mask);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<test32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jae    11c7 <test32+0x87>
mov    -0x8(%rbp),%edi
call   1060 <generate@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7f7f7f7f,%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%edi
call   1050 <movmask@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     11b4 <test32+0x74>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ce <test32+0x8e>
jmp    11b9 <test32+0x79>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114f <test32+0xf>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test32>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %edi,%edi
call   1060 <generate@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   $0x7f7f7f7f,%eax
sete   %dil
call   1040 <assert@plt>
mov    %ebp,%edi
call   1050 <movmask@plt>
test   %eax,%eax
je     116f <test32+0x2f>
mov    $0x1,%bl
jmp    11be <test32+0x7e>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x10,%ebx
je     11dc <test32+0x9c>
mov    %ebx,%edi
call   1060 <generate@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   $0x7f7f7f7f,%eax
sete   %dil
call   1040 <assert@plt>
mov    %ebp,%edi
call   1050 <movmask@plt>
lea    0x1(%rbx),%r14d
cmp    %eax,%ebx
mov    %r14d,%ebx
je     1180 <test32+0x40>
lea    -0x2(%r14),%ecx
cmp    $0xf,%ecx
setb   %bl
add    $0xffffffff,%r14d
lea    0xe3b(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %r14d,%ecx
call   1030 <printf@plt>
xor    $0x1,%bl
movzbl %bl,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
add    $0xffffffff,%ebx
cmp    $0xf,%ebx
setb   %bl
jmp    11d1 <test32+0x91>

LLVM IR (-O0):
@.str = [26 x i8] c"%08x => %x (expected %x)\0A\00"
define i32 @test32() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %2
br label %5
5: ; preds = %27, %0
%6 = load i32, i32* %2
%7 = icmp ult i32 %6, 16
br i1 %7, label %8, label %30
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i32 @generate(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = and i32 %11, 2139062143
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %3
%17 = call i32 @movmask(i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %8
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = load i32, i32* %2
%25 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23, i32 %24)
store i32 0, i32* %1
br label %31
26: ; preds = %8
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add i32 %28, 1
store i32 %29, i32* %2
br label %5
30: ; preds = %5
store i32 1, i32* %1
br label %31
31: ; preds = %30, %21
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [26 x i8] c"%08x => %x (expected %x)\0A\00"
define i32 @test32() {
%1 = tail call i32 @generate(i32 0)
%2 = and i32 %1, 2139062143
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @movmask(i32 %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %24, label %18
8: ; preds = %24
%9 = tail call i32 @generate(i32 %26)
%10 = and i32 %9, 2139062143
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @movmask(i32 %9)
%15 = icmp eq i32 %14, %26
br i1 %15, label %24, label %16
16: ; preds = %8
%17 = icmp ult i32 %25, 15
br label %18
18: ; preds = %16, %0
%19 = phi i1 [ true, %0 ], [ %17, %16 ]
%20 = phi i32 [ 0, %0 ], [ %26, %16 ]
%21 = phi i32 [ %1, %0 ], [ %9, %16 ]
%22 = phi i32 [ %6, %0 ], [ %14, %16 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22, i32 %20)
br label %30
24: ; preds = %0, %8
%25 = phi i32 [ %26, %8 ], [ 0, %0 ]
%26 = add nuw nsw i32 %25, 1
%27 = icmp eq i32 %26, 16
br i1 %27, label %28, label %8
28: ; preds = %24
%29 = icmp ult i32 %25, 15
br label %30
30: ; preds = %28, %18
%31 = phi i1 [ %19, %18 ], [ %29, %28 ]
%32 = xor i1 %31, true
%33 = zext i1 %32 to i32
ret i32 %33
}