#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 */

/* Variables and functions */
int vtom(int);
int mtop(int mask) {
  int i;
  int count = 0;
  for (i = 1; i < 10; i++) {
    if (mask & vtom(i))
      count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<mtop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    116d <mtop+0x5d>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <vtom@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
and    %ecx,%eax
cmp    $0x0,%eax
je     115a <mtop+0x4a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115f <mtop+0x4f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1129 <mtop+0x19>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mtop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,0xc(%rsp)
mov    $0x1,%edi
call   1030 <vtom@plt>
mov    %eax,0x10(%rsp)
mov    $0x2,%edi
call   1030 <vtom@plt>
mov    %eax,%r12d
mov    $0x3,%edi
call   1030 <vtom@plt>
mov    %eax,%r13d
mov    $0x4,%edi
call   1030 <vtom@plt>
mov    %eax,%ebx
mov    $0x5,%edi
call   1030 <vtom@plt>
mov    %eax,%ebp
mov    $0x6,%edi
call   1030 <vtom@plt>
mov    %eax,%r14d
mov    $0x7,%edi
call   1030 <vtom@plt>
mov    %eax,%r15d
mov    $0x8,%edi
call   1030 <vtom@plt>
movd   0x10(%rsp),%xmm2
movd   %r12d,%xmm0
punpckldq %xmm0,%xmm2
movd   %r13d,%xmm0
movd   %ebx,%xmm1
punpckldq %xmm1,%xmm0
punpcklqdq %xmm0,%xmm2
movdqa %xmm2,%xmm3
movd   %ebp,%xmm2
movd   %r14d,%xmm0
punpckldq %xmm0,%xmm2
movd   %r15d,%xmm0
movd   %eax,%xmm1
punpckldq %xmm1,%xmm0
punpcklqdq %xmm0,%xmm2
mov    0xc(%rsp),%ebx
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
pand   %xmm0,%xmm2
movdqa %xmm2,0x10(%rsp)
pand   %xmm0,%xmm3
movdqa %xmm3,0x20(%rsp)
mov    $0x9,%edi
call   1030 <vtom@plt>
and    %ebx,%eax
movdqa 0x20(%rsp),%xmm1
pxor   %xmm3,%xmm3
pcmpeqd %xmm3,%xmm1
pcmpeqd %xmm0,%xmm0
pxor   %xmm0,%xmm1
movdqa 0x10(%rsp),%xmm2
pcmpeqd %xmm3,%xmm2
pxor   %xmm0,%xmm2
packssdw %xmm2,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ecx
mov    %ecx,%edx
shr    %dl
and    $0x55,%dl
sub    %dl,%cl
mov    %ecx,%edx
and    $0x33,%dl
shr    $0x2,%cl
and    $0x33,%cl
add    %dl,%cl
mov    %ecx,%edx
shr    $0x4,%dl
add    %cl,%dl
and    $0xf,%dl
movzbl %dl,%ecx
cmp    $0x1,%eax
sbb    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mtop(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 1, i32* %3
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = call i32 @vtom(i32 %10)
%12 = and i32 %9, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %17
17: ; preds = %14, %8
br label %18
18: ; preds = %17
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %5
21: ; preds = %5
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
define i32 @mtop(i32 %0) {
%2 = tail call i32 @vtom(i32 1)
%3 = tail call i32 @vtom(i32 2)
%4 = tail call i32 @vtom(i32 3)
%5 = tail call i32 @vtom(i32 4)
%6 = tail call i32 @vtom(i32 5)
%7 = tail call i32 @vtom(i32 6)
%8 = tail call i32 @vtom(i32 7)
%9 = tail call i32 @vtom(i32 8)
%10 = insertelement <8 x i32> poison, i32 %2, i64 0
%11 = insertelement <8 x i32> %10, i32 %3, i64 1
%12 = insertelement <8 x i32> %11, i32 %4, i64 2
%13 = insertelement <8 x i32> %12, i32 %5, i64 3
%14 = insertelement <8 x i32> %13, i32 %6, i64 4
%15 = insertelement <8 x i32> %14, i32 %7, i64 5
%16 = insertelement <8 x i32> %15, i32 %8, i64 6
%17 = insertelement <8 x i32> %16, i32 %9, i64 7
%18 = insertelement <8 x i32> poison, i32 %0, i64 0
%19 = shufflevector <8 x i32> %18, <8 x i32> poison, <8 x i32> zeroinitializer
%20 = and <8 x i32> %17, %19
%21 = icmp ne <8 x i32> %20, zeroinitializer
%22 = tail call i32 @vtom(i32 9)
%23 = and i32 %22, %0
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i32
%26 = bitcast <8 x i1> %21 to i8
%27 = call i8 @llvm.ctpop.i8(i8 %26)
%28 = zext i8 %27 to i32
%29 = add nuw nsw i32 %28, %25
ret i32 %29
}