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

/* Variables and functions */
scalar_t__ strchr(char const *, char);
int /*<<< orphan*/ strtol(scalar_t__, int /*<<< orphan*/ *, int);
uint8_t nmea_valid_checksum(const char *message) {
  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>
mov    %rax,%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %al,-0x11(%rbp)
movb   $0x0,-0x13(%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,-0x12(%rbp)
movsbl %al,%eax
cmp    $0x2a,%eax
je     1194 <nmea_valid_checksum+0x74>
movsbl -0x12(%rbp),%ecx
movsbl -0x13(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x13(%rbp)
jmp    1162 <nmea_valid_checksum+0x42>
movsbl -0x13(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     11ad <nmea_valid_checksum+0x8d>
movb   $0x80,-0x1(%rbp)
jmp    11b1 <nmea_valid_checksum+0x91>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%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>
lea    0x1(%rax),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
add    $0x1,%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%ecx
movsbl (%r14),%edx
xor    %edx,%ebx
add    $0x1,%r14
cmp    $0x2a,%edx
jne    1150 <nmea_valid_checksum+0x30>
movsbl %al,%eax
cmp    %eax,%ecx
setne  %al
shl    $0x7,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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