#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 hdSurEncCryptLookup_D2_0F_11(unsigned char, unsigned char);
void hdSurEncPhase2_D2_0F_11_sub(unsigned char *CWa, unsigned char *CWb,
                                 unsigned char AddrInd) {
  unsigned char Buffer[8];
  unsigned char tmp, i;
  for (i = 0; i <= 7; ++i) {
    Buffer[i] = hdSurEncCryptLookup_D2_0F_11(CWb[i], AddrInd);
  }
  tmp = Buffer[7];
  for (i = 7; i >= 1; --i) {
    Buffer[i] = ((Buffer[1] >> 4) & 0xFF) | ((Buffer[i - 1] << 4) & 0xFF);
  }
  Buffer[0] = ((Buffer[0] >> 4) & 0xFF) | ((tmp << 4) & 0xFF);
  for (i = 0; i <= 7; ++i) {
    CWa[i] = CWa[i] ^ Buffer[i];
  }
}


x86 assembly (clang, -O0):
<hdSurEncPhase2_D2_0F_11_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movb   $0x0,-0x1b(%rbp)
movzbl -0x1b(%rbp),%eax
cmp    $0x7,%eax
jg     1164 <hdSurEncPhase2_D2_0F_11_sub+0x54>
mov    -0x10(%rbp),%rax
movzbl -0x1b(%rbp),%ecx
mov    (%rax,%rcx,1),%al
movzbl %al,%edi
movzbl -0x11(%rbp),%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %al,%cl
movzbl -0x1b(%rbp),%eax
mov    %cl,-0x19(%rbp,%rax,1)
mov    -0x1b(%rbp),%al
add    $0x1,%al
mov    %al,-0x1b(%rbp)
jmp    1129 <hdSurEncPhase2_D2_0F_11_sub+0x19>
mov    -0x12(%rbp),%al
mov    %al,-0x1a(%rbp)
movb   $0x7,-0x1b(%rbp)
movzbl -0x1b(%rbp),%eax
cmp    $0x1,%eax
jl     11b8 <hdSurEncPhase2_D2_0F_11_sub+0xa8>
movzbl -0x18(%rbp),%eax
sar    $0x4,%eax
and    $0xff,%eax
movzbl -0x1b(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl -0x19(%rbp,%rcx,1),%ecx
shl    $0x4,%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %al,%cl
movzbl -0x1b(%rbp),%eax
mov    %cl,-0x19(%rbp,%rax,1)
mov    -0x1b(%rbp),%al
add    $0xff,%al
mov    %al,-0x1b(%rbp)
jmp    116e <hdSurEncPhase2_D2_0F_11_sub+0x5e>
movzbl -0x19(%rbp),%eax
sar    $0x4,%eax
and    $0xff,%eax
movzbl -0x1a(%rbp),%ecx
shl    $0x4,%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %al,-0x19(%rbp)
movb   $0x0,-0x1b(%rbp)
movzbl -0x1b(%rbp),%eax
cmp    $0x7,%eax
jg     1218 <hdSurEncPhase2_D2_0F_11_sub+0x108>
mov    -0x8(%rbp),%rax
movzbl -0x1b(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
movzbl -0x1b(%rbp),%ecx
movzbl -0x19(%rbp,%rcx,1),%ecx
xor    %ecx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movzbl -0x1b(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1b(%rbp),%al
add    $0x1,%al
mov    %al,-0x1b(%rbp)
jmp    11da <hdSurEncPhase2_D2_0F_11_sub+0xca>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdSurEncPhase2_D2_0F_11_sub>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r13
movzbl (%rsi),%edi
mov    %edx,%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %al,0x7(%rsp)
movzbl 0x1(%r15),%edi
mov    %ebp,%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %eax,%ebx
movzbl 0x2(%r15),%edi
mov    %ebp,%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %al,0x6(%rsp)
movzbl 0x3(%r15),%edi
mov    %ebp,%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %al,0x5(%rsp)
movzbl 0x4(%r15),%edi
mov    %ebp,%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %al,0x4(%rsp)
movzbl 0x5(%r15),%edi
mov    %ebp,%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %eax,%r14d
movzbl 0x6(%r15),%edi
mov    %ebp,%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %eax,%r12d
movzbl 0x7(%r15),%edi
mov    %ebp,%esi
call   1030 <hdSurEncCryptLookup_D2_0F_11@plt>
mov    %ebx,%ecx
shr    $0x4,%cl
shl    $0x4,%r12b
shl    $0x4,%r14b
mov    0x4(%rsp),%r8b
shl    $0x4,%r8b
rol    $0x4,%bl
mov    %ebx,%esi
mov    0x5(%rsp),%dil
shl    $0x4,%dil
mov    0x7(%rsp),%bl
mov    %ebx,%edx
shl    $0x4,%dl
shr    $0x4,%bl
shl    $0x4,%al
or     %bl,%al
xor    %al,0x0(%r13)
or     %cl,%dl
xor    %dl,0x1(%r13)
mov    0x6(%rsp),%al
shl    $0x4,%al
xor    %sil,0x2(%r13)
or     %cl,%al
xor    %al,0x3(%r13)
mov    %edi,%eax
or     %cl,%al
xor    %al,0x4(%r13)
mov    %r8d,%eax
or     %cl,%al
xor    %al,0x5(%r13)
or     %cl,%r14b
xor    %r14b,0x6(%r13)
or     %cl,%r12b
xor    %r12b,0x7(%r13)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hdSurEncPhase2_D2_0F_11_sub(i8* %0, i8* %1, i8 zeroext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca [8 x i8]
%8 = alloca i8
%9 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
store i8 0, i8* %9
br label %10
10: ; preds = %25, %3
%11 = load i8, i8* %9
%12 = zext i8 %11 to i32
%13 = icmp sle i32 %12, 7
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load i8, i8* %9
%17 = zext i8 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = load i8, i8* %6
%21 = call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %19, i8 zeroext %20)
%22 = load i8, i8* %9
%23 = zext i8 %22 to i64
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %23
store i8 %21, i8* %24
br label %25
25: ; preds = %14
%26 = load i8, i8* %9
%27 = add i8 %26, 1
store i8 %27, i8* %9
br label %10
28: ; preds = %10
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 7
%30 = load i8, i8* %29
store i8 %30, i8* %8
store i8 7, i8* %9
br label %31
31: ; preds = %55, %28
%32 = load i8, i8* %9
%33 = zext i8 %32 to i32
%34 = icmp sge i32 %33, 1
br i1 %34, label %35, label %58
35: ; preds = %31
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 1
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = ashr i32 %38, 4
%40 = and i32 %39, 255
%41 = load i8, i8* %9
%42 = zext i8 %41 to i32
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = shl i32 %47, 4
%49 = and i32 %48, 255
%50 = or i32 %40, %49
%51 = trunc i32 %50 to i8
%52 = load i8, i8* %9
%53 = zext i8 %52 to i64
%54 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %53
store i8 %51, i8* %54
br label %55
55: ; preds = %35
%56 = load i8, i8* %9
%57 = add i8 %56, -1
store i8 %57, i8* %9
br label %31
58: ; preds = %31
%59 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = ashr i32 %61, 4
%63 = and i32 %62, 255
%64 = load i8, i8* %8
%65 = zext i8 %64 to i32
%66 = shl i32 %65, 4
%67 = and i32 %66, 255
%68 = or i32 %63, %67
%69 = trunc i32 %68 to i8
%70 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
store i8 %69, i8* %70
store i8 0, i8* %9
br label %71
71: ; preds = %93, %58
%72 = load i8, i8* %9
%73 = zext i8 %72 to i32
%74 = icmp sle i32 %73, 7
br i1 %74, label %75, label %96
75: ; preds = %71
%76 = load i8*, i8** %4
%77 = load i8, i8* %9
%78 = zext i8 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = load i8, i8* %9
%83 = zext i8 %82 to i64
%84 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %83
%85 = load i8, i8* %84
%86 = zext i8 %85 to i32
%87 = xor i32 %81, %86
%88 = trunc i32 %87 to i8
%89 = load i8*, i8** %4
%90 = load i8, i8* %9
%91 = zext i8 %90 to i64
%92 = getelementptr inbounds i8, i8* %89, i64 %91
store i8 %88, i8* %92
br label %93
93: ; preds = %75
%94 = load i8, i8* %9
%95 = add i8 %94, 1
store i8 %95, i8* %9
br label %71
96: ; preds = %71
ret void
}

LLVM IR (-O2):
define void @hdSurEncPhase2_D2_0F_11_sub(i8* nocapture %0, i8* nocapture %1, i8 zeroext %2) {
%4 = load i8, i8* %1
%5 = tail call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %4, i8 zeroext %2)
%6 = getelementptr inbounds i8, i8* %1, i64 1
%7 = load i8, i8* %6
%8 = tail call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %7, i8 zeroext %2)
%9 = getelementptr inbounds i8, i8* %1, i64 2
%10 = load i8, i8* %9
%11 = tail call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %10, i8 zeroext %2)
%12 = getelementptr inbounds i8, i8* %1, i64 3
%13 = load i8, i8* %12
%14 = tail call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %13, i8 zeroext %2)
%15 = getelementptr inbounds i8, i8* %1, i64 4
%16 = load i8, i8* %15
%17 = tail call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %16, i8 zeroext %2)
%18 = getelementptr inbounds i8, i8* %1, i64 5
%19 = load i8, i8* %18
%20 = tail call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %19, i8 zeroext %2)
%21 = getelementptr inbounds i8, i8* %1, i64 6
%22 = load i8, i8* %21
%23 = tail call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %22, i8 zeroext %2)
%24 = getelementptr inbounds i8, i8* %1, i64 7
%25 = load i8, i8* %24
%26 = tail call zeroext i8 @hdSurEncCryptLookup_D2_0F_11(i8 zeroext %25, i8 zeroext %2)
%27 = tail call i8 @llvm.fshl.i8(i8 %23, i8 %8, i8 4)
%28 = tail call i8 @llvm.fshl.i8(i8 %20, i8 %8, i8 4)
%29 = tail call i8 @llvm.fshl.i8(i8 %17, i8 %8, i8 4)
%30 = tail call i8 @llvm.fshl.i8(i8 %14, i8 %8, i8 4)
%31 = tail call i8 @llvm.fshl.i8(i8 %11, i8 %8, i8 4)
%32 = tail call i8 @llvm.fshl.i8(i8 %8, i8 %8, i8 4)
%33 = tail call i8 @llvm.fshl.i8(i8 %5, i8 %8, i8 4)
%34 = tail call i8 @llvm.fshl.i8(i8 %26, i8 %5, i8 4)
%35 = load i8, i8* %0
%36 = xor i8 %34, %35
store i8 %36, i8* %0
%37 = getelementptr inbounds i8, i8* %0, i64 1
%38 = load i8, i8* %37
%39 = xor i8 %33, %38
store i8 %39, i8* %37
%40 = getelementptr inbounds i8, i8* %0, i64 2
%41 = load i8, i8* %40
%42 = xor i8 %32, %41
store i8 %42, i8* %40
%43 = getelementptr inbounds i8, i8* %0, i64 3
%44 = load i8, i8* %43
%45 = xor i8 %31, %44
store i8 %45, i8* %43
%46 = getelementptr inbounds i8, i8* %0, i64 4
%47 = load i8, i8* %46
%48 = xor i8 %30, %47
store i8 %48, i8* %46
%49 = getelementptr inbounds i8, i8* %0, i64 5
%50 = load i8, i8* %49
%51 = xor i8 %29, %50
store i8 %51, i8* %49
%52 = getelementptr inbounds i8, i8* %0, i64 6
%53 = load i8, i8* %52
%54 = xor i8 %28, %53
store i8 %54, i8* %52
%55 = getelementptr inbounds i8, i8* %0, i64 7
%56 = load i8, i8* %55
%57 = xor i8 %27, %56
store i8 %57, i8* %55
ret void
}