#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ isxdigit(int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char strtol(char *, int /*<<< orphan*/ *, int);
char tolower(char);
int ParseCryptoPAnKey(char *s, char *key) {
  int i, j;
  char numstr[3];
  uint32_t len = strlen(s);
  if (len < 32 || len > 66) {
    fprintf(stderr, "*** CryptoPAnKey error: size: %u\n", len);
    fprintf(stderr, "*** Need either a plain 32 char string, or a 32 byte hex "
                    "key starting with 0x..\n");
    return 0;
  }
  if (strlen(s) == 32) {
    strncpy(key, s, 32);
    return 1;
  }
  s[1] = tolower(s[1]);
  numstr[2] = 0;
  if (strlen(s) == 66 && s[0] == '0' && s[1] == 'x') {
    j = 2;
    for (i = 0; i < 32; i++) {
      if (!isxdigit((int)s[j]) || !isxdigit((int)s[j + 1]))
        return 0;
      numstr[0] = s[j++];
      numstr[1] = s[j++];
      key[i] = strtol(numstr, NULL, 16);
    }
    return 1;
  }
  fprintf(stderr, "*** CryptoPAnKey error: size: %u\n", len);
  fprintf(stderr, "*** Need either a plain 32 char string, or a 32 byte hex "
                  "key starting with 0x..\n");
  return 0;
}


