#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 */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
void nmea_add_checksum(char *sentence) {
  unsigned char sum = '\0';
  char c, *p = sentence;
  if (*p == '$') {
    p++;
  } else {
  }
  while (((c = *p) != '*') && (c != '\0')) {
    sum ^= c;
    p++;
  }
  *p++ = '*';
  (void)snprintf(p, 5, "%02X\r\n", (unsigned)sum);
}


x86 assembly (clang, -O0):
<nmea_add_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    1149 <nmea_add_checksum+0x39>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114e <nmea_add_checksum+0x3e>
jmp    114e <nmea_add_checksum+0x3e>
jmp    1153 <nmea_add_checksum+0x43>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xa(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x2a,%ecx
mov    %al,-0x19(%rbp)
je     117a <nmea_add_checksum+0x6a>
movsbl -0xa(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118a <nmea_add_checksum+0x7a>
jmp    11a8 <nmea_add_checksum+0x98>
movsbl -0xa(%rbp),%ecx
movzbl -0x9(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1153 <nmea_add_checksum+0x43>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2a,(%rax)
mov    -0x18(%rbp),%rdi
movzbl -0x9(%rbp),%ecx
mov    $0x5,%esi
lea    0xe32(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nmea_add_checksum>:
xor    %eax,%eax
cmpb   $0x24,(%rdi)
sete   %al
add    %rax,%rdi
add    $0x1,%rdi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rdi),%eax
test   %eax,%eax
je     1144 <nmea_add_checksum+0x34>
cmp    $0x2a,%al
je     1144 <nmea_add_checksum+0x34>
xor    %eax,%ecx
add    $0x1,%rdi
jmp    1130 <nmea_add_checksum+0x20>
movb   $0x2a,-0x1(%rdi)
lea    0xeb1(%rip),%rdx
mov    $0x5,%esi
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%02X\0D\0A\00"
define void @nmea_add_checksum(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8*
store i8* %0, i8** %2
store i8 0, i8* %3
%6 = load i8*, i8** %2
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 36
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
br label %15
14: ; preds = %1
br label %15
15: ; preds = %14, %11
br label %16
16: ; preds = %27, %15
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
store i8 %18, i8* %4
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 42
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br label %25
25: ; preds = %21, %16
%26 = phi i1 [ false, %16 ], [ %24, %21 ]
br i1 %26, label %27, label %36
27: ; preds = %25
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = load i8, i8* %3
%31 = zext i8 %30 to i32
%32 = xor i32 %31, %29
%33 = trunc i32 %32 to i8
store i8 %33, i8* %3
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
br label %16
36: ; preds = %25
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
store i8 42, i8* %37
%39 = load i8*, i8** %5
%40 = load i8, i8* %3
%41 = zext i8 %40 to i32
%42 = call i32 @snprintf(i8* %39, i32 5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %41)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%02X\0D\0A\00"
define void @nmea_add_checksum(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 36
%4 = zext i1 %3 to i64
%5 = getelementptr i8, i8* %0, i64 %4
br label %6
6: ; preds = %10, %1
%7 = phi i32 [ 0, %1 ], [ %12, %10 ]
%8 = phi i8* [ %5, %1 ], [ %13, %10 ]
%9 = load i8, i8* %8
switch i8 %9, label %10 [
i8 42, label %14
i8 0, label %14
]
10: ; preds = %6
%11 = zext i8 %9 to i32
%12 = xor i32 %7, %11
%13 = getelementptr inbounds i8, i8* %8, i64 1
br label %6
14: ; preds = %6, %6
%15 = getelementptr inbounds i8, i8* %8, i64 1
store i8 42, i8* %8
%16 = tail call i32 @snprintf(i8* %15, i32 5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7)
ret void
}