#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 */
char *strchr(char const *, char);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
uint8_t nmea_valid_checksum(const char *message) {
  char *fuck = strchr(message, '*');
  if (fuck == NULL)
    return 0x80;
  uint8_t checksum = (uint8_t)strtol(fuck + 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    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1155 <nmea_valid_checksum+0x35>
movl   $0x80,-0x4(%rbp)
jmp    11cf <nmea_valid_checksum+0xaf>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%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,-0x1d(%rbp)
movsbl %al,%eax
cmp    $0x2a,%eax
je     11b0 <nmea_valid_checksum+0x90>
movsbl -0x1d(%rbp),%eax
xor    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1181 <nmea_valid_checksum+0x61>
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11c8 <nmea_valid_checksum+0xa8>
movl   $0x80,-0x4(%rbp)
jmp    11cf <nmea_valid_checksum+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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     116d <nmea_valid_checksum+0x4d>
add    $0x1,%rax
xor    %ebx,%ebx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
add    $0x1,%r14
nop
mov    %ebx,%edx
movsbl (%r14),%ecx
xor    %ecx,%ebx
add    $0x1,%r14
cmp    $0x2a,%ecx
jne    1150 <nmea_valid_checksum+0x30>
xor    %ecx,%ecx
cmp    %eax,%edx
setne  %cl
shl    $0x7,%ecx
jmp    1172 <nmea_valid_checksum+0x52>
mov    $0x80,%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 i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i8* @strchr(i8* %8, i8 signext 42)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 128, i32* %2
br label %36
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i32 @strtol(i8* %15, i32* null, i32 16)
store i32 %16, i32* %5
store i32 0, i32* %7
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
br label %19
19: ; preds = %25, %13
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
%22 = load i8, i8* %20
store i8 %22, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 42
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = load i8, i8* %6
%27 = sext i8 %26 to i32
%28 = load i32, i32* %7
%29 = xor i32 %28, %27
store i32 %29, i32* %7
br label %19
30: ; preds = %19
%31 = load i32, i32* %7
%32 = load i32, i32* %5
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 128, i32* %2
br label %36
35: ; preds = %30
store i32 0, i32* %2
br label %36
36: ; preds = %35, %34, %12
%37 = load i32, i32* %2
ret i32 %37
}

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