int pinValidationData(unsigned const char *ipan, const int iposition,
                      unsigned char *opinvaldat, char *errstatus) {
  memset(opinvaldat, '\0', 8 * 2 + 1);
  memset(errstatus, '\0', 100 + 1);
  unsigned char accountnumber[13];
  memset(accountnumber, '\0', 13);
  unsigned char last5digits[6];
  memset(last5digits, '\0', 6);
  int panlength = validatePan(ipan, errstatus);
  if (panlength == -1)
    return -1;
  if (iposition - 1 < 0 || iposition - 1 > 11) {
    strcpy(errstatus, "Invalid position to insert last 5 digits of account "
                      "number - must be between 1 to 12 !!");
    return -1;
  }
  strncpy((char *)accountnumber, (const char *)(ipan + panlength - 12 - 1), 12);
  accountnumber[12] = '\0';
  strncpy((char *)last5digits, (const char *)(ipan + panlength - 5 - 1), 5);
  last5digits[5] = '\0';
  strncpy((char *)opinvaldat, (const char *)accountnumber, iposition - 1);
  strcat((char *)opinvaldat, (const char *)last5digits);
  strncat((char *)opinvaldat, (const char *)(accountnumber + iposition),
          12 - iposition);
  opinvaldat[8 * 2 + 1] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<pinValidationData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x65,%edx
call   1050 <memset@plt>
lea    -0x35(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1050 <memset@plt>
lea    -0x3b(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1070 <validatePan@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
jne    11df <pinValidationData+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b4 <pinValidationData+0x154>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
jl     11fd <pinValidationData+0x9d>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cmp    $0xb,%eax
jle    1219 <pinValidationData+0xb9>
mov    -0x28(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b4 <pinValidationData+0x154>
lea    -0x35(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x40(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffff4,%rsi
add    $0xffffffffffffffff,%rsi
mov    $0xc,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x29(%rbp)
lea    -0x3b(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x40(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffb,%rsi
add    $0xffffffffffffffff,%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x36(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x35(%rbp),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
lea    -0x3b(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    -0x35(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0xc,%eax
sub    -0x14(%rbp),%eax
movslq %eax,%rdx
call   1060 <strncat@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0x11(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pinValidationData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%r12
xorps  %xmm0,%xmm0
movups %xmm0,(%rdx)
movb   $0x0,0x10(%rdx)
movups %xmm0,0x50(%rcx)
movups %xmm0,0x40(%rcx)
movups %xmm0,0x30(%rcx)
movups %xmm0,0x20(%rcx)
movups %xmm0,0x10(%rcx)
movups %xmm0,(%rcx)
movq   $0x0,0x5d(%rcx)
mov    %rcx,%rsi
xor    %eax,%eax
call   1050 <validatePan@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xffffffff,%ecx
je     126f <pinValidationData+0x12f>
lea    -0xd(%r14),%edx
cmp    $0xfffffff3,%edx
ja     11ef <pinValidationData+0xaf>
movups 0xe93(%rip),%xmm0
movups %xmm0,0x40(%rbx)
movups 0xe78(%rip),%xmm0
movups %xmm0,0x30(%rbx)
movups 0xe5d(%rip),%xmm0
movups %xmm0,0x20(%rbx)
movups 0xe42(%rip),%xmm0
movups %xmm0,0x10(%rbx)
movups 0xe27(%rip),%xmm0
movups %xmm0,(%rbx)
movabs $0x2121203231206f,%rcx
mov    %rcx,0x50(%rbx)
jmp    126f <pinValidationData+0x12f>
lea    -0x1(%r14),%ebx
movslq %ecx,%rbp
lea    (%r12,%rbp,1),%rsi
add    $0xfffffffffffffff3,%rsi
lea    0xb(%rsp),%r13
mov    $0xc,%edx
mov    %r13,%rdi
call   1030 <strncpy@plt>
movb   $0x0,0x17(%rsp)
lea    (%r12,%rbp,1),%rsi
add    $0xfffffffffffffffa,%rsi
lea    0x5(%rsp),%r12
mov    $0x5,%edx
mov    %r12,%rdi
call   1030 <strncpy@plt>
movb   $0x0,0xa(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
mov    %r14d,%eax
lea    (%rsp,%rax,1),%rsi
add    $0xb,%rsi
mov    $0xc,%edx
sub    %r14d,%edx
mov    %r15,%rdi
call   1040 <strncat@plt>
movb   $0x0,0x11(%r15)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [88 x i8] c"Invalid position to insert last 5 digits of account number - must be between 1 to 12 !!\00"
define i32 @pinValidationData(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [13 x i8]
%11 = alloca [6 x i8]
%12 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = load i8*, i8** %8
%14 = load i8*, i8** %9
%15 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = load i8*, i8** %9
%19 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @validatePan to i32 (i8*, i8*, ...)*)(i8* %17, i8* %18)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %4
store i32 -1, i32* %5
br label %73
23: ; preds = %4
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 1
%26 = icmp slt i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 1
%30 = icmp sgt i32 %29, 11
br i1 %30, label %31, label %34
31: ; preds = %27, %23
%32 = load i8*, i8** %9
%33 = call i8* @strcpy(i8* %32, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %73
34: ; preds = %27
%35 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
%36 = load i8*, i8** %6
%37 = load i32, i32* %12
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = getelementptr inbounds i8, i8* %39, i64 -12
%41 = getelementptr inbounds i8, i8* %40, i64 -1
%42 = call i8* @strncpy(i8* %35, i8* %41, i64 12)
%43 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 12
store i8 0, i8* %43
%44 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%45 = load i8*, i8** %6
%46 = load i32, i32* %12
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = getelementptr inbounds i8, i8* %48, i64 -5
%50 = getelementptr inbounds i8, i8* %49, i64 -1
%51 = call i8* @strncpy(i8* %44, i8* %50, i64 5)
%52 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 5
store i8 0, i8* %52
%53 = load i8*, i8** %8
%54 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
%55 = load i32, i32* %7
%56 = sub nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = call i8* @strncpy(i8* %53, i8* %54, i64 %57)
%59 = load i8*, i8** %8
%60 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%61 = call i8* @strcat(i8* %59, i8* %60)
%62 = load i8*, i8** %8
%63 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i32, i32* %7
%68 = sub nsw i32 12, %67
%69 = sext i32 %68 to i64
%70 = call i8* @strncat(i8* %62, i8* %66, i64 %69)
%71 = load i8*, i8** %8
%72 = getelementptr inbounds i8, i8* %71, i64 17
store i8 0, i8* %72
store i32 0, i32* %5
br label %73
73: ; preds = %34, %31, %22
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
@.str = [88 x i8] c"Invalid position to insert last 5 digits of account number - must be between 1 to 12 !!\00"
define i32 @pinValidationData(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [13 x i8]
%6 = alloca [6 x i8]
tail call void @llvm.memset.p0i8.i64(i8* align 1 dereferenceable(17) %2, i8 0, i64 17, i1 false)
tail call void @llvm.memset.p0i8.i64(i8* align 1 dereferenceable(101) %3, i8 0, i64 101, i1 false)
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%9 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @validatePan to i32 (i8*, i8*, ...)*)(i8* %0, i8* %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %36, label %11
11: ; preds = %4
%12 = add i32 %1, -13
%13 = icmp ult i32 %12, -12
br i1 %13, label %14, label %15
14: ; preds = %11
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(88) %3, i8* align 1 dereferenceable(88) getelementptr inbounds ([88 x i8], [88 x i8]* @.str, i64 0, i64 0), i64 88, i1 false)
br label %36
15: ; preds = %11
%16 = add nsw i32 %1, -1
%17 = sext i32 %9 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 -12
%20 = getelementptr inbounds i8, i8* %19, i64 -1
%21 = call i8* @strncpy(i8* %7, i8* %20, i64 12)
%22 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 12
store i8 0, i8* %22
%23 = getelementptr inbounds i8, i8* %18, i64 -5
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = call i8* @strncpy(i8* %8, i8* %24, i64 5)
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 5
store i8 0, i8* %26
%27 = zext i32 %16 to i64
%28 = call i8* @strncpy(i8* dereferenceable(1) %2, i8* %7, i64 %27)
%29 = call i8* @strcat(i8* dereferenceable(1) %2, i8* %8)
%30 = zext i32 %1 to i64
%31 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %30
%32 = sub nuw nsw i32 12, %1
%33 = zext i32 %32 to i64
%34 = call i8* @strncat(i8* dereferenceable(1) %2, i8* %31, i64 %33)
%35 = getelementptr inbounds i8, i8* %2, i64 17
store i8 0, i8* %35
br label %36
36: ; preds = %4, %15, %14
%37 = phi i32 [ -1, %14 ], [ 0, %15 ], [ -1, %4 ]
ret i32 %37
}