char _aes_multiply(char a, char b) {
  switch (a) {
  case 0x1:
    return b;
  case 0x2:
    return __aes_multiply_by_2(b);
  case 0x3:
    return ((b) ^ (_aes_multiply(0x2, b)));
  case 0x9:
    return ((__aes_power_by_2(b, 3)) ^ (b));
  case 0xb:
    return aes_addition(3, __aes_power_by_2(b, 3), __aes_multiply_by_2(b), b);
  case 0xd:
    return aes_addition(3, __aes_power_by_2(b, 3), __aes_power_by_2(b, 2), b);
  case 0xe:
    return aes_addition(3, __aes_power_by_2(b, 3), __aes_power_by_2(b, 2),
                        __aes_multiply_by_2(b));
  default:
    printf("%s: a(%x) and b(%x) is not expected\n", __func__, a, b);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<_aes_multiply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movsbl -0x2(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0xd,%eax
ja     12c9 <_aes_multiply+0x169>
mov    -0x10(%rbp),%rax
lea    0xe6b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x3(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    12f0 <_aes_multiply+0x190>
movsbl -0x3(%rbp),%edi
mov    $0x0,%al
call   1080 <__aes_multiply_by_2@plt>
mov    %al,-0x1(%rbp)
jmp    12f0 <_aes_multiply+0x190>
movsbl -0x3(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x2,%edi
movsbl -0x3(%rbp),%esi
call   1030 <_aes_multiply@plt>
mov    %al,%cl
mov    -0x14(%rbp),%eax
movsbl %cl,%ecx
xor    %ecx,%eax
mov    %al,-0x1(%rbp)
jmp    12f0 <_aes_multiply+0x190>
movsbl -0x3(%rbp),%edi
mov    $0x3,%esi
mov    $0x0,%al
call   1050 <__aes_power_by_2@plt>
movsbl -0x3(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0x1(%rbp)
jmp    12f0 <_aes_multiply+0x190>
movsbl -0x3(%rbp),%edi
mov    $0x3,%esi
mov    $0x0,%al
call   1050 <__aes_power_by_2@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x3(%rbp),%edi
mov    $0x0,%al
call   1080 <__aes_multiply_by_2@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
movsbl -0x3(%rbp),%ecx
mov    $0x3,%edi
mov    $0x0,%al
call   1060 <aes_addition@plt>
mov    %al,-0x1(%rbp)
jmp    12f0 <_aes_multiply+0x190>
movsbl -0x3(%rbp),%edi
mov    $0x3,%esi
mov    $0x0,%al
call   1050 <__aes_power_by_2@plt>
mov    %eax,-0x1c(%rbp)
movsbl -0x3(%rbp),%edi
mov    $0x2,%esi
mov    $0x0,%al
call   1050 <__aes_power_by_2@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
movsbl -0x3(%rbp),%ecx
mov    $0x3,%edi
mov    $0x0,%al
call   1060 <aes_addition@plt>
mov    %al,-0x1(%rbp)
jmp    12f0 <_aes_multiply+0x190>
movsbl -0x3(%rbp),%edi
mov    $0x3,%esi
mov    $0x0,%al
call   1050 <__aes_power_by_2@plt>
mov    %eax,-0x24(%rbp)
movsbl -0x3(%rbp),%edi
mov    $0x2,%esi
mov    $0x0,%al
call   1050 <__aes_power_by_2@plt>
mov    %eax,-0x20(%rbp)
movsbl -0x3(%rbp),%edi
mov    $0x0,%al
call   1080 <__aes_multiply_by_2@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
mov    $0x3,%edi
mov    $0x0,%al
call   1060 <aes_addition@plt>
mov    %al,-0x1(%rbp)
jmp    12f0 <_aes_multiply+0x190>
movsbl -0x2(%rbp),%edx
movsbl -0x3(%rbp),%ecx
lea    0xd60(%rip),%rdi
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_aes_multiply>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%edx
lea    -0x1(%rdx),%eax
cmp    $0xd,%eax
ja     123c <_aes_multiply+0xec>
lea    0xe95(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsbl %bl,%edi
xor    %eax,%eax
call   1070 <__aes_multiply_by_2@plt>
jmp    1233 <_aes_multiply+0xe3>
movsbl %bl,%edi
xor    %eax,%eax
call   1070 <__aes_multiply_by_2@plt>
jmp    119e <_aes_multiply+0x4e>
movsbl %bl,%edi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <__aes_power_by_2@plt>
xor    %bl,%al
mov    %eax,%ebx
jmp    1235 <_aes_multiply+0xe5>
movsbl %bl,%ebx
mov    %ebx,%edi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <__aes_power_by_2@plt>
mov    %eax,%ebp
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <__aes_multiply_by_2@plt>
jmp    11e6 <_aes_multiply+0x96>
movsbl %bl,%ebx
mov    %ebx,%edi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <__aes_power_by_2@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <__aes_power_by_2@plt>
mov    $0x3,%edi
mov    %ebp,%esi
mov    %eax,%edx
mov    %ebx,%ecx
jmp    122c <_aes_multiply+0xdc>
movsbl %bl,%ebx
mov    %ebx,%edi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <__aes_power_by_2@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <__aes_power_by_2@plt>
mov    %eax,%ebp
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <__aes_multiply_by_2@plt>
mov    $0x3,%edi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <aes_addition@plt>
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
movsbl %bl,%ecx
lea    0xdf2(%rip),%rdi
lea    0xe10(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"%s: a(%x) and b(%x) is not expected\0A\00"
@__func__._aes_multiply = [14 x i8] c"_aes_multiply\00"
define signext i8 @_aes_multiply(i8 signext %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
store i8 %0, i8* %4
store i8 %1, i8* %5
%6 = load i8, i8* %4
%7 = sext i8 %6 to i32
switch i32 %7, label %65 [
i32 1, label %8
i32 2, label %10
i32 3, label %15
i32 9, label %23
i32 11, label %31
i32 13, label %42
i32 14, label %53
]
8: ; preds = %2
%9 = load i8, i8* %5
store i8 %9, i8* %3
br label %71
10: ; preds = %2
%11 = load i8, i8* %5
%12 = sext i8 %11 to i32
%13 = call i32 (i32, ...) bitcast (i32 (...)* @__aes_multiply_by_2 to i32 (i32, ...)*)(i32 %12)
%14 = trunc i32 %13 to i8
store i8 %14, i8* %3
br label %71
15: ; preds = %2
%16 = load i8, i8* %5
%17 = sext i8 %16 to i32
%18 = load i8, i8* %5
%19 = call signext i8 @_aes_multiply(i8 signext 2, i8 signext %18)
%20 = sext i8 %19 to i32
%21 = xor i32 %17, %20
%22 = trunc i32 %21 to i8
store i8 %22, i8* %3
br label %71
23: ; preds = %2
%24 = load i8, i8* %5
%25 = sext i8 %24 to i32
%26 = call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %25, i32 3)
%27 = load i8, i8* %5
%28 = sext i8 %27 to i32
%29 = xor i32 %26, %28
%30 = trunc i32 %29 to i8
store i8 %30, i8* %3
br label %71
31: ; preds = %2
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %33, i32 3)
%35 = load i8, i8* %5
%36 = sext i8 %35 to i32
%37 = call i32 (i32, ...) bitcast (i32 (...)* @__aes_multiply_by_2 to i32 (i32, ...)*)(i32 %36)
%38 = load i8, i8* %5
%39 = sext i8 %38 to i32
%40 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @aes_addition to i32 (i32, i32, i32, i32, ...)*)(i32 3, i32 %34, i32 %37, i32 %39)
%41 = trunc i32 %40 to i8
store i8 %41, i8* %3
br label %71
42: ; preds = %2
%43 = load i8, i8* %5
%44 = sext i8 %43 to i32
%45 = call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %44, i32 3)
%46 = load i8, i8* %5
%47 = sext i8 %46 to i32
%48 = call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %47, i32 2)
%49 = load i8, i8* %5
%50 = sext i8 %49 to i32
%51 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @aes_addition to i32 (i32, i32, i32, i32, ...)*)(i32 3, i32 %45, i32 %48, i32 %50)
%52 = trunc i32 %51 to i8
store i8 %52, i8* %3
br label %71
53: ; preds = %2
%54 = load i8, i8* %5
%55 = sext i8 %54 to i32
%56 = call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %55, i32 3)
%57 = load i8, i8* %5
%58 = sext i8 %57 to i32
%59 = call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %58, i32 2)
%60 = load i8, i8* %5
%61 = sext i8 %60 to i32
%62 = call i32 (i32, ...) bitcast (i32 (...)* @__aes_multiply_by_2 to i32 (i32, ...)*)(i32 %61)
%63 = call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @aes_addition to i32 (i32, i32, i32, i32, ...)*)(i32 3, i32 %56, i32 %59, i32 %62)
%64 = trunc i32 %63 to i8
store i8 %64, i8* %3
br label %71
65: ; preds = %2
%66 = load i8, i8* %4
%67 = sext i8 %66 to i32
%68 = load i8, i8* %5
%69 = sext i8 %68 to i32
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__func__._aes_multiply, i64 0, i64 0), i32 %67, i32 %69)
unreachable
71: ; preds = %53, %42, %31, %23, %15, %10, %8
%72 = load i8, i8* %3
ret i8 %72
}

