#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 /*<<< orphan*/ funcC(unsigned char, unsigned char *);
int /*<<< orphan*/ funcF(unsigned char *, unsigned char *, unsigned char *,
                         unsigned char *, unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
void ExpandKey(const unsigned char *masterKey, unsigned char *keys) {
  unsigned char C[16] = {0};
  unsigned char temp1[16] = {0};
  unsigned char temp2[16] = {0};
  unsigned char j, i;
  memcpy(keys, masterKey, 16);
  memcpy(keys + 16, masterKey + 16, 16);
  for (j = 0; j < 4; ++j) {
    memcpy(temp1, keys + j * 2 * 16, 16);
    memcpy(temp2, keys + (j * 2 + 1) * 16, 16);
    for (i = 1; i < 8; ++i) {
      funcC(j * 8 + i, C);
      funcF(temp1, temp2, C, temp1, temp2);
    }
    funcC(j * 8 + 8, C);
    funcF(temp1, temp2, C, temp1, temp2);
    memcpy(keys + (j * 2 + 2) * 16, temp1, 16);
    memcpy(keys + (j * 2 + 3) * 16, temp2, 16);
  }
}


x86 assembly (clang, -O0):
<ExpandKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
mov    -0x8(%rbp),%rsi
add    $0x10,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
movb   $0x0,-0x41(%rbp)
movzbl -0x41(%rbp),%eax
cmp    $0x4,%eax
jge    12d6 <ExpandKey+0x196>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movzbl -0x41(%rbp),%eax
shl    $0x1,%eax
shl    $0x4,%eax
cltq
add    %rax,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movzbl -0x41(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
shl    $0x4,%eax
cltq
add    %rax,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
movb   $0x1,-0x42(%rbp)
movzbl -0x42(%rbp),%eax
cmp    $0x8,%eax
jge    1252 <ExpandKey+0x112>
movzbl -0x41(%rbp),%eax
shl    $0x3,%eax
movzbl -0x42(%rbp),%ecx
add    %ecx,%eax
lea    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1030 <funcC@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1060 <funcF@plt>
mov    -0x42(%rbp),%al
add    $0x1,%al
mov    %al,-0x42(%rbp)
jmp    1206 <ExpandKey+0xc6>
movzbl -0x41(%rbp),%eax
shl    $0x3,%eax
add    $0x8,%eax
lea    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1030 <funcC@plt>
lea    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x40(%rbp),%r8
call   1060 <funcF@plt>
mov    -0x10(%rbp),%rdi
movzbl -0x41(%rbp),%eax
shl    $0x1,%eax
add    $0x2,%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rdi
movzbl -0x41(%rbp),%eax
shl    $0x1,%eax
add    $0x3,%eax
shl    $0x4,%eax
cltq
add    %rax,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x41(%rbp),%al
add    $0x1,%al
mov    %al,-0x41(%rbp)
jmp    11b0 <ExpandKey+0x70>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExpandKey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r13
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsi,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
lea    0x10(%r13),%rdi
add    $0x10,%r14
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    $0xffffffffffffffe0,%rbp
lea    0x10(%rsp),%r14
mov    %rsp,%r15
lea    0x20(%rsp),%r12
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
lea    0x10(%r13),%rsi
mov    %r15,%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
lea    0x21(%rbp),%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <funcC@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <funcF@plt>
lea    0x22(%rbp),%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <funcC@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <funcF@plt>
lea    0x23(%rbp),%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <funcC@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <funcF@plt>
lea    0x24(%rbp),%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <funcC@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <funcF@plt>
lea    0x25(%rbp),%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <funcC@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <funcF@plt>
lea    0x26(%rbp),%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <funcC@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <funcF@plt>
lea    0x27(%rbp),%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <funcC@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <funcF@plt>
lea    0x28(%rbp),%eax
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <funcC@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <funcF@plt>
lea    0x20(%r13),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0x30,%r13
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    %rbx,%r13
add    $0x8,%rbp
jne    1190 <ExpandKey+0x60>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @ExpandKey(i8* %0, i8* %1) {
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @memcpy(i8* %1, i8* %0, i32 16)
%10 = getelementptr inbounds i8, i8* %1, i64 16
%11 = getelementptr inbounds i8, i8* %0, i64 16
%12 = tail call i32 @memcpy(i8* %10, i8* %11, i32 16)
br label %13
13: ; preds = %2, %13
%14 = phi i64 [ 0, %2 ], [ %61, %13 ]
%15 = phi i32 [ 0, %2 ], [ %62, %13 ]
%16 = shl nuw nsw i64 %14, 5
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = call i32 @memcpy(i8* %7, i8* %17, i32 16)
%19 = or i64 %16, 16
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = call i32 @memcpy(i8* %8, i8* %20, i32 16)
%22 = shl i32 %15, 3
%23 = trunc i32 %22 to i8
%24 = or i8 %23, 1
%25 = call i32 @funcC(i8 zeroext %24, i8* %6)
%26 = call i32 @funcF(i8* %7, i8* %8, i8* %6, i8* %7, i8* %8)
%27 = trunc i32 %22 to i8
%28 = or i8 %27, 2
%29 = call i32 @funcC(i8 zeroext %28, i8* %6)
%30 = call i32 @funcF(i8* %7, i8* %8, i8* %6, i8* %7, i8* %8)
%31 = trunc i32 %22 to i8
%32 = or i8 %31, 3
%33 = call i32 @funcC(i8 zeroext %32, i8* %6)
%34 = call i32 @funcF(i8* %7, i8* %8, i8* %6, i8* %7, i8* %8)
%35 = trunc i32 %22 to i8
%36 = or i8 %35, 4
%37 = call i32 @funcC(i8 zeroext %36, i8* %6)
%38 = call i32 @funcF(i8* %7, i8* %8, i8* %6, i8* %7, i8* %8)
%39 = trunc i32 %22 to i8
%40 = or i8 %39, 5
%41 = call i32 @funcC(i8 zeroext %40, i8* %6)
%42 = call i32 @funcF(i8* %7, i8* %8, i8* %6, i8* %7, i8* %8)
%43 = trunc i32 %22 to i8
%44 = or i8 %43, 6
%45 = call i32 @funcC(i8 zeroext %44, i8* %6)
%46 = call i32 @funcF(i8* %7, i8* %8, i8* %6, i8* %7, i8* %8)
%47 = trunc i32 %22 to i8
%48 = or i8 %47, 7
%49 = call i32 @funcC(i8 zeroext %48, i8* %6)
%50 = call i32 @funcF(i8* %7, i8* %8, i8* %6, i8* %7, i8* %8)
%51 = trunc i32 %22 to i8
%52 = add i8 %51, 8
%53 = call i32 @funcC(i8 zeroext %52, i8* %6)
%54 = call i32 @funcF(i8* %7, i8* %8, i8* %6, i8* %7, i8* %8)
%55 = add nuw nsw i64 %16, 32
%56 = getelementptr inbounds i8, i8* %1, i64 %55
%57 = call i32 @memcpy(i8* %56, i8* %7, i32 16)
%58 = add nuw nsw i64 %16, 48
%59 = getelementptr inbounds i8, i8* %1, i64 %58
%60 = call i32 @memcpy(i8* %59, i8* %8, i32 16)
%61 = add nuw nsw i64 %14, 1
%62 = add nuw nsw i32 %15, 1
%63 = icmp eq i64 %61, 4
br i1 %63, label %64, label %13
64: ; preds = %13
ret void
}