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

/* Variables and functions */
int /*<<< orphan*/ bin2Base64PlusSlashEquals(scalar_t__ *, int, scalar_t__ *);
int /*<<< orphan*/ bin2HexLower(scalar_t__ *, int, scalar_t__ *);
int /*<<< orphan*/ bin2HexUpper(scalar_t__ *, int, scalar_t__ *);
scalar_t__ calloc(size_t, size_t);
int /*<<< orphan*/ free(char *);
scalar_t__ hex2Bin(scalar_t__ *, int, scalar_t__ *);
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 = (char *)calloc((size_t)strlen(argv[1]) * 2 + 1, (size_t)1);
  bin2HexLower((uint8_t *)argv[1], strlen(argv[1]), (uint8_t *)out);
  printf("binToHex hex output lowercase: \n%s\n", out);
  bin2HexUpper((uint8_t *)argv[1], strlen(argv[1]), (uint8_t *)out);
  printf("binToHex hex output uppercase: \n%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 = (char *)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 binary output: \n%s\n", out);
  outBase64 = (char *)calloc((size_t)(strlen(out) * 4) / 3 + 4 + 1, (size_t)1);
  bin2Base64PlusSlashEquals((uint8_t *)out, strlen(out), (uint8_t *)outBase64);
  printf("hex2Base64RFCPaddedNoCrlf Base64 output: \n%s\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    0xe4c(%rip),%rdi
call   1080 <printf@plt>
lea    0xeaf(%rip),%rdi
call   1050 <puts@plt>
lea    0xecd(%rip),%rdi
call   1050 <puts@plt>
lea    0xf46(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11ff <main+0x6f>
lea    0xf90(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a9 <main+0x219>
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   10b0 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   10a0 <bin2HexLower@plt>
mov    -0x18(%rbp),%rsi
lea    0xf4b(%rip),%rdi
call   1080 <printf@plt>
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 <bin2HexUpper@plt>
mov    -0x18(%rbp),%rsi
lea    0xf37(%rip),%rdi
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     12c8 <main+0x138>
lea    0xf28(%rip),%rdi
call   1050 <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   10b0 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1060 <hex2Bin@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1331 <main+0x1a1>
lea    0xf03(%rip),%rdi
call   1050 <puts@plt>
mov    -0x18(%rbp),%rsi
lea    0xf48(%rip),%rdi
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   10b0 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
call   1040 <bin2Base64PlusSlashEquals@plt>
mov    -0x20(%rbp),%rsi
lea    0xf03(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    (%rsi),%rsi
lea    0xe5c(%rip),%rdi
call   1080 <printf@plt>
lea    0xebf(%rip),%rdi
call   1050 <puts@plt>
lea    0xedd(%rip),%rdi
call   1050 <puts@plt>
lea    0xf56(%rip),%rdi
call   1050 <puts@plt>
cmp    $0x2,%ebx
jg     11e8 <main+0x58>
lea    0xfa5(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    1326 <main+0x196>
mov    0x8(%r14),%rdi
call   1070 <strlen@plt>
cltq
lea    (%rax,%rax,1),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    %rax,%rbx
mov    0x8(%r14),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   10a0 <bin2HexLower@plt>
lea    0xf7b(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    0x8(%r14),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1090 <bin2HexUpper@plt>
lea    0xf77(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x10(%r14),%rdi
call   1070 <strlen@plt>
test   $0x1,%al
je     1279 <main+0xe9>
lea    0xf77(%rip),%rdi
call   1050 <puts@plt>
mov    0x10(%r14),%rdi
call   1070 <strlen@plt>
movslq %eax,%rdi
shr    %rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    %rax,%r15
mov    0x10(%r14),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
call   1060 <hex2Bin@plt>
test   %rax,%rax
je     12c3 <main+0x133>
lea    0xf71(%rip),%rdi
call   1050 <puts@plt>
lea    0xfba(%rip),%rdi
mov    %r15,%rsi
call   1080 <printf@plt>
mov    %r15,%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   10b0 <calloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1040 <bin2Base64PlusSlashEquals@plt>
lea    0xf84(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
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 = [36 x i8] c"binToHex hex output lowercase: \0A%s\0A\00"
@.str.6 = [36 x i8] c"binToHex hex output uppercase: \0A%s\0A\00"
@.str.7 = [68 x i8] c"Hex strings MUST have an even number of characters, i.e. 61 or 5a7A\00"
@.str.8 = [85 x i8] c"Invalid character found in argument 2, the hex string. Replaced by a nibble of 0's.\00"
@.str.9 = [28 x i8] c"hex2Bin binary output: \0A%s\0A\00"
@.str.10 = [46 x i8] c"hex2Base64RFCPaddedNoCrlf Base64 output: \0A%s\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 i64
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 @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 %112
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 = bitcast i8* %32 to i64*
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strlen(i8* %36)
%38 = load i8*, i8** %6
%39 = bitcast i8* %38 to i64*
%40 = call i32 @bin2HexLower(i64* %33, i32 %37, i64* %39)
%41 = load i8*, i8** %6
%42 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = bitcast i8* %45 to i64*
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @strlen(i8* %49)
%51 = load i8*, i8** %6
%52 = bitcast i8* %51 to i64*
%53 = call i32 @bin2HexUpper(i64* %46, i32 %50, i64* %52)
%54 = load i8*, i8** %6
%55 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %54)
%56 = load i8*, i8** %6
%57 = call i32 @free(i8* %56)
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = call i32 @strlen(i8* %60)
%62 = srem i32 %61, 2
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %20
%65 = call i32 @puts(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.7, i64 0, i64 0))
br label %66
66: ; preds = %64, %20
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = call i32 @strlen(i8* %69)
%71 = sext i32 %70 to i64
%72 = udiv i64 %71, 2
%73 = add i64 %72, 1
%74 = call i64 @calloc(i64 %73, i64 1)
%75 = inttoptr i64 %74 to i8*
store i8* %75, i8** %6
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 2
%78 = load i8*, i8** %77
%79 = bitcast i8* %78 to i64*
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 2
%82 = load i8*, i8** %81
%83 = call i32 @strlen(i8* %82)
%84 = load i8*, i8** %6
%85 = bitcast i8* %84 to i64*
%86 = call i64 @hex2Bin(i64* %79, i32 %83, i64* %85)
store i64 %86, i64* %8
%87 = load i64, i64* %8
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %66
%90 = call i32 @puts(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.8, i64 0, i64 0))
br label %91
91: ; preds = %89, %66
%92 = load i8*, i8** %6
%93 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i8* %92)
%94 = load i8*, i8** %6
%95 = call i32 @strlen(i8* %94)
%96 = mul nsw i32 %95, 4
%97 = sext i32 %96 to i64
%98 = udiv i64 %97, 3
%99 = add i64 %98, 4
%100 = add i64 %99, 1
%101 = call i64 @calloc(i64 %100, i64 1)
%102 = inttoptr i64 %101 to i8*
store i8* %102, i8** %7
%103 = load i8*, i8** %6
%104 = bitcast i8* %103 to i64*
%105 = load i8*, i8** %6
%106 = call i32 @strlen(i8* %105)
%107 = load i8*, i8** %7
%108 = bitcast i8* %107 to i64*
%109 = call i32 @bin2Base64PlusSlashEquals(i64* %104, i32 %106, i64* %108)
%110 = load i8*, i8** %7
%111 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i8* %110)
store i32 0, i32* %3
br label %112
112: ; preds = %91, %18
%113 = load i32, i32* %3
ret i32 %113
}

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 = [36 x i8] c"binToHex hex output lowercase: \0A%s\0A\00"
@.str.6 = [36 x i8] c"binToHex hex output uppercase: \0A%s\0A\00"
@.str.7 = [68 x i8] c"Hex strings MUST have an even number of characters, i.e. 61 or 5a7A\00"
@.str.8 = [85 x i8] c"Invalid character found in argument 2, the hex string. Replaced by a nibble of 0's.\00"
@.str.9 = [28 x i8] c"hex2Bin binary output: \0A%s\0A\00"
@.str.10 = [46 x i8] c"hex2Base64RFCPaddedNoCrlf Base64 output: \0A%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @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 %68
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 = bitcast i8* %20 to i64*
%22 = tail call i32 @strlen(i8* %20)
%23 = inttoptr i64 %18 to i64*
%24 = tail call i32 @bin2HexLower(i64* %21, i32 %22, i64* %23)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %19)
%26 = load i8*, i8** %12
%27 = bitcast i8* %26 to i64*
%28 = tail call i32 @strlen(i8* %26)
%29 = tail call i32 @bin2HexUpper(i64* %27, i32 %28, i64* %23)
%30 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%31 = tail call i32 @free(i8* %19)
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = tail call i32 @strlen(i8* %33)
%35 = and i32 %34, 1
%36 = icmp eq i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %11
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.7, i64 0, i64 0))
br label %39
39: ; preds = %37, %11
%40 = load i8*, i8** %32
%41 = tail call i32 @strlen(i8* %40)
%42 = sext i32 %41 to i64
%43 = lshr i64 %42, 1
%44 = add nuw i64 %43, 1
%45 = tail call i64 @calloc(i64 %44, i64 1)
%46 = inttoptr i64 %45 to i8*
%47 = load i8*, i8** %32
%48 = bitcast i8* %47 to i64*
%49 = tail call i32 @strlen(i8* %47)
%50 = inttoptr i64 %45 to i64*
%51 = tail call i64 @hex2Bin(i64* %48, i32 %49, i64* %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %39
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.8, i64 0, i64 0))
br label %55
55: ; preds = %53, %39
%56 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i8* %46)
%57 = tail call i32 @strlen(i8* %46)
%58 = shl nsw i32 %57, 2
%59 = sext i32 %58 to i64
%60 = udiv i64 %59, 3
%61 = add nuw nsw i64 %60, 5
%62 = tail call i64 @calloc(i64 %61, i64 1)
%63 = inttoptr i64 %62 to i8*
%64 = tail call i32 @strlen(i8* %46)
%65 = inttoptr i64 %62 to i64*
%66 = tail call i32 @bin2Base64PlusSlashEquals(i64* %50, i32 %64, i64* %65)
%67 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.10, i64 0, i64 0), i8* %63)
br label %68
68: ; preds = %55, %9
%69 = phi i32 [ 1, %9 ], [ 0, %55 ]
ret i32 %69
}