#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 */
unsigned int mulX(unsigned int);
unsigned mul(unsigned a, unsigned b) {
  unsigned v;
  int i;
  v = 0;
  for (i = 0; i < 8; i++) {
    if (b & (1 << i))
      v ^= a;
    a = mulX(a);
  }
  return v;
}


x86 assembly (clang, -O0):
<mul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1172 <mul+0x62>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1159 <mul+0x49>
mov    -0x4(%rbp),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <mulX@plt>
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112c <mul+0x1c>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mul>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xed4(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xed8(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ebx
xor    %r13d,%r13d
test   $0x80,%bl
mov    %edi,%ebp
cmovne %r13d,%ebp
call   1030 <mulX@plt>
test   $0x40,%bl
mov    %eax,%r15d
cmovne %r13d,%r15d
xor    %ebp,%r15d
mov    %eax,%edi
call   1030 <mulX@plt>
test   $0x20,%bl
mov    %eax,%r12d
cmovne %r13d,%r12d
mov    %eax,%edi
call   1030 <mulX@plt>
test   $0x10,%bl
mov    %eax,%r14d
cmovne %r13d,%r14d
xor    %r12d,%r14d
xor    %r15d,%r14d
mov    %eax,%edi
call   1030 <mulX@plt>
test   $0x8,%bl
mov    %eax,%r15d
cmovne %r13d,%r15d
mov    %eax,%edi
call   1030 <mulX@plt>
test   $0x4,%bl
mov    %ebx,%r12d
mov    %eax,%ebx
cmovne %r13d,%ebx
xor    %r15d,%ebx
mov    %eax,%edi
call   1030 <mulX@plt>
test   $0x2,%r12b
mov    %eax,%ebp
cmovne %r13d,%ebp
xor    %ebx,%ebp
xor    %r14d,%ebp
mov    %eax,%edi
call   1030 <mulX@plt>
test   $0x1,%r12b
cmove  %eax,%r13d
xor    %ebp,%r13d
mov    %eax,%edi
call   1030 <mulX@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @mul(i32 %0, i32 %1) {
%3 = insertelement <8 x i32> poison, i32 %1, i64 0
%4 = shufflevector <8 x i32> %3, <8 x i32> poison, <8 x i32> zeroinitializer
%5 = and <8 x i32> %4, <i32 128, i32 64, i32 32, i32 16, i32 8, i32 4, i32 2, i32 1>
%6 = icmp eq <8 x i32> %5, zeroinitializer
%7 = extractelement <8 x i1> %6, i64 7
%8 = select i1 %7, i32 0, i32 %0
%9 = tail call i32 @mulX(i32 %0)
%10 = extractelement <8 x i1> %6, i64 6
%11 = select i1 %10, i32 0, i32 %9
%12 = xor i32 %11, %8
%13 = tail call i32 @mulX(i32 %9)
%14 = extractelement <8 x i1> %6, i64 5
%15 = select i1 %14, i32 0, i32 %13
%16 = xor i32 %15, %12
%17 = tail call i32 @mulX(i32 %13)
%18 = extractelement <8 x i1> %6, i64 4
%19 = select i1 %18, i32 0, i32 %17
%20 = xor i32 %19, %16
%21 = tail call i32 @mulX(i32 %17)
%22 = extractelement <8 x i1> %6, i64 3
%23 = select i1 %22, i32 0, i32 %21
%24 = xor i32 %23, %20
%25 = tail call i32 @mulX(i32 %21)
%26 = extractelement <8 x i1> %6, i64 2
%27 = select i1 %26, i32 0, i32 %25
%28 = xor i32 %27, %24
%29 = tail call i32 @mulX(i32 %25)
%30 = extractelement <8 x i1> %6, i64 1
%31 = select i1 %30, i32 0, i32 %29
%32 = xor i32 %31, %28
%33 = tail call i32 @mulX(i32 %29)
%34 = extractelement <8 x i1> %6, i64 0
%35 = select i1 %34, i32 0, i32 %33
%36 = xor i32 %35, %32
%37 = tail call i32 @mulX(i32 %33)
ret i32 %36
}