#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 char xtime(unsigned char);
unsigned char bd(unsigned char a, unsigned char b) {
  unsigned char V[8];
  unsigned char sum = 0;
  int i;
  V[0] = a;
  for (i = 1; i < 8; i++) {
    V[i] = xtime(V[i - 1]);
  }
  for (i = 0; i < 8; i++) {
    if (((b >> i) & 0x1) == 0x1) {
      sum ^= V[i];
    }
  }
  return sum;
}


x86 assembly (clang, -O0):
<bd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
movb   $0x0,-0xb(%rbp)
mov    -0x1(%rbp),%al
mov    %al,-0xa(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1169 <bd+0x59>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
cltq
movzbl -0xa(%rbp,%rax,1),%edi
call   1030 <xtime@plt>
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0xa(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1135 <bd+0x25>
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    11b4 <bd+0xa4>
movzbl -0x2(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x1,%eax
jne    11a1 <bd+0x91>
movslq -0x10(%rbp),%rax
movzbl -0xa(%rbp,%rax,1),%ecx
movzbl -0xb(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0xb(%rbp)
jmp    11a6 <bd+0x96>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1170 <bd+0x60>
movzbl -0xb(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,(%rsp)
mov    %edi,0x4(%rsp)
call   1030 <xtime@plt>
movzbl %al,%ebp
mov    %ebp,%edi
call   1030 <xtime@plt>
movzbl %al,%r15d
mov    %r15d,%edi
call   1030 <xtime@plt>
movzbl %al,%ebx
mov    %ebx,%edi
call   1030 <xtime@plt>
movzbl %al,%r12d
mov    %r12d,%edi
call   1030 <xtime@plt>
movzbl %al,%r13d
mov    %r13d,%edi
call   1030 <xtime@plt>
movzbl %al,%r14d
mov    %r14d,%edi
call   1030 <xtime@plt>
movd   (%rsp),%xmm0
pshufd $0x0,%xmm0,%xmm1
movdqa 0xe83(%rip),%xmm0
pand   %xmm1,%xmm0
pand   0xe87(%rip),%xmm1
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm1
pcmpeqd %xmm2,%xmm0
packssdw %xmm1,%xmm0
packsswb %xmm0,%xmm0
shl    $0x8,%ebx
or     %r15d,%ebx
shl    $0x8,%ebp
add    0x4(%rsp),%ebp
movd   %ebp,%xmm1
pinsrw $0x1,%ebx,%xmm1
shl    $0x8,%r13d
or     %r12d,%r13d
pinsrw $0x2,%r13d,%xmm1
movzbl %al,%eax
shl    $0x8,%eax
or     %r14d,%eax
pinsrw $0x3,%eax,%xmm1
pandn  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
pxor   %xmm0,%xmm1
movdqa %xmm1,%xmm0
psrld  $0x10,%xmm0
pxor   %xmm1,%xmm0
movdqa %xmm0,%xmm1
psrlw  $0x8,%xmm1
pxor   %xmm0,%xmm1
movd   %xmm1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @bd(i8 zeroext %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca [8 x i8]
%6 = alloca i8
%7 = alloca i32
store i8 %0, i8* %3
store i8 %1, i8* %4
store i8 0, i8* %6
%8 = load i8, i8* %3
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
store i8 %8, i8* %9
store i32 1, i32* %7
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 8
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call zeroext i8 @xtime(i8 zeroext %18)
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %21
store i8 %19, i8* %22
br label %23
23: ; preds = %13
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %10
26: ; preds = %10
store i32 0, i32* %7
br label %27
27: ; preds = %48, %26
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 8
br i1 %29, label %30, label %51
30: ; preds = %27
%31 = load i8, i8* %4
%32 = zext i8 %31 to i32
%33 = load i32, i32* %7
%34 = ashr i32 %32, %33
%35 = and i32 %34, 1
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %47
37: ; preds = %30
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = load i8, i8* %6
%44 = zext i8 %43 to i32
%45 = xor i32 %44, %42
%46 = trunc i32 %45 to i8
store i8 %46, i8* %6
br label %47
47: ; preds = %37, %30
br label %48
48: ; preds = %47
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %27
51: ; preds = %27
%52 = load i8, i8* %6
ret i8 %52
}

LLVM IR (-O2):
define zeroext i8 @bd(i8 zeroext %0, i8 zeroext %1) {
%3 = tail call zeroext i8 @xtime(i8 zeroext %0)
%4 = tail call zeroext i8 @xtime(i8 zeroext %3)
%5 = tail call zeroext i8 @xtime(i8 zeroext %4)
%6 = tail call zeroext i8 @xtime(i8 zeroext %5)
%7 = tail call zeroext i8 @xtime(i8 zeroext %6)
%8 = tail call zeroext i8 @xtime(i8 zeroext %7)
%9 = tail call zeroext i8 @xtime(i8 zeroext %8)
%10 = zext i8 %1 to i32
%11 = insertelement <8 x i32> poison, i32 %10, i64 0
%12 = shufflevector <8 x i32> %11, <8 x i32> poison, <8 x i32> zeroinitializer
%13 = and <8 x i32> %12, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%14 = icmp eq <8 x i32> %13, zeroinitializer
%15 = insertelement <8 x i8> poison, i8 %0, i64 0
%16 = insertelement <8 x i8> %15, i8 %3, i64 1
%17 = insertelement <8 x i8> %16, i8 %4, i64 2
%18 = insertelement <8 x i8> %17, i8 %5, i64 3
%19 = insertelement <8 x i8> %18, i8 %6, i64 4
%20 = insertelement <8 x i8> %19, i8 %7, i64 5
%21 = insertelement <8 x i8> %20, i8 %8, i64 6
%22 = insertelement <8 x i8> %21, i8 %9, i64 7
%23 = select <8 x i1> %14, <8 x i8> zeroinitializer, <8 x i8> %22
%24 = call i8 @llvm.vector.reduce.xor.v8i8(<8 x i8> %23)
ret i8 %24
}