int EnANSIX98(unsigned char *TheKey, char *CardNo, int CardNoLen, char *Pin,
              char PinLen, unsigned char *EnCryData) {
  char AccInfo[20];
  unsigned char HexAccInfo[8];
  char PinInfo[20];
  unsigned char HexPinInfo[8];
  unsigned char Tmp1[8];
  if (CardNoLen > 19)
    return -1;
  if (PinLen > 12)
    return -1;
  memset(AccInfo, 0, sizeof(AccInfo));
  CardNoLen = strlen(CardNo);
  strcpy(AccInfo, "0000");
  memcpy(AccInfo + 4, CardNo + CardNoLen - 13, 12);
  str2hex(HexAccInfo, 8, (unsigned char *)AccInfo);
  memset(HexPinInfo, 0xFF, 8);
  HexPinInfo[0] = PinLen;
  str2hex(HexPinInfo + 1, (PinLen + 1) / 2, (unsigned char *)Pin);
  XOR(HexAccInfo, HexPinInfo, Tmp1);
  TriEnDes(Tmp1, EnCryData, TheKey);
  return 0;
}


x86 assembly (clang, -O0):
<EnANSIX98>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %r8b,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %al,-0x29(%rbp)
mov    %r9,-0x38(%rbp)
cmpl   $0x13,-0x1c(%rbp)
jle    119a <EnANSIX98+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <EnANSIX98+0x115>
movsbl -0x29(%rbp),%eax
cmp    $0xc,%eax
jle    11b3 <EnANSIX98+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1275 <EnANSIX98+0x115>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    -0xd(%rax,%rcx,1),%rdx
mov    %rdx,-0x4c(%rbp)
mov    -0x5(%rax,%rcx,1),%eax
mov    %eax,-0x44(%rbp)
lea    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    $0x8,%esi
mov    $0x0,%al
call   1060 <str2hex@plt>
lea    -0x78(%rbp),%rdi
mov    $0xff,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x29(%rbp),%al
mov    %al,-0x78(%rbp)
lea    -0x78(%rbp),%rdi
add    $0x1,%rdi
movsbl -0x29(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1060 <str2hex@plt>
lea    -0x58(%rbp),%rdi
lea    -0x78(%rbp),%rsi
lea    -0x80(%rbp),%rdx
mov    $0x0,%al
call   1070 <XOR@plt>
lea    -0x80(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1080 <TriEnDes@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EnANSIX98>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0xffffffff,%r13d
cmp    $0x13,%edx
jg     1214 <EnANSIX98+0xd4>
mov    %r8d,%ebx
cmp    $0xc,%bl
jg     1214 <EnANSIX98+0xd4>
mov    %r9,%r14
mov    %rcx,%r12
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
movl   $0x0,0x20(%rsp)
movl   $0x30303030,0x10(%rsp)
30
movb   $0x0,0x14(%rsp)
cltq
mov    -0xd(%rbp,%rax,1),%rcx
mov    %rcx,0x14(%rsp)
mov    -0x5(%rbp,%rax,1),%eax
mov    %eax,0x1c(%rsp)
xor    %r13d,%r13d
lea    0x30(%rsp),%rbp
lea    0x10(%rsp),%rdx
mov    %rbp,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <str2hex@plt>
movq   $0xffffffffffffffff,0x8(%rsp)
ff ff
mov    %bl,0x8(%rsp)
lea    0x9(%rsp),%rdi
add    $0x1,%bl
mov    %ebx,%eax
shr    $0x7,%al
add    %bl,%al
sar    %al
movsbl %al,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <str2hex@plt>
lea    0x8(%rsp),%rsi
lea    0x28(%rsp),%rbx
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <XOR@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <TriEnDes@plt>
mov    %r13d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0000\00"
define i32 @EnANSIX98(i8* %0, i8* %1, i32 %2, i8* %3, i8 signext %4, i8* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8
%13 = alloca i8*
%14 = alloca [20 x i8]
%15 = alloca [8 x i8]
%16 = alloca [20 x i8]
%17 = alloca [8 x i8]
%18 = alloca [8 x i8]
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8 %4, i8* %12
store i8* %5, i8** %13
%19 = load i32, i32* %10
%20 = icmp sgt i32 %19, 19
br i1 %20, label %21, label %22
21: ; preds = %6
store i32 -1, i32* %7
br label %63
22: ; preds = %6
%23 = load i8, i8* %12
%24 = sext i8 %23 to i32
%25 = icmp sgt i32 %24, 12
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 -1, i32* %7
br label %63
27: ; preds = %22
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%29 = load i8*, i8** %9
%30 = call i64 @strlen(i8* %29)
%31 = trunc i64 %30 to i32
store i32 %31, i32* %10
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%33 = call i8* @strcpy(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 4
%36 = load i8*, i8** %9
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = getelementptr inbounds i8, i8* %39, i64 -13
%41 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%43 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @str2hex to i32 (i8*, i32, i8*, ...)*)(i8* %41, i32 8, i8* %42)
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %17, i64 0, i64 0
%45 = load i8, i8* %12
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %17, i64 0, i64 0
store i8 %45, i8* %46
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %17, i64 0, i64 0
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = load i8, i8* %12
%50 = sext i8 %49 to i32
%51 = add nsw i32 %50, 1
%52 = sdiv i32 %51, 2
%53 = load i8*, i8** %11
%54 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @str2hex to i32 (i8*, i32, i8*, ...)*)(i8* %48, i32 %52, i8* %53)
%55 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%56 = getelementptr inbounds [8 x i8], [8 x i8]* %17, i64 0, i64 0
%57 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%58 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @XOR to i32 (i8*, i8*, i8*, ...)*)(i8* %55, i8* %56, i8* %57)
%59 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%60 = load i8*, i8** %13
%61 = load i8*, i8** %8
%62 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @TriEnDes to i32 (i8*, i8*, i8*, ...)*)(i8* %59, i8* %60, i8* %61)
store i32 0, i32* %7
br label %63
63: ; preds = %27, %26, %21
%64 = load i32, i32* %7
ret i32 %64
}

