#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 */
unsigned char ahextobin(char *);
scalar_t__ isxdigit(char);
unsigned int nmea_checksum(char *, unsigned char *);
char *strchr(char *, char);
unsigned int check_nmea_checksum(char *buffer, unsigned char *checksum) {
  unsigned int rv;
  char *p;
  unsigned char ssum;
  if (!buffer)
    return 2;
  if (!checksum)
    return 2;
  if (!(rv = nmea_checksum(buffer, checksum))) {
    if ((p = strchr((char *)buffer, '*')) == NULL)
      return 2;
    if (*p == '*') {
      if (isxdigit(*(p + 1)) && isxdigit(*(p + 2))) {
        ssum = ahextobin(p + 1) << 4;
        ssum += ahextobin(p + 2);
        if (ssum == *checksum)
          return 0;
      } else {
        return 1;
      }
    } else {
      return 1;
    }
  }
  return 2;
}


x86 assembly (clang, -O0):
<check_nmea_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1167 <check_nmea_checksum+0x27>
movl   $0x2,-0x4(%rbp)
jmp    1279 <check_nmea_checksum+0x139>
cmpq   $0x0,-0x18(%rbp)
jne    117e <check_nmea_checksum+0x3e>
movl   $0x2,-0x4(%rbp)
jmp    1279 <check_nmea_checksum+0x139>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <nmea_checksum@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1272 <check_nmea_checksum+0x132>
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11bf <check_nmea_checksum+0x7f>
movl   $0x2,-0x4(%rbp)
jmp    1279 <check_nmea_checksum+0x139>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    1261 <check_nmea_checksum+0x121>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%rax
je     1250 <check_nmea_checksum+0x110>
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%rax
je     1250 <check_nmea_checksum+0x110>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1050 <ahextobin@plt>
movzbl %al,%eax
shl    $0x4,%eax
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x2,%rdi
call   1050 <ahextobin@plt>
movzbl %al,%ecx
movzbl -0x29(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
mov    -0x18(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    124b <check_nmea_checksum+0x10b>
movl   $0x0,-0x4(%rbp)
jmp    1279 <check_nmea_checksum+0x139>
jmp    125c <check_nmea_checksum+0x11c>
movl   $0x1,-0x4(%rbp)
jmp    1279 <check_nmea_checksum+0x139>
jmp    126d <check_nmea_checksum+0x12d>
movl   $0x1,-0x4(%rbp)
jmp    1279 <check_nmea_checksum+0x139>
jmp    1272 <check_nmea_checksum+0x132>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_nmea_checksum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x2,%ebp
test   %rdi,%rdi
je     116d <check_nmea_checksum+0x2d>
mov    %rsi,%r15
test   %rsi,%rsi
je     116d <check_nmea_checksum+0x2d>
mov    %rdi,%rbx
mov    %r15,%rsi
call   1040 <nmea_checksum@plt>
test   %eax,%eax
je     117a <check_nmea_checksum+0x3a>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     116d <check_nmea_checksum+0x2d>
mov    %rax,%r14
mov    $0x1,%ebp
cmpb   $0x2a,(%rax)
jne    116d <check_nmea_checksum+0x2d>
movsbl 0x1(%r14),%edi
call   1060 <isxdigit@plt>
test   %rax,%rax
je     116d <check_nmea_checksum+0x2d>
movsbl 0x2(%r14),%edi
call   1060 <isxdigit@plt>
test   %rax,%rax
je     116d <check_nmea_checksum+0x2d>
lea    0x1(%r14),%rdi
add    $0x2,%r14
call   1050 <ahextobin@plt>
mov    %eax,%ebx
shl    $0x4,%bl
mov    %r14,%rdi
call   1050 <ahextobin@plt>
add    %bl,%al
xor    %ebp,%ebp
cmp    (%r15),%al
jne    1168 <check_nmea_checksum+0x28>
jmp    116d <check_nmea_checksum+0x2d>

LLVM IR (-O0):
define i32 @check_nmea_checksum(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 2, i32* %3
br label %71
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12
store i32 2, i32* %3
br label %71
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 @nmea_checksum(i8* %17, i8* %18)
store i32 %19, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %70, label %21
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i8* @strchr(i8* %22, i8 signext 42)
store i8* %23, i8** %7
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 2, i32* %3
br label %71
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 42
br i1 %30, label %31, label %68
31: ; preds = %26
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = call i64 @isxdigit(i8 signext %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %66
37: ; preds = %31
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = load i8, i8* %39
%41 = call i64 @isxdigit(i8 signext %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %66
43: ; preds = %37
%44 = load i8*, i8** %7
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = call zeroext i8 @ahextobin(i8* %45)
%47 = zext i8 %46 to i32
%48 = shl i32 %47, 4
%49 = trunc i32 %48 to i8
store i8 %49, i8* %8
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = call zeroext i8 @ahextobin(i8* %51)
%53 = zext i8 %52 to i32
%54 = load i8, i8* %8
%55 = zext i8 %54 to i32
%56 = add nsw i32 %55, %53
%57 = trunc i32 %56 to i8
store i8 %57, i8* %8
%58 = load i8, i8* %8
%59 = zext i8 %58 to i32
%60 = load i8*, i8** %5
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp eq i32 %59, %62
br i1 %63, label %64, label %65
64: ; preds = %43
store i32 0, i32* %3
br label %71
65: ; preds = %43
br label %67
66: ; preds = %37, %31
store i32 1, i32* %3
br label %71
67: ; preds = %65
br label %69
68: ; preds = %26
store i32 1, i32* %3
br label %71
69: ; preds = %67
br label %70
70: ; preds = %69, %16
store i32 2, i32* %3
br label %71
71: ; preds = %70, %68, %66, %64, %25, %15, %11
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
define i32 @check_nmea_checksum(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %33, label %6
6: ; preds = %2
%7 = tail call i32 @nmea_checksum(i8* %0, i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %6
%10 = tail call i8* @strchr(i8* %0, i8 signext 42)
%11 = icmp eq i8* %10, null
br i1 %11, label %33, label %12
12: ; preds = %9
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 42
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %10, i64 1
%17 = load i8, i8* %16
%18 = tail call i64 @isxdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %15
%21 = getelementptr inbounds i8, i8* %10, i64 2
%22 = load i8, i8* %21
%23 = tail call i64 @isxdigit(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %20
%26 = tail call zeroext i8 @ahextobin(i8* %16)
%27 = shl i8 %26, 4
%28 = tail call zeroext i8 @ahextobin(i8* %21)
%29 = add i8 %27, %28
%30 = load i8, i8* %1
%31 = icmp eq i8 %29, %30
br i1 %31, label %33, label %32
32: ; preds = %25, %6
br label %33
33: ; preds = %12, %15, %20, %25, %9, %2, %32
%34 = phi i32 [ 2, %32 ], [ 2, %2 ], [ 2, %9 ], [ 0, %25 ], [ 1, %20 ], [ 1, %15 ], [ 1, %12 ]
ret i32 %34
}