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

/* Variables and functions */
int /*<<< orphan*/ Base64Decode(char *, char **);
int /*<<< orphan*/ HKDF(char *, char *, int, char **);
int /*<<< orphan*/ PRBG_RSA(char **, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_mac_adress(char **);
int /*<<< orphan*/ hash_function(char *, char **);
int interpretor(char **, int *, int *, char **, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int k_iter;
  int hkdf_iter;
  int borne_start;
  int borne_stop;
  char *to_valid;
  char *key_init;
  char *key;
  char *Ns;
  char *code;
  int space = 6;
  int i;
  if (argc < 2) {
    printf("./%s <your code>", argv[0]);
    return 1;
  }
  to_valid = (char *)malloc(sizeof(char) * 2048);
  key_init = (char *)malloc(sizeof(char) * 65);
  key = (char *)malloc(sizeof(char) * 65);
  Ns = (char *)malloc(sizeof(char) * 2048);
  code = (char *)malloc(sizeof(char) * 2048);
  memset(to_valid, 0, 2048);
  memset(code, 0, 2048);
  memset(key, 0, 65);
  memset(key_init, 0, 65);
  memset(Ns, 0, 2048);
  strcpy(code, argv[1]);
  i = interpretor(&code, &k_iter, &hkdf_iter, &to_valid, space);
  if (i > 0) {
    return 2;
  }
  if (1) {
    memset(code, 0, 2048);
    Base64Decode(to_valid, &code);
  } else {
    strcpy(code, to_valid);
  }
  memset(to_valid, 0, 2048);
  PRBG_RSA(&to_valid, k_iter);
  hash_function(to_valid, &key_init);
  get_mac_adress(&Ns);
  HKDF(key_init, Ns, hkdf_iter, &key);
  printf("Key : %s\nCode: %s\n", key, code);
  if (strcmp(key, code) == 0) {
    printf("Your code is OK !!\\o/\n");
  } else {
    printf("Bad code...\n");
  }
  free(to_valid);
  free(key_init);
  free(key);
  free(Ns);
  free(code);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x6,-0x4c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1208 <main+0x48>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c6 <main+0x206>
mov    $0x800,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x41,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x41,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x800,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x800,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1090 <memset@plt>
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1090 <memset@plt>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1090 <memset@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1090 <memset@plt>
mov    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1090 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x4c(%rbp),%r8d
lea    -0x48(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1070 <interpretor@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jle    12e1 <main+0x121>
movl   $0x2,-0x4(%rbp)
jmp    13c6 <main+0x206>
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1090 <memset@plt>
mov    -0x28(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   10b0 <Base64Decode@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1090 <memset@plt>
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   10d0 <PRBG_RSA@plt>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10e0 <hash_function@plt>
lea    -0x40(%rbp),%rdi
call   1050 <get_mac_adress@plt>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    -0x38(%rbp),%rcx
call   1060 <HKDF@plt>
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%rdx
lea    0xcbe(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1384 <main+0x1c4>
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1392 <main+0x1d2>
lea    0xcb0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     1201 <main+0x31>
mov    (%r14),%rsi
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%eax
jmp    13c5 <main+0x1f5>
mov    $0x800,%edi
call   10d0 <malloc@plt>
mov    %rax,%r13
mov    %rax,0x10(%rsp)
mov    $0x41,%edi
call   10d0 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x28(%rsp)
mov    $0x41,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x18(%rsp)
mov    $0x800,%edi
call   10d0 <malloc@plt>
mov    %rax,%r12
mov    %rax,0x20(%rsp)
mov    $0x800,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   10a0 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   10a0 <memset@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   10a0 <memset@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   10a0 <memset@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   10a0 <memset@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0x8(%rsp),%rdi
lea    0x34(%rsp),%rsi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0x6,%r8d
call   1080 <interpretor@plt>
mov    %eax,%ecx
mov    $0x2,%eax
test   %ecx,%ecx
jg     13c5 <main+0x1f5>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   10a0 <memset@plt>
mov    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10c0 <Base64Decode@plt>
mov    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   10a0 <memset@plt>
mov    0x34(%rsp),%esi
lea    0x10(%rsp),%rdi
call   10e0 <PRBG_RSA@plt>
mov    0x10(%rsp),%rdi
lea    0x28(%rsp),%rsi
call   10f0 <hash_function@plt>
lea    0x20(%rsp),%rdi
call   1050 <get_mac_adress@plt>
mov    0x28(%rsp),%rdi
mov    0x20(%rsp),%rsi
mov    0x30(%rsp),%edx
lea    0x18(%rsp),%rcx
call   1070 <HKDF@plt>
mov    0x18(%rsp),%rsi
mov    0x8(%rsp),%rdx
lea    0xcb0(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x18(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
lea    0xcaf(%rip),%rax
lea    0xc9c(%rip),%rdi
cmove  %rax,%rdi
call   1060 <puts@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"./%s <your code>\00"
@.str.1 = [19 x i8] c"Key : %s\0ACode: %s\0A\00"
@.str.2 = [23 x i8] c"Your code is OK !!\\o/\0A\00"
@.str.3 = [13 x i8] c"Bad code...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 6, i32* %15
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %93
24: ; preds = %2
%25 = call i64 @malloc(i32 2048)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %10
%27 = call i64 @malloc(i32 65)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %11
%29 = call i64 @malloc(i32 65)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %12
%31 = call i64 @malloc(i32 2048)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %13
%33 = call i64 @malloc(i32 2048)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %14
%35 = load i8*, i8** %10
%36 = call i32 @memset(i8* %35, i32 0, i32 2048)
%37 = load i8*, i8** %14
%38 = call i32 @memset(i8* %37, i32 0, i32 2048)
%39 = load i8*, i8** %12
%40 = call i32 @memset(i8* %39, i32 0, i32 65)
%41 = load i8*, i8** %11
%42 = call i32 @memset(i8* %41, i32 0, i32 65)
%43 = load i8*, i8** %13
%44 = call i32 @memset(i8* %43, i32 0, i32 2048)
%45 = load i8*, i8** %14
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 @strcpy(i8* %45, i8* %48)
%50 = load i32, i32* %15
%51 = call i32 @interpretor(i8** %14, i32* %6, i32* %7, i8** %10, i32 %50)
store i32 %51, i32* %16
%52 = load i32, i32* %16
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %24
store i32 2, i32* %3
br label %93
55: ; preds = %24
%56 = load i8*, i8** %14
%57 = call i32 @memset(i8* %56, i32 0, i32 2048)
%58 = load i8*, i8** %10
%59 = call i32 @Base64Decode(i8* %58, i8** %14)
%60 = load i8*, i8** %10
%61 = call i32 @memset(i8* %60, i32 0, i32 2048)
%62 = load i32, i32* %6
%63 = call i32 @PRBG_RSA(i8** %10, i32 %62)
%64 = load i8*, i8** %10
%65 = call i32 @hash_function(i8* %64, i8** %11)
%66 = call i32 @get_mac_adress(i8** %13)
%67 = load i8*, i8** %11
%68 = load i8*, i8** %13
%69 = load i32, i32* %7
%70 = call i32 @HKDF(i8* %67, i8* %68, i32 %69, i8** %12)
%71 = load i8*, i8** %12
%72 = load i8*, i8** %14
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %71, i8* %72)
%74 = load i8*, i8** %12
%75 = load i8*, i8** %14
%76 = call i64 @strcmp(i8* %74, i8* %75)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %55
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %82
80: ; preds = %55
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %82
82: ; preds = %80, %78
%83 = load i8*, i8** %10
%84 = call i32 @free(i8* %83)
%85 = load i8*, i8** %11
%86 = call i32 @free(i8* %85)
%87 = load i8*, i8** %12
%88 = call i32 @free(i8* %87)
%89 = load i8*, i8** %13
%90 = call i32 @free(i8* %89)
%91 = load i8*, i8** %14
%92 = call i32 @free(i8* %91)
store i32 0, i32* %3
br label %93
93: ; preds = %82, %54, %19
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str = [17 x i8] c"./%s <your code>\00"
@.str.1 = [19 x i8] c"Key : %s\0ACode: %s\0A\00"
@str = [12 x i8] c"Bad code...\00"
@str.4 = [22 x i8] c"Your code is OK !!\\o/\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i8** %5 to i8*
%13 = bitcast i8** %6 to i8*
%14 = bitcast i8** %7 to i8*
%15 = bitcast i8** %8 to i8*
%16 = bitcast i8** %9 to i8*
%17 = icmp slt i32 %0, 2
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i8*, i8** %1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %77
21: ; preds = %2
%22 = tail call i64 @malloc(i32 2048)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %5
%24 = tail call i64 @malloc(i32 65)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %6
%26 = tail call i64 @malloc(i32 65)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %7
%28 = tail call i64 @malloc(i32 2048)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %8
%30 = tail call i64 @malloc(i32 2048)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %9
%32 = tail call i32 @memset(i8* %23, i32 0, i32 2048)
%33 = tail call i32 @memset(i8* %31, i32 0, i32 2048)
%34 = tail call i32 @memset(i8* %27, i32 0, i32 65)
%35 = tail call i32 @memset(i8* %25, i32 0, i32 65)
%36 = tail call i32 @memset(i8* %29, i32 0, i32 2048)
%37 = getelementptr inbounds i8*, i8** %1, i64 1
%38 = load i8*, i8** %37
%39 = tail call i32 @strcpy(i8* %31, i8* %38)
%40 = call i32 @interpretor(i8** %9, i32* %3, i32* %4, i8** %5, i32 6)
%41 = icmp sgt i32 %40, 0
br i1 %41, label %77, label %42
42: ; preds = %21
%43 = load i8*, i8** %9
%44 = call i32 @memset(i8* %43, i32 0, i32 2048)
%45 = load i8*, i8** %5
%46 = call i32 @Base64Decode(i8* %45, i8** %9)
%47 = load i8*, i8** %5
%48 = call i32 @memset(i8* %47, i32 0, i32 2048)
%49 = load i32, i32* %3
%50 = call i32 @PRBG_RSA(i8** %5, i32 %49)
%51 = load i8*, i8** %5
%52 = call i32 @hash_function(i8* %51, i8** %6)
%53 = call i32 @get_mac_adress(i8** %8)
%54 = load i8*, i8** %6
%55 = load i8*, i8** %8
%56 = load i32, i32* %4
%57 = call i32 @HKDF(i8* %54, i8* %55, i32 %56, i8** %7)
%58 = load i8*, i8** %7
%59 = load i8*, i8** %9
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %58, i8* %59)
%61 = load i8*, i8** %7
%62 = load i8*, i8** %9
%63 = call i64 @strcmp(i8* %61, i8* %62)
%64 = icmp eq i64 %63, 0
%65 = select i1 %64, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0)
%66 = call i32 @puts(i8* dereferenceable(1) %65)
%67 = load i8*, i8** %5
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %6
%70 = call i32 @free(i8* %69)
%71 = load i8*, i8** %7
%72 = call i32 @free(i8* %71)
%73 = load i8*, i8** %8
%74 = call i32 @free(i8* %73)
%75 = load i8*, i8** %9
%76 = call i32 @free(i8* %75)
br label %77
77: ; preds = %21, %42, %18
%78 = phi i32 [ 1, %18 ], [ 0, %42 ], [ 2, %21 ]
ret i32 %78
}