#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ *strchr(char const *, char);
int /*<<< orphan*/ strtol(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
uint8_t nmea_valid_checksum(const char *message) {
  if (strchr(message, '*') == NULL) {
    return 0x00;
  }
  uint8_t checksum = (uint8_t)strtol(strchr(message, '*') + 1, NULL, 16);
  char p;
  uint8_t sum = 0;
  ++message;
  while ((p = *message++) != '*') {
    sum ^= p;
  }
  if (sum != checksum) {
    return 0x80;
  }
  return 0x00;
}


x86 assembly (clang, -O0):
<nmea_valid_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1150 <nmea_valid_checksum+0x30>
movl   $0x0,-0x4(%rbp)
jmp    11d7 <nmea_valid_checksum+0xb7>
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
mov    %rax,%rdi
add    $0x4,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl %al,%eax
cmp    $0x2a,%eax
je     11b8 <nmea_valid_checksum+0x98>
movsbl -0x15(%rbp),%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <nmea_valid_checksum+0x69>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11d0 <nmea_valid_checksum+0xb0>
movl   $0x80,-0x4(%rbp)
jmp    11d7 <nmea_valid_checksum+0xb7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nmea_valid_checksum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     117d <nmea_valid_checksum+0x5d>
mov    %r14,%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
lea    0x4(%rax),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
add    $0x1,%r14
nopl   0x0(%rax)
mov    %ebx,%edx
movsbl (%r14),%ecx
xor    %ecx,%ebx
add    $0x1,%r14
cmp    $0x2a,%ecx
jne    1160 <nmea_valid_checksum+0x40>
xor    %ecx,%ecx
cmp    %eax,%edx
setne  %cl
shl    $0x7,%ecx
jmp    117f <nmea_valid_checksum+0x5f>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @nmea_valid_checksum(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @strchr(i8* %7, i8 signext 42)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %35
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32* @strchr(i8* %12, i8 signext 42)
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = call i32 @strtol(i32* %14, i32* null, i32 16)
store i32 %15, i32* %4
store i32 0, i32* %6
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %3
br label %18
18: ; preds = %24, %11
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
%21 = load i8, i8* %19
store i8 %21, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 42
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = load i32, i32* %6
%28 = xor i32 %27, %26
store i32 %28, i32* %6
br label %18
29: ; preds = %18
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 128, i32* %2
br label %35
34: ; preds = %29
store i32 0, i32* %2
br label %35
35: ; preds = %34, %33, %10
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @nmea_valid_checksum(i8* %0) {
%2 = tail call i32* @strchr(i8* %0, i8 signext 42)
%3 = icmp eq i32* %2, null
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = tail call i32* @strchr(i8* %0, i8 signext 42)
%6 = getelementptr inbounds i32, i32* %5, i64 1
%7 = tail call i32 @strtol(i32* nocapture %6, i32* null, i32 16)
br label %8
8: ; preds = %8, %4
%9 = phi i8* [ %0, %4 ], [ %11, %8 ]
%10 = phi i32 [ 0, %4 ], [ %15, %8 ]
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 42
%14 = sext i8 %12 to i32
%15 = xor i32 %10, %14
br i1 %13, label %16, label %8
16: ; preds = %8
%17 = icmp eq i32 %10, %7
%18 = select i1 %17, i32 0, i32 128
br label %19
19: ; preds = %1, %16
%20 = phi i32 [ %18, %16 ], [ 0, %1 ]
ret i32 %20
}