int customerPin(unsigned const char *ipvk, const int ipinlength,
                unsigned const char *idectable, unsigned const char *ipinvaldat,
                unsigned char *ioffset, unsigned char *opin, char *errstatus) {
  unsigned char natPin[ipinlength];
  memset(natPin, '\0', ipinlength);
  memset(opin, '\0', ipinlength);
  memset(errstatus, '\0', 100 + 1);
  int k =
      naturalpin(ipvk, ipinlength, idectable, ipinvaldat, natPin, errstatus);
  if (k == -1)
    return -1;
  for (k = 0; k < ipinlength - 1; k++) {
    int i1nat = getHexValue(*(natPin + k));
    int i2off = getHexValue(*(ioffset + k));
    *(opin + k) = getUChar((i1nat + i2off) % 10);
  }
  return 0;
}


x86 assembly (clang, -O0):
<customerPin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x60(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
movslq -0x14(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
movslq -0x14(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x65,%edx
call   1040 <memset@plt>
mov    -0x60(%rbp),%r8
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    0x10(%rbp),%r9
mov    $0x0,%al
call   1030 <naturalpin@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    11f1 <customerPin+0xb1>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    1275 <customerPin+0x135>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1267 <customerPin+0x127>
mov    -0x60(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1060 <getHexValue@plt>
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1060 <getHexValue@plt>
mov    %eax,-0x58(%rbp)
mov    -0x54(%rbp),%eax
add    -0x58(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    $0x0,%al
call   1050 <getUChar@plt>
mov    %al,%dl
mov    -0x38(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11f8 <customerPin+0xb8>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<customerPin>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r15
mov    %r8,-0x38(%rbp)
mov    %rcx,-0x50(%rbp)
mov    %rdx,-0x48(%rbp)
mov    %rdi,-0x40(%rbp)
mov    0x10(%rbp),%r14
mov    %esi,%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsi,-0x30(%rbp)
movslq %esi,%rbx
xor    %r12d,%r12d
mov    %r13,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
movups %xmm0,(%r14)
movups %xmm0,0x10(%r14)
movups %xmm0,0x20(%r14)
movups %xmm0,0x30(%r14)
movups %xmm0,0x40(%r14)
movups %xmm0,0x50(%r14)
movq   $0x0,0x5d(%r14)
mov    -0x40(%rbp),%rdi
mov    %ebx,%esi
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    %r13,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1030 <naturalpin@plt>
cmp    $0xffffffff,%eax
je     1265 <customerPin+0x125>
cmpl   $0x2,-0x30(%rbp)
jl     126b <customerPin+0x12b>
mov    -0x30(%rbp),%rax
add    $0xffffffff,%eax
mov    %rax,-0x30(%rbp)
mov    %r15,%r12
mov    -0x38(%rbp),%r15
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x0(%r13,%r14,1),%edi
xor    %eax,%eax
call   1060 <getHexValue@plt>
mov    %eax,%ebx
movzbl (%r15,%r14,1),%edi
xor    %eax,%eax
call   1060 <getHexValue@plt>
add    %ebx,%eax
movslq %eax,%rdi
imul   $0x66666667,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
xor    %eax,%eax
call   1050 <getUChar@plt>
mov    %al,(%r12,%r14,1)
add    $0x1,%r14
cmp    %r14,-0x30(%rbp)
jne    1210 <customerPin+0xd0>
xor    %r12d,%r12d
jmp    126b <customerPin+0x12b>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @customerPin(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i8* %0, i8** %9
store i32 %1, i32* %10
store i8* %2, i8** %11
store i8* %3, i8** %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i8* %6, i8** %15
%22 = load i32, i32* %10
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %16
%25 = alloca i8, i64 %23
store i64 %23, i64* %17
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = load i8*, i8** %14
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = load i8*, i8** %15
%32 = load i8*, i8** %9
%33 = load i32, i32* %10
%34 = load i8*, i8** %11
%35 = load i8*, i8** %12
%36 = load i8*, i8** %15
%37 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @naturalpin to i32 (i8*, i32, i8*, i8*, i8*, i8*, ...)*)(i8* %32, i32 %33, i8* %34, i8* %35, i8* %25, i8* %36)
store i32 %37, i32* %18
%38 = load i32, i32* %18
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %7
store i32 -1, i32* %8
store i32 1, i32* %19
br label %75
41: ; preds = %7
store i32 0, i32* %18
br label %42
42: ; preds = %71, %41
%43 = load i32, i32* %18
%44 = load i32, i32* %10
%45 = sub nsw i32 %44, 1
%46 = icmp slt i32 %43, %45
br i1 %46, label %47, label %74
47: ; preds = %42
%48 = load i32, i32* %18
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %25, i64 %49
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = call i32 (i32, ...) bitcast (i32 (...)* @getHexValue to i32 (i32, ...)*)(i32 %52)
store i32 %53, i32* %20
%54 = load i8*, i8** %13
%55 = load i32, i32* %18
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i32, ...) bitcast (i32 (...)* @getHexValue to i32 (i32, ...)*)(i32 %59)
store i32 %60, i32* %21
%61 = load i32, i32* %20
%62 = load i32, i32* %21
%63 = add nsw i32 %61, %62
%64 = srem i32 %63, 10
%65 = call i32 (i32, ...) bitcast (i32 (...)* @getUChar to i32 (i32, ...)*)(i32 %64)
%66 = trunc i32 %65 to i8
%67 = load i8*, i8** %14
%68 = load i32, i32* %18
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
store i8 %66, i8* %70
br label %71
71: ; preds = %47
%72 = load i32, i32* %18
%73 = add nsw i32 %72, 1
store i32 %73, i32* %18
br label %42
74: ; preds = %42
store i32 0, i32* %8
store i32 1, i32* %19
br label %75
75: ; preds = %74, %40
%76 = load i8*, i8** %16
%77 = load i32, i32* %8
ret i32 %77
}

LLVM IR (-O2):
define i32 @customerPin(i8* %0, i32 %1, i8* %2, i8* %3, i8* nocapture %4, i8* nocapture writeonly %5, i8* %6) {
%8 = zext i32 %1 to i64
%9 = alloca i8, i64 %8
%10 = sext i32 %1 to i64
tail call void @llvm.memset.p0i8.i64(i8* align 1 %5, i8 0, i64 %10, i1 false)
tail call void @llvm.memset.p0i8.i64(i8* align 1 dereferenceable(101) %6, i8 0, i64 101, i1 false)
%11 = call i32 (i8*, i32, i8*, i8*, i8*, i8*, ...) bitcast (i32 (...)* @naturalpin to i32 (i8*, i32, i8*, i8*, i8*, i8*, ...)*)(i8* %0, i32 %1, i8* %2, i8* %3, i8* %9, i8* %6)
%12 = icmp eq i32 %11, -1
br i1 %12, label %35, label %13
13: ; preds = %7
%14 = icmp sgt i32 %1, 1
br i1 %14, label %15, label %35
15: ; preds = %13
%16 = add nsw i32 %1, -1
%17 = zext i32 %16 to i64
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ 0, %15 ], [ %33, %18 ]
%20 = getelementptr inbounds i8, i8* %9, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 (i32, ...) bitcast (i32 (...)* @getHexValue to i32 (i32, ...)*)(i32 %22)
%24 = getelementptr inbounds i8, i8* %4, i64 %19
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = call i32 (i32, ...) bitcast (i32 (...)* @getHexValue to i32 (i32, ...)*)(i32 %26)
%28 = add nsw i32 %27, %23
%29 = srem i32 %28, 10
%30 = call i32 (i32, ...) bitcast (i32 (...)* @getUChar to i32 (i32, ...)*)(i32 %29)
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %5, i64 %19
store i8 %31, i8* %32
%33 = add nuw nsw i64 %19, 1
%34 = icmp eq i64 %33, %17
br i1 %34, label %35, label %18
35: ; preds = %18, %13, %7
%36 = phi i32 [ -1, %7 ], [ 0, %13 ], [ 0, %18 ]
ret i32 %36
}