#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*/ AccInfo;

/* Variables and functions */
int /*<<< orphan*/ TriUnDes(unsigned char *, unsigned char *, unsigned char *);
int /*<<< orphan*/ XOR(unsigned char *, unsigned char *, unsigned char *);
int /*<<< orphan*/ hex2str(char *, unsigned char *, char);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ str2hex(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int UnANSIX98(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;
  *PinLen = 0;
  memset(AccInfo, 0, sizeof(AccInfo));
  CardNoLen = strlen(CardNo);
  strcpy(AccInfo, "0000");
  memcpy(AccInfo + 4, CardNo + CardNoLen - 13, 12);
  str2hex(HexAccInfo, 8, (unsigned char *)AccInfo);
  TriUnDes(EnCryData, Tmp1, TheKey);
  XOR(HexAccInfo, Tmp1, HexPinInfo);
  *PinLen = HexPinInfo[0];
  hex2str(Pin, HexPinInfo + 1, *PinLen);
  return 0;
}


x86 assembly (clang, -O0):
<UnANSIX98>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
cmpl   $0x13,-0x1c(%rbp)
jle    11b8 <UnANSIX98+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1268 <UnANSIX98+0xe8>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffff3,%rsi
mov    $0xc,%edx
call   1080 <memcpy@plt>
lea    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    $0x8,%esi
call   1070 <str2hex@plt>
mov    -0x38(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <TriUnDes@plt>
lea    -0x58(%rbp),%rdi
lea    -0x80(%rbp),%rsi
lea    -0x78(%rbp),%rdx
call   1090 <XOR@plt>
mov    -0x78(%rbp),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rdi
lea    -0x78(%rbp),%rsi
add    $0x1,%rsi
mov    -0x30(%rbp),%rax
movsbl (%rax),%edx
call   10a0 <hex2str@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UnANSIX98>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    $0xffffffff,%ebp
cmp    $0x13,%edx
jg     124e <UnANSIX98+0xce>
mov    %r8,%r15
mov    %rsi,%r14
mov    %rdi,%r12
movb   $0x0,(%r8)
lea    0x30(%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
mov    %rcx,0x18(%rsp)
mov    %r9,0x10(%rsp)
call   1060 <memset@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
lea    0xe25(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x34(%rsp),%rdi
movslq %r13d,%rax
lea    (%r14,%rax,1),%rsi
add    $0xfffffffffffffff3,%rsi
mov    $0xc,%edx
call   1080 <memcpy@plt>
lea    0x28(%rsp),%r14
mov    %r14,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
call   1070 <str2hex@plt>
lea    0x20(%rsp),%rbx
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <TriUnDes@plt>
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <XOR@plt>
movsbl 0x8(%rsp),%edx
mov    %dl,(%r15)
lea    0x9(%rsp),%rsi
mov    0x18(%rsp),%rdi
call   10a0 <hex2str@plt>
mov    %ebp,%eax
add    $0x48,%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 @UnANSIX98(i8* %0, i8* %1, i32 %2, i8* %3, i8* %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 %58
22: ; preds = %6
%23 = load i8*, i8** %12
store i8 0, i8* %23
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 20)
%26 = load i8*, i8** %9
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %10
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 4
%32 = load i8*, i8** %9
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 -13
%37 = call i32 @memcpy(i8* %31, i8* %36, i32 12)
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%40 = call i32 @str2hex(i8* %38, i32 8, i8* %39)
%41 = load i8*, i8** %13
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%43 = load i8*, i8** %8
%44 = call i32 @TriUnDes(i8* %41, i8* %42, i8* %43)
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %17, i64 0, i64 0
%48 = call i32 @XOR(i8* %45, i8* %46, i8* %47)
%49 = getelementptr inbounds [8 x i8], [8 x i8]* %17, i64 0, i64 0
%50 = load i8, i8* %49
%51 = load i8*, i8** %12
store i8 %50, i8* %51
%52 = load i8*, i8** %11
%53 = getelementptr inbounds [8 x i8], [8 x i8]* %17, i64 0, i64 0
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i8*, i8** %12
%56 = load i8, i8* %55
%57 = call i32 @hex2str(i8* %52, i8* %54, i8 signext %56)
store i32 0, i32* %7
br label %58
58: ; preds = %22, %21
%59 = load i32, i32* %7
ret i32 %59
}

LLVM IR (-O2):
@.str = [5 x i8] c"0000\00"
define i32 @UnANSIX98(i8* %0, i8* %1, i32 %2, i8* %3, i8* nocapture writeonly %4, i8* %5) {
%7 = alloca [20 x i8]
%8 = alloca [8 x i8]
%9 = alloca [8 x i8]
%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 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%15 = icmp sgt i32 %2, 19
br i1 %15, label %31, label %16
16: ; preds = %6
store i8 0, i8* %4
%17 = call i32 @memset(i8* %11, i32 0, i32 20)
%18 = call i32 @strlen(i8* %1)
%19 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 4
%21 = sext i32 %18 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 -13
%24 = call i32 @memcpy(i8* %20, i8* %23, i32 12)
%25 = call i32 @str2hex(i8* %12, i32 8, i8* %11)
%26 = call i32 @TriUnDes(i8* %5, i8* %14, i8* %0)
%27 = call i32 @XOR(i8* %12, i8* %14, i8* %13)
%28 = load i8, i8* %13
store i8 %28, i8* %4
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 1
%30 = call i32 @hex2str(i8* %3, i8* %29, i8 signext %28)
br label %31
31: ; preds = %6, %16
%32 = phi i32 [ 0, %16 ], [ -1, %6 ]
ret i32 %32
}