int ibm3624Offset(unsigned const char *ipvk, unsigned const char *ipin,
                  unsigned const char *idectable,
                  unsigned const char *ipinvaldat, unsigned char *offset,
                  char *errstatus) {
  int k = 0;
  memset(errstatus, '\0', 100 + 1);
  int pinLength = validatePin(ipin, errstatus);
  if (pinLength == -1)
    return -1;
  pinLength++;
  unsigned char natPin[pinLength];
  memset(natPin, '\0', pinLength);
  memset(offset, '\0', pinLength);
  k = naturalpin(ipvk, pinLength, idectable, ipinvaldat, natPin, errstatus);
  if (k == -1)
    return -1;
  for (k = 0; k < pinLength - 1; k++) {
    int i1nat = getHexValue(*(natPin + k));
    int i2pin = getHexValue(*(ipin + k));
    *(offset + k) = getUChar((10 - i1nat + i2pin) % 10);
  }
  return 0;
}


x86 assembly (clang, -O0):
<ibm3624Offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x65,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x0,%al
call   1060 <validatePin@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    11af <ibm3624Offset+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c6 <ibm3624Offset+0x176>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x68(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
movslq -0x40(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x30(%rbp),%rdi
movslq -0x40(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x68(%rbp),%r8
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%r9
mov    $0x0,%al
call   1030 <naturalpin@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1236 <ibm3624Offset+0xe6>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    12bf <ibm3624Offset+0x16f>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x40(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12b1 <ibm3624Offset+0x161>
mov    -0x68(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1070 <getHexValue@plt>
mov    %eax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1070 <getHexValue@plt>
mov    %eax,-0x5c(%rbp)
mov    $0xa,%eax
sub    -0x58(%rbp),%eax
add    -0x5c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    $0x0,%al
call   1050 <getUChar@plt>
mov    %al,%dl
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    123d <ibm3624Offset+0xed>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ibm3624Offset>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%rbx
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,-0x38(%rbp)
xorps  %xmm0,%xmm0
movups %xmm0,0x50(%r9)
movups %xmm0,0x40(%r9)
movups %xmm0,0x30(%r9)
movups %xmm0,0x20(%r9)
movups %xmm0,0x10(%r9)
movups %xmm0,(%r9)
movq   $0x0,0x5d(%r9)
mov    %rsi,%rdi
mov    %r9,%rsi
xor    %eax,%eax
call   1060 <validatePin@plt>
cmp    $0xffffffff,%eax
je     12ad <ibm3624Offset+0x15d>
mov    %r12,-0x60(%rbp)
mov    %r14,-0x58(%rbp)
mov    %rsp,-0x30(%rbp)
lea    0x1(%rax),%edx
mov    %rax,-0x50(%rbp)
mov    %eax,%ecx
mov    %r13,%r14
mov    %rsp,%r13
mov    %rcx,-0x48(%rbp)
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
movslq %edx,%r12
mov    %r13,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
mov    %r15,-0x40(%rbp)
mov    %r15,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    %r12d,%esi
mov    %r14,%rdx
mov    -0x58(%rbp),%rcx
mov    %r13,-0x38(%rbp)
mov    %r13,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1030 <naturalpin@plt>
cmp    $0xffffffff,%eax
je     12b4 <ibm3624Offset+0x164>
cmpl   $0x0,-0x50(%rbp)
mov    $0x0,%eax
mov    -0x30(%rbp),%rcx
jle    12bd <ibm3624Offset+0x16d>
mov    -0x40(%rbp),%r12
xor    %r14d,%r14d
mov    -0x48(%rbp),%r13
mov    -0x38(%rbp),%r15
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%r14,1),%edi
xor    %eax,%eax
call   1070 <getHexValue@plt>
mov    %eax,%ebx
mov    -0x60(%rbp),%rax
movzbl (%rax,%r14,1),%edi
xor    %eax,%eax
call   1070 <getHexValue@plt>
sub    %ebx,%eax
add    $0xa,%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,%r13
jne    1250 <ibm3624Offset+0x100>
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
jmp    12bd <ibm3624Offset+0x16d>
mov    $0xffffffff,%eax
jmp    12c0 <ibm3624Offset+0x170>
mov    $0xffffffff,%eax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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