#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ bin2Base64PlusSlashEqualsOneLine(char *, int, char *);
int /*<<< orphan*/ bin2HexLower(char *, int, char *);
scalar_t__ calloc(size_t, size_t);
int /*<<< orphan*/ fflush;
int /*<<< orphan*/ free(char *);
char hex2Bin(char *, int, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ puts(char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  printf("Usage: %s [string to convert TO hex] [hex string to convert TO "
         "binary and then convert that binary TO Base64]\n",
         argv[0]);
  puts("  The strings do NOT have to be the same.");
  puts("WARNING: This is mainly just a demonstration of public domain skeleton "
       "conversion code - just enough to work in nearly constant time");
  puts("   for constant length output - i.e. password hashing with a fixed "
       "output length and salt size.");
  char *out;
  char *outBase64;
  uint8_t isError;
  if (argc < 3) {
    puts("You must enter at least 2 arguments.");
    return 1;
  }
  out = (uint8_t *)calloc((size_t)strlen(argv[1]) * 2 + 1, (size_t)1);
  bin2HexLower((uint8_t *)argv[1], strlen(argv[1]), (uint8_t *)out);
  printf("binToHex: %s\n", out);
  free(out);
  if (strlen(argv[2]) % 2 != 0) {
    puts("Hex strings MUST have an even number of characters, i.e. 61 or 5a7A");
  }
  out = (uint8_t *)calloc((size_t)strlen(argv[2]) / 2 + 1, (size_t)1);
  isError = hex2Bin((uint8_t *)argv[2], strlen(argv[2]), (uint8_t *)out);
  if (isError) {
    puts("Invalid character found in argument 2, the hex string.  Replaced by "
         "a nibble of 0's.");
  }
  printf("hex2Bin: %s  \nstrlen: %i  expected result: %i\n", out, strlen(out),
         (strlen(out) * 4) / 3 + 0);
  outBase64 =
      (uint8_t *)calloc((size_t)(strlen(out) * 4) / 3 + 4 + 1, (size_t)1);
  bin2Base64PlusSlashEqualsOneLine((uint8_t *)out, strlen(out),
                                   (uint8_t *)outBase64);
  puts("ready");
  fflush;
  printf("hex2Base64RFCPaddedNoCrlf: %s\n\n", outBase64);
  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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xebd(%rip),%rdi
call   1040 <puts@plt>
lea    0xedb(%rip),%rdi
call   1040 <puts@plt>
lea    0xf54(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11f1 <main+0x71>
lea    0xf9e(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a3 <main+0x223>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
movslq %eax,%rdi
shl    $0x1,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1090 <bin2HexLower@plt>
mov    -0x18(%rbp),%rsi
lea    0xf59(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1284 <main+0x104>
lea    0xf32(%rip),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <strlen@plt>
movslq %eax,%rdi
shr    $0x1,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1050 <hex2Bin@plt>
mov    %al,-0x21(%rbp)
cmpb   $0x0,-0x21(%rbp)
je     12eb <main+0x16b>
lea    0xf0f(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x50(%rbp),%rsi
shl    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x44(%rbp),%edx
mov    %eax,%ecx
add    $0x0,%ecx
lea    0xf24(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
shl    $0x2,%eax
cltq
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdi
add    $0x4,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
call   1060 <bin2Base64PlusSlashEqualsOneLine@plt>
lea    0xef4(%rip),%rdi
call   1040 <puts@plt>
mov    -0x20(%rbp),%rsi
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@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   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    (%rsi),%rsi
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0xee9(%rip),%rdi
call   1040 <puts@plt>
lea    0xf62(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebx
jg     11dd <main+0x5d>
lea    0xfb1(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
jmp    1334 <main+0x1b4>
mov    0x8(%r14),%rdi
call   1070 <strlen@plt>
cltq
lea    (%rax,%rax,1),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
mov    0x8(%r14),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1090 <bin2HexLower@plt>
lea    0xf86(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x10(%r14),%rdi
call   1070 <strlen@plt>
test   $0x1,%al
je     1248 <main+0xc8>
lea    0xf6e(%rip),%rdi
call   1040 <puts@plt>
mov    0x10(%r14),%rdi
call   1070 <strlen@plt>
movslq %eax,%rdi
shr    %rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1050 <hex2Bin@plt>
test   %al,%al
je     1291 <main+0x111>
lea    0xf69(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1070 <strlen@plt>
shl    $0x2,%eax
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
shr    $0x20,%rcx
add    %eax,%ecx
lea    0xf86(%rip),%rdi
xor    %r15d,%r15d
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
shl    $0x2,%eax
cltq
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mul    %rcx
shr    %rdx
lea    0x5(%rdx),%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %rbp,%rdx
call   1060 <bin2Base64PlusSlashEqualsOneLine@plt>
lea    0xf5b(%rip),%rdi
call   1040 <puts@plt>
lea    0xf55(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [111 x i8] c"Usage: %s [string to convert TO hex] [hex string to convert TO binary and then convert that binary TO Base64]\0A\00"
@.str.1 = [42 x i8] c" The strings do NOT have to be the same.\00"
@.str.2 = [133 x i8] c"WARNING: This is mainly just a demonstration of public domain skeleton conversion code - just enough to work in nearly constant time\00"
@.str.3 = [96 x i8] c" for constant length output - i.e. password hashing with a fixed output length and salt size.\00"
@.str.4 = [37 x i8] c"You must enter at least 2 arguments.\00"
@.str.5 = [14 x i8] c"binToHex: %s\0A\00"
@.str.6 = [68 x i8] c"Hex strings MUST have an even number of characters, i.e. 61 or 5a7A\00"
@.str.7 = [85 x i8] c"Invalid character found in argument 2, the hex string. Replaced by a nibble of 0's.\00"
@.str.8 = [47 x i8] c"hex2Bin: %s \0Astrlen: %i expected result: %i\0A\00"
@.str.9 = [6 x i8] c"ready\00"
@fflush = global i32 0
@.str.10 = [32 x i8] c"hex2Base64RFCPaddedNoCrlf: %s\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @puts(i8* getelementptr inbounds ([133 x i8], [133 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @puts(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %102
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 2
%27 = add i64 %26, 1
%28 = call i64 @calloc(i64 %27, i64 1)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strlen(i8* %35)
%37 = load i8*, i8** %6
%38 = call i32 @bin2HexLower(i8* %32, i32 %36, i8* %37)
%39 = load i8*, i8** %6
%40 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %6
%42 = call i32 @free(i8* %41)
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @strlen(i8* %45)
%47 = srem i32 %46, 2
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %20
%50 = call i32 @puts(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %49, %20
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @strlen(i8* %54)
%56 = sext i32 %55 to i64
%57 = udiv i64 %56, 2
%58 = add i64 %57, 1
%59 = call i64 @calloc(i64 %58, i64 1)
%60 = inttoptr i64 %59 to i8*
store i8* %60, i8** %6
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = call i32 @strlen(i8* %66)
%68 = load i8*, i8** %6
%69 = call signext i8 @hex2Bin(i8* %63, i32 %67, i8* %68)
store i8 %69, i8* %8
%70 = load i8, i8* %8
%71 = icmp ne i8 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %51
%73 = call i32 @puts(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.7, i64 0, i64 0))
br label %74
74: ; preds = %72, %51
%75 = load i8*, i8** %6
%76 = load i8*, i8** %6
%77 = call i32 @strlen(i8* %76)
%78 = load i8*, i8** %6
%79 = call i32 @strlen(i8* %78)
%80 = mul nsw i32 %79, 4
%81 = sdiv i32 %80, 3
%82 = add nsw i32 %81, 0
%83 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i8* %75, i32 %77, i32 %82)
%84 = load i8*, i8** %6
%85 = call i32 @strlen(i8* %84)
%86 = mul nsw i32 %85, 4
%87 = sext i32 %86 to i64
%88 = udiv i64 %87, 3
%89 = add i64 %88, 4
%90 = add i64 %89, 1
%91 = call i64 @calloc(i64 %90, i64 1)
%92 = inttoptr i64 %91 to i8*
store i8* %92, i8** %7
%93 = load i8*, i8** %6
%94 = load i8*, i8** %6
%95 = call i32 @strlen(i8* %94)
%96 = load i8*, i8** %7
%97 = call i32 @bin2Base64PlusSlashEqualsOneLine(i8* %93, i32 %95, i8* %96)
%98 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%99 = load i32, i32* @fflush
%100 = load i8*, i8** %7
%101 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %100)
store i32 0, i32* %3
br label %102
102: ; preds = %74, %18
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@.str = [111 x i8] c"Usage: %s [string to convert TO hex] [hex string to convert TO binary and then convert that binary TO Base64]\0A\00"
@.str.1 = [42 x i8] c" The strings do NOT have to be the same.\00"
@.str.2 = [133 x i8] c"WARNING: This is mainly just a demonstration of public domain skeleton conversion code - just enough to work in nearly constant time\00"
@.str.3 = [96 x i8] c" for constant length output - i.e. password hashing with a fixed output length and salt size.\00"
@.str.4 = [37 x i8] c"You must enter at least 2 arguments.\00"
@.str.5 = [14 x i8] c"binToHex: %s\0A\00"
@.str.6 = [68 x i8] c"Hex strings MUST have an even number of characters, i.e. 61 or 5a7A\00"
@.str.7 = [85 x i8] c"Invalid character found in argument 2, the hex string. Replaced by a nibble of 0's.\00"
@.str.8 = [47 x i8] c"hex2Bin: %s \0Astrlen: %i expected result: %i\0A\00"
@.str.9 = [6 x i8] c"ready\00"
@fflush = global i32 0
@.str.10 = [32 x i8] c"hex2Base64RFCPaddedNoCrlf: %s\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([111 x i8], [111 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([133 x i8], [133 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp slt i32 %0, 3
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %63
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = shl nsw i64 %15, 1
%17 = or i64 %16, 1
%18 = tail call i64 @calloc(i64 %17, i64 1)
%19 = inttoptr i64 %18 to i8*
%20 = load i8*, i8** %12
%21 = tail call i32 @strlen(i8* %20)
%22 = tail call i32 @bin2HexLower(i8* %20, i32 %21, i8* %19)
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %19)
%24 = tail call i32 @free(i8* %19)
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32 @strlen(i8* %26)
%28 = and i32 %27, 1
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %11
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.6, i64 0, i64 0))
br label %32
32: ; preds = %30, %11
%33 = load i8*, i8** %25
%34 = tail call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = lshr i64 %35, 1
%37 = add nuw i64 %36, 1
%38 = tail call i64 @calloc(i64 %37, i64 1)
%39 = inttoptr i64 %38 to i8*
%40 = load i8*, i8** %25
%41 = tail call i32 @strlen(i8* %40)
%42 = tail call signext i8 @hex2Bin(i8* %40, i32 %41, i8* %39)
%43 = icmp eq i8 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %32
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.7, i64 0, i64 0))
br label %46
46: ; preds = %44, %32
%47 = tail call i32 @strlen(i8* %39)
%48 = tail call i32 @strlen(i8* %39)
%49 = shl nsw i32 %48, 2
%50 = sdiv i32 %49, 3
%51 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.8, i64 0, i64 0), i8* %39, i32 %47, i32 %50)
%52 = tail call i32 @strlen(i8* %39)
%53 = shl nsw i32 %52, 2
%54 = sext i32 %53 to i64
%55 = udiv i64 %54, 3
%56 = add nuw nsw i64 %55, 5
%57 = tail call i64 @calloc(i64 %56, i64 1)
%58 = inttoptr i64 %57 to i8*
%59 = tail call i32 @strlen(i8* %39)
%60 = tail call i32 @bin2Base64PlusSlashEqualsOneLine(i8* %39, i32 %59, i8* %58)
%61 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%62 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i8* %58)
br label %63
63: ; preds = %46, %9
%64 = phi i32 [ 1, %9 ], [ 0, %46 ]
ret i32 %64
}