#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 */

/* Variables and functions */
int /*<<< orphan*/ check_sum(char const *, unsigned int);
int hex_to_int(char const *);
int check_hex_line(const char *str, unsigned int len) {
  if ((str[0] != ':') || (len < 11) || !check_sum(str, len) ||
      (hex_to_int(str + 1) * 2 + 11 != len))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<check_hex_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    117a <check_hex_line+0x5a>
cmpl   $0xb,-0x14(%rbp)
jb     117a <check_hex_line+0x5a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <check_sum@plt>
cmp    $0x0,%eax
je     117a <check_hex_line+0x5a>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1040 <hex_to_int@plt>
shl    $0x1,%eax
add    $0xb,%eax
cmp    -0x14(%rbp),%eax
je     1186 <check_hex_line+0x66>
movl   $0x0,-0x4(%rbp)
jmp    118d <check_hex_line+0x6d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_hex_line>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
cmp    $0xb,%esi
jb     115b <check_hex_line+0x3b>
mov    %rdi,%rbp
cmpb   $0x3a,(%rdi)
jne    115b <check_hex_line+0x3b>
mov    %esi,%r14d
mov    %rbp,%rdi
call   1030 <check_sum@plt>
test   %eax,%eax
je     115b <check_hex_line+0x3b>
add    $0x1,%rbp
mov    %rbp,%rdi
call   1040 <hex_to_int@plt>
add    %eax,%eax
add    $0xb,%eax
xor    %ebx,%ebx
cmp    %r14d,%eax
sete   %bl
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_hex_line(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 58
br i1 %10, label %27, label %11
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp ult i32 %12, 11
br i1 %13, label %27, label %14
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = call i32 @check_sum(i8* %15, i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @hex_to_int(i8* %21)
%23 = mul nsw i32 %22, 2
%24 = add nsw i32 %23, 11
%25 = load i32, i32* %5
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %19, %14, %11, %2
store i32 0, i32* %3
br label %29
28: ; preds = %19
store i32 1, i32* %3
br label %29
29: ; preds = %28, %27
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @check_hex_line(i8* %0, i32 %1) {
%3 = load i8, i8* %0
%4 = icmp ne i8 %3, 58
%5 = icmp ult i32 %1, 11
%6 = or i1 %5, %4
br i1 %6, label %17, label %7
7: ; preds = %2
%8 = tail call i32 @check_sum(i8* %0, i32 %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = tail call i32 @hex_to_int(i8* %11)
%13 = shl nsw i32 %12, 1
%14 = add nsw i32 %13, 11
%15 = icmp eq i32 %14, %1
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %10, %2, %7
%18 = phi i32 [ 0, %7 ], [ 0, %2 ], [ %16, %10 ]
ret i32 %18
}