#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 */
typedef char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ mrtd_crypto_fix_parity(char *, char *, int, int *);
int /*<<< orphan*/ mrtd_crypto_sha1(char *, int, char *);
void mrtd_bac_kenc_kmac(const uint8_t *input, uint8_t *kenc, uint8_t *kmac) {
  uint8_t hash[20];
  uint8_t k[20];
  uint8_t kenc_tmp[20];
  uint8_t kmac_tmp[20];
  int tmp;
  memcpy(hash, input, 16);
  memcpy(hash + 16, "\x00\x00\x00\x01", 4);
  mrtd_crypto_sha1(hash, 20, k);
  mrtd_crypto_fix_parity(k, kenc_tmp, 20, &tmp);
  memcpy(kenc, kenc_tmp, 16);
  hash[19] = 0x02;
  mrtd_crypto_sha1(hash, 20, k);
  mrtd_crypto_fix_parity(k, kmac_tmp, 20, &tmp);
  memcpy(kmac, kmac_tmp, 16);
}


x86 assembly (clang, -O0):
<mrtd_bac_kenc_kmac>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
lea    -0x30(%rbp),%rdi
add    $0x10,%rdi
lea    0xe98(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    $0x14,%esi
call   1030 <mrtd_crypto_sha1@plt>
lea    -0x50(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x14,%edx
lea    -0x94(%rbp),%rcx
call   1050 <mrtd_crypto_fix_parity@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movb   $0x2,-0x1d(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    $0x14,%esi
call   1030 <mrtd_crypto_sha1@plt>
lea    -0x50(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x14,%edx
lea    -0x94(%rbp),%rcx
call   1050 <mrtd_crypto_fix_parity@plt>
mov    -0x18(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mrtd_bac_kenc_kmac>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdx,(%rsp)
mov    %rsi,%r12
mov    %rdi,%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
lea    0x20(%rsp),%rdi
lea    0xe97(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
lea    0x70(%rsp),%rbx
mov    %r15,%rdi
mov    $0x14,%esi
mov    %rbx,%rdx
call   1030 <mrtd_crypto_sha1@plt>
lea    0x50(%rsp),%r13
lea    0xc(%rsp),%r14
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x14,%edx
mov    %r14,%rcx
call   1050 <mrtd_crypto_fix_parity@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movb   $0x2,0x23(%rsp)
mov    %r15,%rdi
mov    $0x14,%esi
mov    %rbx,%rdx
call   1030 <mrtd_crypto_sha1@plt>
lea    0x30(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x14,%edx
mov    %r14,%rcx
call   1050 <mrtd_crypto_fix_parity@plt>
mov    (%rsp),%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\00\00\00\01\00"
define void @mrtd_bac_kenc_kmac(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [20 x i8]
%8 = alloca [20 x i8]
%9 = alloca [20 x i8]
%10 = alloca [20 x i8]
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @memcpy(i8* %12, i8* %13, i32 16)
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%16 = getelementptr inbounds i8, i8* %15, i64 16
%17 = call i32 @memcpy(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%20 = call i32 @mrtd_crypto_sha1(i8* %18, i32 20, i8* %19)
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%23 = call i32 @mrtd_crypto_fix_parity(i8* %21, i8* %22, i32 20, i32* %11)
%24 = load i8*, i8** %5
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%26 = call i32 @memcpy(i8* %24, i8* %25, i32 16)
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 19
store i8 2, i8* %27
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%30 = call i32 @mrtd_crypto_sha1(i8* %28, i32 20, i8* %29)
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%33 = call i32 @mrtd_crypto_fix_parity(i8* %31, i8* %32, i32 20, i32* %11)
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%36 = call i32 @memcpy(i8* %34, i8* %35, i32 16)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\00\00\00\01\00"
define void @mrtd_bac_kenc_kmac(i8* %0, i8* %1, i8* %2) {
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = alloca i32
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%13 = bitcast i32* %8 to i8*
%14 = call i32 @memcpy(i8* %9, i8* %0, i32 16)
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 16
%16 = call i32 @memcpy(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%17 = call i32 @mrtd_crypto_sha1(i8* %9, i32 20, i8* %10)
%18 = call i32 @mrtd_crypto_fix_parity(i8* %10, i8* %11, i32 20, i32* %8)
%19 = call i32 @memcpy(i8* %1, i8* %11, i32 16)
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 19
store i8 2, i8* %20
%21 = call i32 @mrtd_crypto_sha1(i8* %9, i32 20, i8* %10)
%22 = call i32 @mrtd_crypto_fix_parity(i8* %10, i8* %12, i32 20, i32* %8)
%23 = call i32 @memcpy(i8* %2, i8* %12, i32 16)
ret void
}