#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 int /*<<< orphan*/ HexData;

/* Variables and functions */
int /*<<< orphan*/ CBCDesEncrypt(unsigned char *, int, unsigned char *, int,
                                 unsigned char *);
int /*<<< orphan*/ TriDesDecrypt(unsigned char *, int, unsigned char *, int,
                                 unsigned char *);
int /*<<< orphan*/ TriDesEncrypt(unsigned char *, int, unsigned char *, int,
                                 unsigned char *);
int /*<<< orphan*/ hex2str(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ str2hex(unsigned char *, int, unsigned char *);
int ANSI_X919(unsigned char *MACKey, unsigned char *InData, int InDataLen,
              unsigned char *MAC) {
  int i, b;
  unsigned char Tmp1[20];
  unsigned char Tmp2[20];
  unsigned char Tmp3[20];
  unsigned char HexMacKey[16];
  unsigned char HexData[4096];
  unsigned char OutData[4096];
  int HexDataLen;
  memset(HexData, 0, sizeof(HexData));
  str2hex(HexMacKey, 16, MACKey);
  HexDataLen = InDataLen;
  memcpy(HexData, InData, HexDataLen);
  HexDataLen = (HexDataLen + 7) / 8 * 8;
  CBCDesEncrypt(HexMacKey, 8, HexData, HexDataLen, OutData);
  memcpy(Tmp1, OutData + HexDataLen - 8, 8);
  TriDesDecrypt(HexMacKey + 8, 8, Tmp1, 8, Tmp2);
  TriDesEncrypt(HexMacKey, 8, Tmp2, 8, Tmp3);
  hex2str(MAC, Tmp3, 16);
  return 0;
}


x86 assembly (clang, -O0):
<ANSI_X919>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x1090(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x10,%esi
call   1060 <str2hex@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2094(%rbp)
lea    -0x1090(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2094(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x2094(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
shl    $0x3,%eax
mov    %eax,-0x2094(%rbp)
lea    -0x90(%rbp),%rdi
lea    -0x1090(%rbp),%rdx
mov    -0x2094(%rbp),%ecx
lea    -0x2090(%rbp),%r8
mov    $0x8,%esi
call   1080 <CBCDesEncrypt@plt>
lea    -0x40(%rbp),%rdi
lea    -0x2090(%rbp),%rsi
movslq -0x2094(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffff8,%rsi
mov    $0x8,%edx
call   1070 <memcpy@plt>
lea    -0x90(%rbp),%rdi
add    $0x8,%rdi
lea    -0x40(%rbp),%rdx
lea    -0x60(%rbp),%r8
mov    $0x8,%ecx
mov    %ecx,%esi
call   1050 <TriDesDecrypt@plt>
lea    -0x90(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0x80(%rbp),%r8
mov    $0x8,%ecx
mov    %ecx,%esi
call   1030 <TriDesEncrypt@plt>
mov    -0x20(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x10,%edx
call   1090 <hex2str@plt>
xor    %eax,%eax
add    $0x20a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ANSI_X919>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2078,%rsp
mov    %rcx,%r14
mov    %edx,%ebx
mov    %rsi,%r13
mov    %rdi,%rbp
lea    0x1070(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x10,%esi
mov    %rbp,%rdx
call   1060 <str2hex@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1070 <memcpy@plt>
lea    0x7(%rbx),%eax
add    $0xe,%ebx
test   %eax,%eax
cmovns %eax,%ebx
and    $0xfffffff8,%ebx
lea    0x70(%rsp),%r8
mov    %r15,%rdi
mov    $0x8,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1080 <CBCDesEncrypt@plt>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x68,%rsi
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%edx
call   1070 <memcpy@plt>
lea    0x8(%rsp),%rdi
lea    0x30(%rsp),%rbp
mov    $0x8,%esi
mov    %rbx,%rdx
mov    $0x8,%ecx
mov    %rbp,%r8
call   1050 <TriDesDecrypt@plt>
lea    0x10(%rsp),%rbx
mov    %r15,%rdi
mov    $0x8,%esi
mov    %rbp,%rdx
mov    $0x8,%ecx
mov    %rbx,%r8
call   1030 <TriDesEncrypt@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1090 <hex2str@plt>
xor    %eax,%eax
add    $0x2078,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ANSI_X919(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [20 x i8]
%12 = alloca [20 x i8]
%13 = alloca [20 x i8]
%14 = alloca [16 x i8]
%15 = alloca [4096 x i8]
%16 = alloca [4096 x i8]
%17 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 4096)
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = call i32 @str2hex(i8* %20, i32 16, i8* %21)
%23 = load i32, i32* %7
store i32 %23, i32* %17
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%25 = load i8*, i8** %6
%26 = load i32, i32* %17
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i32, i32* %17
%29 = add nsw i32 %28, 7
%30 = sdiv i32 %29, 8
%31 = mul nsw i32 %30, 8
store i32 %31, i32* %17
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%34 = load i32, i32* %17
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%36 = call i32 @CBCDesEncrypt(i8* %32, i32 8, i8* %33, i32 %34, i8* %35)
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%39 = load i32, i32* %17
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 -8
%43 = call i32 @memcpy(i8* %37, i8* %42, i32 8)
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%45 = getelementptr inbounds i8, i8* %44, i64 8
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%48 = call i32 @TriDesDecrypt(i8* %45, i32 8, i8* %46, i32 8, i8* %47)
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%51 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%52 = call i32 @TriDesEncrypt(i8* %49, i32 8, i8* %50, i32 8, i8* %51)
%53 = load i8*, i8** %8
%54 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%55 = call i32 @hex2str(i8* %53, i8* %54, i32 16)
ret i32 0
}

LLVM IR (-O2):
define i32 @ANSI_X919(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca [20 x i8]
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = alloca [16 x i8]
%9 = alloca [4096 x i8]
%10 = alloca [4096 x i8]
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%17 = call i32 @memset(i8* %15, i32 0, i32 4096)
%18 = call i32 @str2hex(i8* %14, i32 16, i8* %0)
%19 = call i32 @memcpy(i8* %15, i8* %1, i32 %2)
%20 = add nsw i32 %2, 7
%21 = sdiv i32 %20, 8
%22 = shl nsw i32 %21, 3
%23 = call i32 @CBCDesEncrypt(i8* %14, i32 8, i8* %15, i32 %22, i8* %16)
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 -8
%27 = call i32 @memcpy(i8* %11, i8* %26, i32 8)
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 8
%29 = call i32 @TriDesDecrypt(i8* %28, i32 8, i8* %11, i32 8, i8* %12)
%30 = call i32 @TriDesEncrypt(i8* %14, i32 8, i8* %12, i32 8, i8* %13)
%31 = call i32 @hex2str(i8* %3, i8* %13, i32 16)
ret i32 0
}