void parse_toeplitz_key(char *str, int slen, unsigned char *key) {
  int i, ret, off;
  if (slen < ((40 * 3) - 1) || slen > ((60 * 3) - 1) + 1)
    error(1, 0, "invalid toeplitz key\n");
  for (i = 0, off = 0; off < slen; i++, off += 3) {
    ret = sscanf(str + off, "%hhx", &key[i]);
    if (ret != 1)
      error(1, 0, "parse error at key index %d off %d len %d\n", i, off, slen);
  }
}


x86 assembly (clang, -O0):
<parse_toeplitz_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x77,-0xc(%rbp)
jl     114a <parse_toeplitz_key+0x2a>
cmpl   $0xb4,-0xc(%rbp)
jle    115f <parse_toeplitz_key+0x3f>
mov    $0x1,%edi
xor    %esi,%esi
lea    0xea8(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <parse_toeplitz_key+0xc6>
mov    -0x8(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
movslq -0x1c(%rbp),%rax
add    %rax,%rdx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
je     11ca <parse_toeplitz_key+0xaa>
mov    -0x1c(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0xc(%rbp),%r9d
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe58(%rip),%rdx
mov    $0x0,%al
call   1040 <error@plt>
jmp    11cf <parse_toeplitz_key+0xaf>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
jmp    116d <parse_toeplitz_key+0x4d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_toeplitz_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r15
lea    -0xb5(%rbx),%eax
cmp    $0xffffffc1,%eax
ja     1157 <parse_toeplitz_key+0x37>
lea    0xebb(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <error@plt>
test   %ebx,%ebx
jle    11b3 <parse_toeplitz_key+0x93>
lea    0xeb8(%rip),%r12
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    117d <parse_toeplitz_key+0x5d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
add    $0x3,%r13
cmp    %ebx,%r13d
jge    11b3 <parse_toeplitz_key+0x93>
lea    (%r15,%r13,1),%rdi
lea    (%r14,%rbp,1),%rdx
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1170 <parse_toeplitz_key+0x50>
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe79(%rip),%rdx
mov    %ebp,%ecx
mov    %r13d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1040 <error@plt>
jmp    1170 <parse_toeplitz_key+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"invalid toeplitz key\0A\00"
@.str.1 = [5 x i8] c"%hhx\00"
@.str.2 = [43 x i8] c"parse error at key index %d off %d len %d\0A\00"
define void @parse_toeplitz_key(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 119
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 180
br i1 %14, label %15, label %17
15: ; preds = %12, %3
%16 = call i32 (i32, i32, i8*, ...) bitcast (i32 (...)* @error to i32 (i32, i32, i8*, ...)*)(i32 1, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
store i32 0, i32* %7
store i32 0, i32* %9
br label %18
18: ; preds = %40, %17
%19 = load i32, i32* %9
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i32 (i8*, i8*, ...) @sscanf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %39
34: ; preds = %22
%35 = load i32, i32* %7
%36 = load i32, i32* %9
%37 = load i32, i32* %5
%38 = call i32 (i32, i32, i8*, i32, i32, i32, ...) bitcast (i32 (...)* @error to i32 (i32, i32, i8*, i32, i32, i32, ...)*)(i32 1, i32 0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %36, i32 %37)
br label %39
39: ; preds = %34, %22
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 3
store i32 %44, i32* %9
br label %18
45: ; preds = %18
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"invalid toeplitz key\0A\00"
@.str.1 = [5 x i8] c"%hhx\00"
@.str.2 = [43 x i8] c"parse error at key index %d off %d len %d\0A\00"
define void @parse_toeplitz_key(i8* nocapture %0, i32 %1, i8* %2) {
%4 = add i32 %1, -181
%5 = icmp ult i32 %4, -62
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 (i32, i32, i8*, ...) bitcast (i32 (...)* @error to i32 (i32, i32, i8*, ...)*)(i32 1, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %26
9: ; preds = %3, %6
br label %10
10: ; preds = %9, %21
%11 = phi i64 [ %22, %21 ], [ 0, %9 ]
%12 = phi i64 [ %23, %21 ], [ 0, %9 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = getelementptr inbounds i8, i8* %2, i64 %11
%15 = tail call i32 (i8*, i8*, ...) @sscanf(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %21, label %17
17: ; preds = %10
%18 = trunc i64 %12 to i32
%19 = trunc i64 %11 to i32
%20 = tail call i32 (i32, i32, i8*, i32, i32, i32, ...) bitcast (i32 (...)* @error to i32 (i32, i32, i8*, i32, i32, i32, ...)*)(i32 1, i32 0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %18, i32 %1)
br label %21
21: ; preds = %10, %17
%22 = add nuw i64 %11, 1
%23 = add nuw i64 %12, 3
%24 = trunc i64 %23 to i32
%25 = icmp slt i32 %24, %1
br i1 %25, label %10, label %26
26: ; preds = %21, %6
ret void
}