#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ is_hex(char *, int);
scalar_t__ is_name(char *, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char *, int);
int sscanf(char *, char *, int /*<<< orphan*/ *);
int strlen(char *);
int str2nodeid(char *str, uint8_t *id) {
  int len = strlen(str);
  int i;
  if (len > 32)
    return -1;
  if (is_name(str, len - 1)) {
    memcpy(id, str, len);
    return 0;
  }
  if (!is_hex(str, len - 1))
    return -1;
  str[len] = '0';
  for (i = 0; i < 16; i++) {
    if (sscanf(&str[2 * i], "%2hhx", &id[i]) != 1)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<str2nodeid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jle    1182 <str2nodeid+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <str2nodeid+0xfa>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
call   1070 <is_name@plt>
cmp    $0x0,%rax
je     11b7 <str2nodeid+0x67>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    124a <str2nodeid+0xfa>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
call   1040 <is_hex@plt>
cmp    $0x0,%eax
jne    11db <str2nodeid+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <str2nodeid+0xfa>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
movl   $0x0,-0x20(%rbp)
cmpl   $0x10,-0x20(%rbp)
jge    1243 <str2nodeid+0xf3>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xde3(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1230 <str2nodeid+0xe0>
jmp    1243 <str2nodeid+0xf3>
jmp    1235 <str2nodeid+0xe5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ee <str2nodeid+0x9e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2nodeid>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    $0xffffffff,%r15d
cmp    $0x20,%eax
jg     1192 <str2nodeid+0x42>
mov    %eax,%ebp
lea    -0x1(%rbp),%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1070 <is_name@plt>
test   %rax,%rax
je     119e <str2nodeid+0x4e>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <is_hex@plt>
test   %eax,%eax
je     1192 <str2nodeid+0x42>
movslq %ebp,%rax
movb   $0x30,(%r12,%rax,1)
lea    0xe45(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
xor    %r15d,%r15d
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x2(%r12),%rdi
lea    0x4(%r14),%rdx
lea    0xe22(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x4(%r12),%rdi
lea    0x8(%r14),%rdx
lea    0xe08(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x6(%r12),%rdi
lea    0xc(%r14),%rdx
lea    0xdee(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x8(%r12),%rdi
lea    0x10(%r14),%rdx
lea    0xdd0(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0xa(%r12),%rdi
lea    0x14(%r14),%rdx
lea    0xdb2(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0xc(%r12),%rdi
lea    0x18(%r14),%rdx
lea    0xd94(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0xe(%r12),%rdi
lea    0x1c(%r14),%rdx
lea    0xd76(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x10(%r12),%rdi
lea    0x20(%r14),%rdx
lea    0xd58(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x12(%r12),%rdi
lea    0x24(%r14),%rdx
lea    0xd3a(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x14(%r12),%rdi
lea    0x28(%r14),%rdx
lea    0xd1c(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x16(%r12),%rdi
lea    0x2c(%r14),%rdx
lea    0xcfe(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x18(%r12),%rdi
lea    0x30(%r14),%rdx
lea    0xce0(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x1a(%r12),%rdi
lea    0x34(%r14),%rdx
lea    0xcc2(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
lea    0x1c(%r12),%rdi
lea    0x38(%r14),%rdx
lea    0xca4(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1192 <str2nodeid+0x42>
add    $0x1e,%r12
add    $0x3c,%r14
lea    0xc87(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
jmp    1192 <str2nodeid+0x42>

LLVM IR (-O0):
@.str = [6 x i8] c"%2hhx\00"
define i32 @str2nodeid(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 32
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %57
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = sub nsw i32 %15, 1
%17 = call i64 @is_name(i8* %14, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = load i32*, i32** %5
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = call i32 @memcpy(i32* %20, i8* %21, i32 %22)
store i32 0, i32* %3
br label %57
24: ; preds = %13
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 1
%28 = call i32 @is_hex(i8* %25, i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %24
store i32 -1, i32* %3
br label %57
31: ; preds = %24
%32 = load i8*, i8** %4
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 48, i8* %35
store i32 0, i32* %7
br label %36
36: ; preds = %53, %31
%37 = load i32, i32* %7
%38 = icmp slt i32 %37, 16
br i1 %38, label %39, label %56
39: ; preds = %36
%40 = load i8*, i8** %4
%41 = load i32, i32* %7
%42 = mul nsw i32 2, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
%45 = load i32*, i32** %5
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = call i32 @sscanf(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %48)
%50 = icmp ne i32 %49, 1
br i1 %50, label %51, label %52
51: ; preds = %39
br label %56
52: ; preds = %39
br label %53
53: ; preds = %52
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %36
56: ; preds = %51, %36
store i32 0, i32* %3
br label %57
57: ; preds = %56, %30, %19, %12
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [6 x i8] c"%2hhx\00"
define i32 @str2nodeid(i8* %0, i32* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 32
br i1 %4, label %93, label %5
5: ; preds = %2
%6 = add nsw i32 %3, -1
%7 = tail call i64 @is_name(i8* %0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @memcpy(i32* %1, i8* %0, i32 %3)
br label %93
11: ; preds = %5
%12 = tail call i32 @is_hex(i8* %0, i32 %6)
%13 = icmp eq i32 %12, 0
br i1 %13, label %93, label %14
14: ; preds = %11
%15 = sext i32 %3 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 48, i8* %16
%17 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %93
19: ; preds = %14
%20 = getelementptr inbounds i8, i8* %0, i64 2
%21 = getelementptr inbounds i32, i32* %1, i64 1
%22 = tail call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %93
24: ; preds = %19
%25 = getelementptr inbounds i8, i8* %0, i64 4
%26 = getelementptr inbounds i32, i32* %1, i64 2
%27 = tail call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %93
29: ; preds = %24
%30 = getelementptr inbounds i8, i8* %0, i64 6
%31 = getelementptr inbounds i32, i32* %1, i64 3
%32 = tail call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %31)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %93
34: ; preds = %29
%35 = getelementptr inbounds i8, i8* %0, i64 8
%36 = getelementptr inbounds i32, i32* %1, i64 4
%37 = tail call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %36)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %93
39: ; preds = %34
%40 = getelementptr inbounds i8, i8* %0, i64 10
%41 = getelementptr inbounds i32, i32* %1, i64 5
%42 = tail call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %41)
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %93
44: ; preds = %39
%45 = getelementptr inbounds i8, i8* %0, i64 12
%46 = getelementptr inbounds i32, i32* %1, i64 6
%47 = tail call i32 @sscanf(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %46)
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %93
49: ; preds = %44
%50 = getelementptr inbounds i8, i8* %0, i64 14
%51 = getelementptr inbounds i32, i32* %1, i64 7
%52 = tail call i32 @sscanf(i8* %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %51)
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %93
54: ; preds = %49
%55 = getelementptr inbounds i8, i8* %0, i64 16
%56 = getelementptr inbounds i32, i32* %1, i64 8
%57 = tail call i32 @sscanf(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %56)
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %93
59: ; preds = %54
%60 = getelementptr inbounds i8, i8* %0, i64 18
%61 = getelementptr inbounds i32, i32* %1, i64 9
%62 = tail call i32 @sscanf(i8* %60, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %61)
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %93
64: ; preds = %59
%65 = getelementptr inbounds i8, i8* %0, i64 20
%66 = getelementptr inbounds i32, i32* %1, i64 10
%67 = tail call i32 @sscanf(i8* %65, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %66)
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %93
69: ; preds = %64
%70 = getelementptr inbounds i8, i8* %0, i64 22
%71 = getelementptr inbounds i32, i32* %1, i64 11
%72 = tail call i32 @sscanf(i8* %70, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %71)
%73 = icmp eq i32 %72, 1
br i1 %73, label %74, label %93
74: ; preds = %69
%75 = getelementptr inbounds i8, i8* %0, i64 24
%76 = getelementptr inbounds i32, i32* %1, i64 12
%77 = tail call i32 @sscanf(i8* %75, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %76)
%78 = icmp eq i32 %77, 1
br i1 %78, label %79, label %93
79: ; preds = %74
%80 = getelementptr inbounds i8, i8* %0, i64 26
%81 = getelementptr inbounds i32, i32* %1, i64 13
%82 = tail call i32 @sscanf(i8* %80, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %81)
%83 = icmp eq i32 %82, 1
br i1 %83, label %84, label %93
84: ; preds = %79
%85 = getelementptr inbounds i8, i8* %0, i64 28
%86 = getelementptr inbounds i32, i32* %1, i64 14
%87 = tail call i32 @sscanf(i8* %85, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %86)
%88 = icmp eq i32 %87, 1
br i1 %88, label %89, label %93
89: ; preds = %84
%90 = getelementptr inbounds i8, i8* %0, i64 30
%91 = getelementptr inbounds i32, i32* %1, i64 15
%92 = tail call i32 @sscanf(i8* %90, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %91)
br label %93
93: ; preds = %89, %14, %19, %24, %29, %34, %39, %44, %49, %54, %59, %64, %69, %74, %79, %84, %11, %2, %9
%94 = phi i32 [ 0, %9 ], [ -1, %2 ], [ -1, %11 ], [ 0, %89 ], [ 0, %84 ], [ 0, %79 ], [ 0, %74 ], [ 0, %69 ], [ 0, %64 ], [ 0, %59 ], [ 0, %54 ], [ 0, %49 ], [ 0, %44 ], [ 0, %39 ], [ 0, %34 ], [ 0, %29 ], [ 0, %24 ], [ 0, %19 ], [ 0, %14 ]
ret i32 %94
}