#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 */
char *find_nmea_start(char *);
unsigned int nmea_checksum(char *buffer, unsigned char *checksum) {
  char *p;
  if (!buffer)
    return 1;
  if (!checksum)
    return 1;
  p = find_nmea_start(buffer);
  if (p == NULL)
    return 1;
  p++;
  *checksum = 0;
  while ((*p != 0) && (*p != '*') && !((*p == '!') || (*p == '$'))) {
    *checksum ^= *p;
    p++;
  }
  if (*p != '*')
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<nmea_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1137 <nmea_checksum+0x27>
movl   $0x1,-0x4(%rbp)
jmp    1232 <nmea_checksum+0x122>
cmpq   $0x0,-0x18(%rbp)
jne    114e <nmea_checksum+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    1232 <nmea_checksum+0x122>
mov    -0x10(%rbp),%rdi
call   1030 <find_nmea_start@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1172 <nmea_checksum+0x62>
movl   $0x1,-0x4(%rbp)
jmp    1232 <nmea_checksum+0x122>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     11dc <nmea_checksum+0xcc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2a,%ecx
mov    %al,-0x21(%rbp)
je     11dc <nmea_checksum+0xcc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x21,%ecx
mov    %al,-0x22(%rbp)
je     11d4 <nmea_checksum+0xc4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ec <nmea_checksum+0xdc>
jmp    120f <nmea_checksum+0xff>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edx
mov    -0x18(%rbp),%rax
movzbl (%rax),%ecx
xor    %edx,%ecx
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1185 <nmea_checksum+0x75>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
je     122b <nmea_checksum+0x11b>
movl   $0x1,-0x4(%rbp)
jmp    1232 <nmea_checksum+0x122>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nmea_checksum>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebp
test   %rdi,%rdi
je     1172 <nmea_checksum+0x62>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1172 <nmea_checksum+0x62>
call   1030 <find_nmea_start@plt>
test   %rax,%rax
je     1172 <nmea_checksum+0x62>
add    $0x1,%rax
xor    %ecx,%ecx
movabs $0x41200000001,%rdx
jmp    1157 <nmea_checksum+0x47>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %sil,%cl
add    $0x1,%rax
mov    %cl,(%rbx)
movzbl (%rax),%esi
cmp    $0x2a,%rsi
ja     1150 <nmea_checksum+0x40>
bt     %rsi,%rdx
jae    1150 <nmea_checksum+0x40>
xor    %ebp,%ebp
cmp    $0x2a,%sil
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @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 %19, label %6
6: ; preds = %2
%7 = tail call i8* @find_nmea_start(i8* %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %19, label %9
9: ; preds = %6, %14
%10 = phi i8 [ %15, %14 ], [ 0, %6 ]
%11 = phi i8* [ %12, %14 ], [ %7, %6 ]
store i8 %10, i8* %1
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
switch i8 %13, label %14 [
i8 0, label %16
i8 42, label %16
i8 33, label %16
i8 36, label %16
]
14: ; preds = %9
%15 = xor i8 %13, %10
br label %9
16: ; preds = %9, %9, %9, %9
%17 = icmp ne i8 %13, 42
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %16, %6, %2
%20 = phi i32 [ 1, %2 ], [ 1, %6 ], [ %18, %16 ]
ret i32 %20
}