#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 */
unsigned char CalculateNmeaCheckSum(char *);
int /*<<< orphan*/ NMEAAddField(char *, int *, char *);
void NMEAAddCheckSum(char *TransmitBuffer, int *TXBufferIndex) {
  unsigned char CheckSum;
  unsigned char TXCheckSum;
  char TempBuf[10];
  NMEAAddField(TransmitBuffer, TXBufferIndex, "*");
  CheckSum = CalculateNmeaCheckSum(TransmitBuffer);
  TXCheckSum = CheckSum & 0xf0;
  TempBuf[0] = (TXCheckSum >> 4) + '0';
  TempBuf[1] = '\0';
  if (TempBuf[0] > '9') {
    TempBuf[0] += 'A' - ('9' + 1);
    TempBuf[1] = '\0';
  }
  NMEAAddField(TransmitBuffer, TXBufferIndex, TempBuf);
  TXCheckSum = CheckSum & 0x0f;
  TempBuf[0] = (TXCheckSum & 0xf) + '0';
  TempBuf[1] = '\0';
  if (TempBuf[0] > '9') {
    TempBuf[0] += 'A' - ('9' + 1);
    TempBuf[1] = '\0';
  }
  NMEAAddField(TransmitBuffer, TXBufferIndex, TempBuf);
}


x86 assembly (clang, -O0):
<NMEAAddCheckSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xec1(%rip),%rdx
call   1030 <NMEAAddField@plt>
mov    -0x8(%rbp),%rdi
call   1040 <CalculateNmeaCheckSum@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
and    $0xf0,%eax
mov    %al,-0x12(%rbp)
movzbl -0x12(%rbp),%eax
sar    $0x4,%eax
add    $0x30,%eax
mov    %al,-0x1c(%rbp)
movb   $0x0,-0x1b(%rbp)
movsbl -0x1c(%rbp),%eax
cmp    $0x39,%eax
jle    1188 <NMEAAddCheckSum+0x68>
movsbl -0x1c(%rbp),%eax
add    $0x7,%eax
mov    %al,-0x1c(%rbp)
movb   $0x0,-0x1b(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <NMEAAddField@plt>
movzbl -0x11(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x12(%rbp)
movzbl -0x12(%rbp),%eax
and    $0xf,%eax
add    $0x30,%eax
mov    %al,-0x1c(%rbp)
movb   $0x0,-0x1b(%rbp)
movsbl -0x1c(%rbp),%eax
cmp    $0x39,%eax
jle    11cf <NMEAAddCheckSum+0xaf>
movsbl -0x1c(%rbp),%eax
add    $0x7,%eax
mov    %al,-0x1c(%rbp)
movb   $0x0,-0x1b(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <NMEAAddField@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NMEAAddCheckSum>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeca(%rip),%rdx
call   1030 <NMEAAddField@plt>
mov    %r15,%rdi
call   1040 <CalculateNmeaCheckSum@plt>
mov    %eax,%ebx
shr    $0x4,%al
lea    0x30(%rax),%ecx
mov    %cl,0x6(%rsp)
movb   $0x0,0x7(%rsp)
cmp    $0x3a,%cl
jb     115f <NMEAAddCheckSum+0x3f>
add    $0x37,%al
mov    %al,0x6(%rsp)
lea    0x6(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <NMEAAddField@plt>
and    $0xf,%bl
lea    0x30(%rbx),%eax
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
cmp    $0x3a,%al
jb     1189 <NMEAAddCheckSum+0x69>
add    $0x37,%bl
mov    %bl,0x6(%rsp)
lea    0x6(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <NMEAAddField@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"*\00"
define void @NMEAAddCheckSum(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i8
%7 = alloca [10 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = load i32*, i32** %4
%10 = call i32 @NMEAAddField(i8* %8, i32* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %3
%12 = call zeroext i8 @CalculateNmeaCheckSum(i8* %11)
store i8 %12, i8* %5
%13 = load i8, i8* %5
%14 = zext i8 %13 to i32
%15 = and i32 %14, 240
%16 = trunc i32 %15 to i8
store i8 %16, i8* %6
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
%19 = ashr i32 %18, 4
%20 = add nsw i32 %19, 48
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
store i8 %21, i8* %22
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 1
store i8 0, i8* %23
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp sgt i32 %26, 57
br i1 %27, label %28, label %35
28: ; preds = %2
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = add nsw i32 %31, 7
%33 = trunc i32 %32 to i8
store i8 %33, i8* %29
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 1
store i8 0, i8* %34
br label %35
35: ; preds = %28, %2
%36 = load i8*, i8** %3
%37 = load i32*, i32** %4
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%39 = call i32 @NMEAAddField(i8* %36, i32* %37, i8* %38)
%40 = load i8, i8* %5
%41 = zext i8 %40 to i32
%42 = and i32 %41, 15
%43 = trunc i32 %42 to i8
store i8 %43, i8* %6
%44 = load i8, i8* %6
%45 = zext i8 %44 to i32
%46 = and i32 %45, 15
%47 = add nsw i32 %46, 48
%48 = trunc i32 %47 to i8
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
store i8 %48, i8* %49
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 1
store i8 0, i8* %50
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp sgt i32 %53, 57
br i1 %54, label %55, label %62
55: ; preds = %35
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = add nsw i32 %58, 7
%60 = trunc i32 %59 to i8
store i8 %60, i8* %56
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 1
store i8 0, i8* %61
br label %62
62: ; preds = %55, %35
%63 = load i8*, i8** %3
%64 = load i32*, i32** %4
%65 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%66 = call i32 @NMEAAddField(i8* %63, i32* %64, i8* %65)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"*\00"
define void @NMEAAddCheckSum(i8* %0, i32* %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @NMEAAddField(i8* %0, i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call zeroext i8 @CalculateNmeaCheckSum(i8* %0)
%7 = lshr i8 %6, 4
%8 = or i8 %7, 48
store i8 %8, i8* %4
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
store i8 0, i8* %9
%10 = icmp ugt i8 %8, 57
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = add nuw nsw i8 %7, 55
store i8 %12, i8* %4
br label %13
13: ; preds = %11, %2
%14 = call i32 @NMEAAddField(i8* %0, i32* %1, i8* %4)
%15 = and i8 %6, 15
%16 = or i8 %15, 48
store i8 %16, i8* %4
store i8 0, i8* %9
%17 = icmp ugt i8 %16, 57
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = add nuw nsw i8 %15, 55
store i8 %19, i8* %4
br label %20
20: ; preds = %18, %13
%21 = call i32 @NMEAAddField(i8* %0, i32* %1, i8* %4)
ret void
}