#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 */
struct cgw_csum_crc8 {
  int profile;
  int /*<<< orphan*/ *profile_data;
};

/* Variables and functions */
#define CGW_CRC8PRF_16U8 130
#define CGW_CRC8PRF_1U8 129
#define CGW_CRC8PRF_SFFID_XOR 128
int /*<<< orphan*/ b64hex(char *, unsigned char *, int);
int sscanf(char *, char *, int *, ...);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
int parse_crc8_profile(char *optarg, struct cgw_csum_crc8 *crc8) {
  int ret = 1;
  char *ptr;
  if (sscanf(optarg, "%hhd:", &crc8->profile) != 1)
    return ret;
  switch (crc8->profile) {
  case CGW_CRC8PRF_1U8:
    if (sscanf(optarg, "%hhd:%2hhx", &crc8->profile, &crc8->profile_data[0]) ==
        2)
      ret = 0;
    break;
  case CGW_CRC8PRF_16U8:
    ptr = strchr(optarg, ':');
    if (ptr != NULL &&
        strlen(ptr) == strlen(":00112233445566778899AABBCCDDEEFF") &&
        b64hex(ptr + 1, (unsigned char *)&crc8->profile_data[0], 16) == 0)
      ret = 0;
    break;
  case CGW_CRC8PRF_SFFID_XOR:
    ret = 0;
    break;
  }
  return ret;
}