LLVM IR (-O2):
@.str = [37 x i8] c"%s: a(%x) and b(%x) is not expected\0A\00"
@__func__._aes_multiply = [14 x i8] c"_aes_multiply\00"
define signext i8 @_aes_multiply(i8 signext %0, i8 signext %1) {
%3 = sext i8 %0 to i32
switch i32 %3, label %37 [
i32 1, label %40
i32 2, label %4
i32 3, label %8
i32 9, label %13
i32 11, label %18
i32 13, label %24
i32 14, label %30
]
4: ; preds = %2
%5 = sext i8 %1 to i32
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @__aes_multiply_by_2 to i32 (i32, ...)*)(i32 %5)
%7 = trunc i32 %6 to i8
br label %40
8: ; preds = %2
%9 = sext i8 %1 to i32
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @__aes_multiply_by_2 to i32 (i32, ...)*)(i32 %9)
%11 = trunc i32 %10 to i8
%12 = xor i8 %11, %1
br label %40
13: ; preds = %2
%14 = sext i8 %1 to i32
%15 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %14, i32 3)
%16 = trunc i32 %15 to i8
%17 = xor i8 %16, %1
br label %40
18: ; preds = %2
%19 = sext i8 %1 to i32
%20 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %19, i32 3)
%21 = tail call i32 (i32, ...) bitcast (i32 (...)* @__aes_multiply_by_2 to i32 (i32, ...)*)(i32 %19)
%22 = tail call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @aes_addition to i32 (i32, i32, i32, i32, ...)*)(i32 3, i32 %20, i32 %21, i32 %19)
%23 = trunc i32 %22 to i8
br label %40
24: ; preds = %2
%25 = sext i8 %1 to i32
%26 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %25, i32 3)
%27 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %25, i32 2)
%28 = tail call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @aes_addition to i32 (i32, i32, i32, i32, ...)*)(i32 3, i32 %26, i32 %27, i32 %25)
%29 = trunc i32 %28 to i8
br label %40
30: ; preds = %2
%31 = sext i8 %1 to i32
%32 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %31, i32 3)
%33 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @__aes_power_by_2 to i32 (i32, i32, ...)*)(i32 %31, i32 2)
%34 = tail call i32 (i32, ...) bitcast (i32 (...)* @__aes_multiply_by_2 to i32 (i32, ...)*)(i32 %31)
%35 = tail call i32 (i32, i32, i32, i32, ...) bitcast (i32 (...)* @aes_addition to i32 (i32, i32, i32, i32, ...)*)(i32 3, i32 %32, i32 %33, i32 %34)
%36 = trunc i32 %35 to i8
br label %40
37: ; preds = %2
%38 = sext i8 %1 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__func__._aes_multiply, i64 0, i64 0), i32 %3, i32 %38)
tail call void @exit(i32 -1)
unreachable
40: ; preds = %2, %30, %24, %18, %13, %8, %4
%41 = phi i8 [ %36, %30 ], [ %29, %24 ], [ %23, %18 ], [ %17, %13 ], [ %12, %8 ], [ %7, %4 ], [ %1, %2 ]
ret i8 %41
}