LLVM IR (-O2):
@.str = [5 x i8] c"0000\00"
define i32 @EnANSIX98(i8* %0, i8* nocapture %1, i32 %2, i8* %3, i8 signext %4, i8* %5) {
%7 = alloca [20 x i8]
%8 = alloca [8 x i8]
%9 = alloca i64
%10 = alloca [8 x i8]
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%13 = bitcast i64* %9 to i8*
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%15 = icmp sgt i32 %2, 19
%16 = icmp sgt i8 %4, 12
%17 = or i1 %15, %16
br i1 %17, label %35, label %18
18: ; preds = %6
%19 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 16
%21 = bitcast i8* %20 to i32*
store i32 0, i32* %21
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 4
%23 = shl i64 %19, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds i8, i8* %1, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 -13
%27 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @str2hex to i32 (i8*, i32, i8*, ...)*)(i8* %12, i32 8, i8* %11)
store i64 -1, i64* %9
store i8 %4, i8* %13
%28 = getelementptr inbounds i8, i8* %13, i64 1
%29 = add nsw i8 %4, 1
%30 = sdiv i8 %29, 2
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, i32, i8*, ...) bitcast (i32 (...)* @str2hex to i32 (i8*, i32, i8*, ...)*)(i8* %28, i32 %31, i8* %3)
%33 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @XOR to i32 (i8*, i8*, i8*, ...)*)(i8* %12, i8* %13, i8* %14)
%34 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @TriEnDes to i32 (i8*, i8*, i8*, ...)*)(i8* %14, i8* %5, i8* %0)
br label %35
35: ; preds = %6, %18
%36 = phi i32 [ 0, %18 ], [ -1, %6 ]
ret i32 %36
}