#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*/ pin;
typedef int /*<<< orphan*/ natPin;

/* Variables and functions */
int /*<<< orphan*/ memset(unsigned char *, char, int);
int naturalpin(unsigned char *, int, unsigned char *, unsigned char *,
               unsigned char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char const *, char const *);
int main(int argc, char *argv[]) {
  unsigned char pvk[] = "815F814E8AAC998E7DD12ADDA0FAF179";
  unsigned char dectable[] = "0123456789012345";
  unsigned char pin[] = "108800";
  char errstatus[100 + 1];
  int k = 0;
  unsigned char pinvaldat[] = "1850002769676960";
  unsigned char natPin[sizeof(pin)];
  unsigned char result[] = "180216";
  memset(natPin, '\0', sizeof(natPin));
  k = naturalpin(pvk, sizeof(natPin), dectable, pinvaldat, natPin, errstatus);
  if (k == 0) {
    if (strcmp((const char *)natPin, (const char *)result) == 0) {
      printf("main.naturalpin.1 OK %s %s \n", natPin, result);
    } else {
      printf("main.naturalpin.1 KO %s %s \n", natPin, result);
    }
  } else {
    printf("main.naturalpin.1 KO %2d %s \n", k, errstatus);
  }
  int length = sizeof(pin) + 1;
  unsigned char natPin2[length];
  k = naturalpin(pvk, length, dectable, pinvaldat, natPin2, errstatus);
  if (k == 0) {
    printf("main.naturalpin.2 KO length %2d %s %s \n", length, natPin2, result);
  } else {
    printf("main.naturalpin.2 OK length %2d %s \n", length, errstatus);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x21,%edx
call   1070 <memcpy@plt>
mov    0xeab(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xea8(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xea6(%rip),%al
mov    %al,-0x50(%rbp)
mov    0xebe(%rip),%eax
mov    %eax,-0x67(%rbp)
mov    0xeb8(%rip),%ax
mov    %ax,-0x63(%rbp)
mov    0xeb0(%rip),%al
mov    %al,-0x61(%rbp)
movl   $0x0,-0xd4(%rbp)
mov    0xe85(%rip),%rax
mov    %rax,-0xf0(%rbp)
mov    0xe7f(%rip),%rax
mov    %rax,-0xe8(%rbp)
mov    0xe7a(%rip),%al
mov    %al,-0xe0(%rbp)
mov    0xe76(%rip),%eax
mov    %eax,-0xfe(%rbp)
mov    0xe6d(%rip),%ax
mov    %ax,-0xfa(%rbp)
mov    0xe62(%rip),%al
mov    %al,-0xf8(%rbp)
lea    -0xf7(%rbp),%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0xf0(%rbp),%rcx
lea    -0xf7(%rbp),%r8
lea    -0xd0(%rbp),%r9
mov    $0x7,%esi
call   1030 <naturalpin@plt>
mov    %eax,-0xd4(%rbp)
cmpl   $0x0,-0xd4(%rbp)
jne    12be <main+0x16e>
lea    -0xf7(%rbp),%rdi
lea    -0xfe(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    129d <main+0x14d>
lea    -0xf7(%rbp),%rsi
lea    -0xfe(%rbp),%rdx
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b9 <main+0x169>
lea    -0xf7(%rbp),%rsi
lea    -0xfe(%rbp),%rdx
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d9 <main+0x189>
mov    -0xd4(%rbp),%esi
lea    -0xd0(%rbp),%rdx
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x8,-0x104(%rbp)
mov    -0x104(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x110(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r8
sub    %rcx,%r8
mov    %r8,-0x120(%rbp)
mov    %r8,%rsp
mov    %rax,-0x118(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x104(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    -0xf0(%rbp),%rcx
lea    -0xd0(%rbp),%r9
call   1030 <naturalpin@plt>
mov    %eax,-0xd4(%rbp)
cmpl   $0x0,-0xd4(%rbp)
jne    1370 <main+0x220>
mov    -0x120(%rbp),%rdx
mov    -0x104(%rbp),%esi
lea    -0xfe(%rbp),%rcx
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    138b <main+0x23b>
mov    -0x104(%rbp),%esi
lea    -0xd0(%rbp),%rdx
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x110(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0xe0,%rsp
movaps 0xebb(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
movaps 0xea0(%rip),%xmm0
movaps %xmm0,-0x80(%rbp)
movb   $0x0,-0x60(%rbp)
movaps 0xec1(%rip),%xmm0
movaps %xmm0,-0x50(%rbp)
movb   $0x0,-0x40(%rbp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
movb   $0x0,-0x20(%rbp)
movl   $0x363132,-0x15(%rbp)
movl   $0x32303831,-0x18(%rbp)
lea    -0x1f(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1050 <memset@plt>
lea    -0x80(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0xf0(%rbp),%r9
mov    $0x7,%esi
mov    %rbx,%r8
call   1030 <naturalpin@plt>
test   %eax,%eax
je     11e4 <main+0xa4>
lea    0xed0(%rip),%rdi
lea    -0xf0(%rbp),%rdx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1215 <main+0xd5>
lea    -0x1f(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ff <main+0xbf>
lea    0xe88(%rip),%rdi
jmp    1206 <main+0xc6>
lea    0xe62(%rip),%rdi
lea    -0x1f(%rbp),%rsi
lea    -0x18(%rbp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r14
mov    %rsp,%rbx
add    $0xfffffffffffffff0,%rbx
mov    %rbx,%rsp
lea    -0x80(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0xf0(%rbp),%r9
mov    $0x8,%esi
mov    %rbx,%r8
call   1030 <naturalpin@plt>
test   %eax,%eax
je     1262 <main+0x122>
lea    0xe9b(%rip),%rdi
lea    -0xf0(%rbp),%rdx
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    127c <main+0x13c>
lea    0xe57(%rip),%rdi
lea    -0x18(%rbp),%rcx
mov    $0x8,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rsp
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.pvk = [33 x i8] c"815F814E8AAC998E7DD12ADDA0FAF179\00"
@__const.main.dectable = [17 x i8] c"0123456789012345\00"
@__const.main.pin = [7 x i8] c"108800\00"
@__const.main.pinvaldat = [17 x i8] c"1850002769676960\00"
@__const.main.result = [7 x i8] c"180216\00"
@.str = [29 x i8] c"main.naturalpin.1 OK %s %s \0A\00"
@.str.1 = [29 x i8] c"main.naturalpin.1 KO %s %s \0A\00"
@.str.2 = [30 x i8] c"main.naturalpin.1 KO %2d %s \0A\00"
@.str.3 = [40 x i8] c"main.naturalpin.2 KO length %2d %s %s \0A\00"
@.str.4 = [37 x i8] c"main.naturalpin.2 OK length %2d %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [33 x i8]
%7 = alloca [17 x i8]
%8 = alloca [7 x i8]
%9 = alloca [101 x i8]
%10 = alloca i32
%11 = alloca [17 x i8]
%12 = alloca [7 x i8]
%13 = alloca [7 x i8]
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = bitcast [33 x i8]* %6 to i8*
%18 = bitcast [17 x i8]* %7 to i8*
%19 = bitcast [7 x i8]* %8 to i8*
store i32 0, i32* %10
%20 = bitcast [17 x i8]* %11 to i8*
%21 = bitcast [7 x i8]* %13 to i8*
%22 = getelementptr inbounds [7 x i8], [7 x i8]* %12, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i8 signext 0, i32 7)
%24 = getelementptr inbounds [33 x i8], [33 x i8]* %6, i64 0, i64 0
%25 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
%27 = getelementptr inbounds [7 x i8], [7 x i8]* %12, i64 0, i64 0
%28 = getelementptr inbounds [101 x i8], [101 x i8]* %9, i64 0, i64 0
%29 = call i32 @naturalpin(i8* %24, i32 7, i8* %25, i8* %26, i8* %27, i8* %28)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %46
32: ; preds = %2
%33 = getelementptr inbounds [7 x i8], [7 x i8]* %12, i64 0, i64 0
%34 = getelementptr inbounds [7 x i8], [7 x i8]* %13, i64 0, i64 0
%35 = call i64 @strcmp(i8* %33, i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = getelementptr inbounds [7 x i8], [7 x i8]* %12, i64 0, i64 0
%39 = getelementptr inbounds [7 x i8], [7 x i8]* %13, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %38, i8* %39)
br label %45
41: ; preds = %32
%42 = getelementptr inbounds [7 x i8], [7 x i8]* %12, i64 0, i64 0
%43 = getelementptr inbounds [7 x i8], [7 x i8]* %13, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43)
br label %45
45: ; preds = %41, %37
br label %50
46: ; preds = %2
%47 = load i32, i32* %10
%48 = getelementptr inbounds [101 x i8], [101 x i8]* %9, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %47, i8* %48)
br label %50
50: ; preds = %46, %45
store i32 8, i32* %14
%51 = load i32, i32* %14
%52 = zext i32 %51 to i64
%53 = call i8* @llvm.stacksave()
store i8* %53, i8** %15
%54 = alloca i8, i64 %52
store i64 %52, i64* %16
%55 = getelementptr inbounds [33 x i8], [33 x i8]* %6, i64 0, i64 0
%56 = load i32, i32* %14
%57 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%58 = getelementptr inbounds [17 x i8], [17 x i8]* %11, i64 0, i64 0
%59 = getelementptr inbounds [101 x i8], [101 x i8]* %9, i64 0, i64 0
%60 = call i32 @naturalpin(i8* %55, i32 %56, i8* %57, i8* %58, i8* %54, i8* %59)
store i32 %60, i32* %10
%61 = load i32, i32* %10
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %50
%64 = load i32, i32* %14
%65 = getelementptr inbounds [7 x i8], [7 x i8]* %13, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %64, i8* %54, i8* %65)
br label %71
67: ; preds = %50
%68 = load i32, i32* %14
%69 = getelementptr inbounds [101 x i8], [101 x i8]* %9, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %68, i8* %69)
br label %71
71: ; preds = %67, %63
store i32 0, i32* %3
%72 = load i8*, i8** %15
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@__const.main.pvk = [33 x i8] c"815F814E8AAC998E7DD12ADDA0FAF179\00"
@__const.main.dectable = [17 x i8] c"0123456789012345\00"
@__const.main.pinvaldat = [17 x i8] c"1850002769676960\00"
@__const.main.result = [7 x i8] c"180216\00"
@.str = [29 x i8] c"main.naturalpin.1 OK %s %s \0A\00"
@.str.1 = [29 x i8] c"main.naturalpin.1 KO %s %s \0A\00"
@.str.2 = [30 x i8] c"main.naturalpin.1 KO %2d %s \0A\00"
@.str.3 = [40 x i8] c"main.naturalpin.2 KO length %2d %s %s \0A\00"
@.str.4 = [37 x i8] c"main.naturalpin.2 OK length %2d %s \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [33 x i8]
%4 = alloca [17 x i8]
%5 = alloca [101 x i8]
%6 = alloca [17 x i8]
%7 = alloca [7 x i8]
%8 = alloca [7 x i8]
%9 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 0
%15 = call i32 @memset(i8* %13, i8 signext 0, i32 7)
%16 = call i32 @naturalpin(i8* %9, i32 7, i8* %10, i8* %12, i8* %13, i8* %11)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = call i64 @strcmp(i8* %13, i8* %14)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14)
br label %27
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %13, i8* %14)
br label %27
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %16, i8* %11)
br label %27
27: ; preds = %21, %23, %25
%28 = call i8* @llvm.stacksave()
%29 = alloca [8 x i8]
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %29, i64 0, i64 0
%31 = call i32 @naturalpin(i8* %9, i32 8, i8* %10, i8* %12, i8* %30, i8* %11)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 8, i8* %30, i8* %14)
br label %37
35: ; preds = %27
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 8, i8* %11)
br label %37
37: ; preds = %35, %33
ret i32 0
}