x86 assembly (clang, -O0):
<parse_crc8_profile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1181 <parse_crc8_profile+0x41>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <parse_crc8_profile+0x131>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x80,%eax
je     1264 <parse_crc8_profile+0x124>
jmp    119a <parse_crc8_profile+0x5a>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
je     11c0 <parse_crc8_profile+0x80>
jmp    11ad <parse_crc8_profile+0x6d>
mov    -0x2c(%rbp),%eax
sub    $0x82,%eax
je     11f3 <parse_crc8_profile+0xb3>
jmp    126b <parse_crc8_profile+0x12b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    11ee <parse_crc8_profile+0xae>
movl   $0x0,-0x1c(%rbp)
jmp    126b <parse_crc8_profile+0x12b>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     125f <parse_crc8_profile+0x11f>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x30(%rbp)
lea    0xdee(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jne    125f <parse_crc8_profile+0x11f>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x10,%edx
call   1060 <b64hex@plt>
cmp    $0x0,%eax
jne    125f <parse_crc8_profile+0x11f>
movl   $0x0,-0x1c(%rbp)
jmp    126b <parse_crc8_profile+0x12b>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_crc8_profile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeac(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    $0x1,%bpl
cmp    $0x1,%eax
jne    11ef <parse_crc8_profile+0xaf>
mov    (%r14),%eax
cmp    $0x80,%eax
je     119f <parse_crc8_profile+0x5f>
cmp    $0x82,%eax
je     11a3 <parse_crc8_profile+0x63>
cmp    $0x81,%eax
jne    11ef <parse_crc8_profile+0xaf>
mov    0x8(%r14),%rcx
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jmp    11eb <parse_crc8_profile+0xab>
xor    %ebp,%ebp
jmp    11ef <parse_crc8_profile+0xaf>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ef <parse_crc8_profile+0xaf>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
lea    0xe47(%rip),%rdi
call   1030 <strlen@plt>
cmp    %eax,%r15d
jne    11ef <parse_crc8_profile+0xaf>
add    $0x1,%rbx
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1060 <b64hex@plt>
test   %eax,%eax
setne  %bpl
movzbl %bpl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cgw_csum_crc8 = type { i32, i32* }
@.str = [6 x i8] c"%hhd:\00"
@.str.1 = [11 x i8] c"%hhd:%2hhx\00"
@.str.2 = [34 x i8] c":00112233445566778899AABBCCDDEEFF\00"
define i32 @parse_crc8_profile(i8* %0, %struct.cgw_csum_crc8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.cgw_csum_crc8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store %struct.cgw_csum_crc8* %1, %struct.cgw_csum_crc8** %5
store i32 1, i32* %6
%8 = load i8*, i8** %4
%9 = load %struct.cgw_csum_crc8*, %struct.cgw_csum_crc8** %5
%10 = getelementptr inbounds %struct.cgw_csum_crc8, %struct.cgw_csum_crc8* %9, i32 0, i32 0
%11 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %10)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %6
store i32 %14, i32* %3
br label %56
15: ; preds = %2
%16 = load %struct.cgw_csum_crc8*, %struct.cgw_csum_crc8** %5
%17 = getelementptr inbounds %struct.cgw_csum_crc8, %struct.cgw_csum_crc8* %16, i32 0, i32 0
%18 = load i32, i32* %17
switch i32 %18, label %54 [
i32 129, label %19
i32 130, label %31
i32 128, label %53
]
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load %struct.cgw_csum_crc8*, %struct.cgw_csum_crc8** %5
%22 = getelementptr inbounds %struct.cgw_csum_crc8, %struct.cgw_csum_crc8* %21, i32 0, i32 0
%23 = load %struct.cgw_csum_crc8*, %struct.cgw_csum_crc8** %5
%24 = getelementptr inbounds %struct.cgw_csum_crc8, %struct.cgw_csum_crc8* %23, i32 0, i32 1
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %22, i32* %26)
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %19
store i32 0, i32* %6
br label %30
30: ; preds = %29, %19
br label %54
31: ; preds = %15
%32 = load i8*, i8** %4
%33 = call i8* @strchr(i8* %32, i8 signext 58)
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %52
36: ; preds = %31
%37 = load i8*, i8** %7
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @strlen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %52
41: ; preds = %36
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load %struct.cgw_csum_crc8*, %struct.cgw_csum_crc8** %5
%45 = getelementptr inbounds %struct.cgw_csum_crc8, %struct.cgw_csum_crc8* %44, i32 0, i32 1
%46 = load i32*, i32** %45
%47 = getelementptr inbounds i32, i32* %46, i64 0
%48 = bitcast i32* %47 to i8*
%49 = call i32 @b64hex(i8* %43, i8* %48, i32 16)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %41
store i32 0, i32* %6
br label %52
52: ; preds = %51, %41, %36, %31
br label %54
53: ; preds = %15
store i32 0, i32* %6
br label %54
54: ; preds = %15, %53, %52, %30
%55 = load i32, i32* %6
store i32 %55, i32* %3
br label %56
56: ; preds = %54, %13
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.cgw_csum_crc8 = type { i32, i32* }
@.str = [6 x i8] c"%hhd:\00"
@.str.1 = [11 x i8] c"%hhd:%2hhx\00"
@.str.2 = [34 x i8] c":00112233445566778899AABBCCDDEEFF\00"
define i32 @parse_crc8_profile(i8* %0, %struct.cgw_csum_crc8* %1) {
%3 = getelementptr inbounds %struct.cgw_csum_crc8, %struct.cgw_csum_crc8* %1, i64 0, i32 0
%4 = tail call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %28
6: ; preds = %2
%7 = load i32, i32* %3
switch i32 %7, label %28 [
i32 129, label %8
i32 130, label %13
i32 128, label %27
]
8: ; preds = %6
%9 = getelementptr inbounds %struct.cgw_csum_crc8, %struct.cgw_csum_crc8* %1, i64 0, i32 1
%10 = load i32*, i32** %9
%11 = tail call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %10)
%12 = icmp ne i32 %11, 2
br label %28
13: ; preds = %6
%14 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%15 = icmp eq i8* %14, null
br i1 %15, label %28, label %16
16: ; preds = %13
%17 = tail call i32 @strlen(i8* %14)
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %14, i64 1
%22 = getelementptr inbounds %struct.cgw_csum_crc8, %struct.cgw_csum_crc8* %1, i64 0, i32 1
%23 = bitcast i32** %22 to i8**
%24 = load i8*, i8** %23
%25 = tail call i32 @b64hex(i8* %21, i8* %24, i32 16)
%26 = icmp ne i32 %25, 0
br label %28
27: ; preds = %6
br label %28
28: ; preds = %20, %8, %27, %6, %16, %13, %2
%29 = phi i1 [ true, %2 ], [ true, %6 ], [ false, %27 ], [ true, %16 ], [ true, %13 ], [ %12, %8 ], [ %26, %20 ]
%30 = zext i1 %29 to i32
ret i32 %30
}