x86 assembly (clang, -O0):
<ParseCryptoPAnKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x20,-0x28(%rbp)
jl     1190 <ParseCryptoPAnKey+0x30>
cmpl   $0x42,-0x28(%rbp)
jle    11cd <ParseCryptoPAnKey+0x6d>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1348 <ParseCryptoPAnKey+0x1e8>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x20,%eax
jne    11fd <ParseCryptoPAnKey+0x9d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    1348 <ParseCryptoPAnKey+0x1e8>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1070 <tolower@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movb   $0x0,-0x21(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x42,%eax
jne    1310 <ParseCryptoPAnKey+0x1b0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1310 <ParseCryptoPAnKey+0x1b0>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    1310 <ParseCryptoPAnKey+0x1b0>
movl   $0x2,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    1304 <ParseCryptoPAnKey+0x1a4>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <isxdigit@plt>
cmp    $0x0,%eax
je     129b <ParseCryptoPAnKey+0x13b>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <isxdigit@plt>
cmp    $0x0,%eax
jne    12a7 <ParseCryptoPAnKey+0x147>
movl   $0x0,-0x4(%rbp)
jmp    1348 <ParseCryptoPAnKey+0x1e8>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x23(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x22(%rbp)
lea    -0x23(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1258 <ParseCryptoPAnKey+0xf8>
movl   $0x1,-0x4(%rbp)
jmp    1348 <ParseCryptoPAnKey+0x1e8>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xce8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ParseCryptoPAnKey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%r15d
add    $0xffffffbd,%eax
cmp    $0xffffffdc,%eax
jbe    1244 <ParseCryptoPAnKey+0xe4>
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    $0x20,%eax
jne    11ac <ParseCryptoPAnKey+0x4c>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x20,%edx
call   1030 <strncpy@plt>
mov    $0x1,%ebp
jmp    1270 <ParseCryptoPAnKey+0x110>
movsbl 0x1(%r12),%edi
call   1070 <tolower@plt>
mov    %al,0x1(%r12)
movb   $0x0,0x7(%rsp)
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    $0x42,%eax
jne    1244 <ParseCryptoPAnKey+0xe4>
cmpb   $0x30,(%r12)
jne    1244 <ParseCryptoPAnKey+0xe4>
cmpb   $0x78,0x1(%r12)
jne    1244 <ParseCryptoPAnKey+0xe4>
xor    %ebx,%ebx
lea    0x5(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x2(%r12,%rbx,2),%ebp
movsbl %bpl,%edi
call   1080 <isxdigit@plt>
test   %eax,%eax
je     1281 <ParseCryptoPAnKey+0x121>
movzbl 0x3(%r12,%rbx,2),%r13d
movsbl %r13b,%edi
call   1080 <isxdigit@plt>
test   %eax,%eax
je     1281 <ParseCryptoPAnKey+0x121>
mov    %bpl,0x5(%rsp)
mov    %r13b,0x6(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    $0x1,%ebp
cmp    $0x20,%rbx
jne    11f0 <ParseCryptoPAnKey+0x90>
jmp    1270 <ParseCryptoPAnKey+0x110>
mov    0x2d95(%rip),%rbx
mov    (%rbx),%edi
lea    0xdac(%rip),%rsi
xor    %ebp,%ebp
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdb9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    1270 <ParseCryptoPAnKey+0x110>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"*** CryptoPAnKey error: size: %u\0A\00"
@.str.1 = [81 x i8] c"*** Need either a plain 32 char string, or a 32 byte hex key starting with 0x..\0A\00"
define i32 @ParseCryptoPAnKey(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 32
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* %9
%16 = icmp sgt i32 %15, 66
br i1 %16, label %17, label %23
17: ; preds = %14, %2
%18 = load i32, i32* @stderr
%19 = load i32, i32* %9
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %109
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = icmp eq i32 %25, 32
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = load i8*, i8** %4
%30 = call i32 @strncpy(i8* %28, i8* %29, i32 32)
store i32 1, i32* %3
br label %109
31: ; preds = %23
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = call signext i8 @tolower(i8 signext %34)
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 1
store i8 %35, i8* %37
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
store i8 0, i8* %38
%39 = load i8*, i8** %4
%40 = call i32 @strlen(i8* %39)
%41 = icmp eq i32 %40, 66
br i1 %41, label %42, label %103
42: ; preds = %31
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 48
br i1 %47, label %48, label %103
48: ; preds = %42
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 120
br i1 %53, label %54, label %103
54: ; preds = %48
store i32 2, i32* %7
store i32 0, i32* %6
br label %55
55: ; preds = %99, %54
%56 = load i32, i32* %6
%57 = icmp slt i32 %56, 32
br i1 %57, label %58, label %102
58: ; preds = %55
%59 = load i8*, i8** %4
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = call i32 @isxdigit(i32 %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %77
67: ; preds = %58
%68 = load i8*, i8** %4
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = call i32 @isxdigit(i32 %74)
%76 = icmp ne i32 %75, 0
br i1 %76, label %78, label %77
77: ; preds = %67, %58
store i32 0, i32* %3
br label %109
78: ; preds = %67
%79 = load i8*, i8** %4
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
%82 = sext i32 %80 to i64
%83 = getelementptr inbounds i8, i8* %79, i64 %82
%84 = load i8, i8* %83
%85 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
store i8 %84, i8* %85
%86 = load i8*, i8** %4
%87 = load i32, i32* %7
%88 = add nsw i32 %87, 1
store i32 %88, i32* %7
%89 = sext i32 %87 to i64
%90 = getelementptr inbounds i8, i8* %86, i64 %89
%91 = load i8, i8* %90
%92 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 %91, i8* %92
%93 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%94 = call signext i8 @strtol(i8* %93, i32* null, i32 16)
%95 = load i8*, i8** %5
%96 = load i32, i32* %6
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
store i8 %94, i8* %98
br label %99
99: ; preds = %78
%100 = load i32, i32* %6
%101 = add nsw i32 %100, 1
store i32 %101, i32* %6
br label %55
102: ; preds = %55
store i32 1, i32* %3
br label %109
103: ; preds = %48, %42, %31
%104 = load i32, i32* @stderr
%105 = load i32, i32* %9
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %105)
%107 = load i32, i32* @stderr
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %109
109: ; preds = %103, %102, %77, %27, %17
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"*** CryptoPAnKey error: size: %u\0A\00"
@.str.1 = [81 x i8] c"*** Need either a plain 32 char string, or a 32 byte hex key starting with 0x..\0A\00"
define i32 @ParseCryptoPAnKey(i8* %0, i8* %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %0)
%6 = add i32 %5, -67
%7 = icmp ult i32 %6, -35
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %5)
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
br label %59
13: ; preds = %2
%14 = tail call i32 @strlen(i8* %0)
%15 = icmp eq i32 %14, 32
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @strncpy(i8* %1, i8* %0, i32 32)
br label %59
18: ; preds = %13
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = load i8, i8* %19
%21 = tail call signext i8 @tolower(i8 signext %20)
store i8 %21, i8* %19
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %22
%23 = tail call i32 @strlen(i8* %0)
%24 = icmp eq i32 %23, 66
br i1 %24, label %25, label %54
25: ; preds = %18
%26 = load i8, i8* %0
%27 = icmp eq i8 %26, 48
br i1 %27, label %28, label %54
28: ; preds = %25
%29 = load i8, i8* %19
%30 = icmp eq i8 %29, 120
br i1 %30, label %31, label %54
31: ; preds = %28
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
br label %33
33: ; preds = %31, %48
%34 = phi i64 [ 0, %31 ], [ %52, %48 ]
%35 = phi i64 [ 2, %31 ], [ %49, %48 ]
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = tail call i32 @isxdigit(i32 %38)
%40 = icmp eq i32 %39, 0
br i1 %40, label %59, label %41
41: ; preds = %33
%42 = or i64 %35, 1
%43 = getelementptr inbounds i8, i8* %0, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = tail call i32 @isxdigit(i32 %45)
%47 = icmp eq i32 %46, 0
br i1 %47, label %59, label %48
48: ; preds = %41
store i8 %37, i8* %4
%49 = add nuw nsw i64 %35, 2
store i8 %44, i8* %32
%50 = call signext i8 @strtol(i8* nocapture %4, i32* null, i32 16)
%51 = getelementptr inbounds i8, i8* %1, i64 %34
store i8 %50, i8* %51
%52 = add nuw nsw i64 %34, 1
%53 = icmp eq i64 %52, 32
br i1 %53, label %59, label %33
54: ; preds = %28, %25, %18
%55 = load i32, i32* @stderr
%56 = tail call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %5)
%57 = load i32, i32* @stderr
%58 = tail call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
br label %59
59: ; preds = %48, %33, %41, %54, %16, %8
%60 = phi i32 [ 0, %8 ], [ 1, %16 ], [ 0, %54 ], [ 1, %48 ], [ 0, %33 ], [ 0, %41 ]
ret i32 %60
}