#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*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ nmea_checksum(char *, unsigned char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int test_nmea_checksum(void) {
  char buf[255];
  unsigned char checksum;
  strcpy((char *)buf, "!AIVDM,1,1,,A,15N;<J0P00Jro1<H>bAP0?vL00Rb,0*1B\n");
  if ((nmea_checksum(buf, &checksum) != 0) || (checksum != 0x1B)) {
    fprintf(stderr, "nmea_checksum() 1: Failed\n");
    return 0;
  }
  strcpy((char *)buf, "!AIVDM,1,1,,A,403OwpiuFt3Sdo=sbvK=CG7008J3,0*41");
  if ((nmea_checksum(buf, &checksum) != 0) || (checksum == 0x41)) {
    fprintf(stderr, "nmea_checksum() 2: Failed\n");
    return 0;
  }
  strcpy((char *)buf, "!AIVDM,1,1,,A,403OwpiuFt3Sdo=sbvK=CG7008J3,0*");
  if ((nmea_checksum(buf, &checksum) != 0) || (checksum == 0x41)) {
    fprintf(stderr, "nmea_checksum() 4: Failed\n");
    return 0;
  }
  fprintf(stderr, "nmea_checksum(): Passed\n");
  return 1;
}


x86 assembly (clang, -O0):
<test_nmea_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rdi
lea    0xeb7(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    -0x111(%rbp),%rsi
call   1040 <nmea_checksum@plt>
cmp    $0x0,%rax
jne    117b <test_nmea_checksum+0x4b>
movzbl -0x111(%rbp),%eax
cmp    $0x1b,%eax
je     119c <test_nmea_checksum+0x6c>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xea6(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127a <test_nmea_checksum+0x14a>
lea    -0x110(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    -0x111(%rbp),%rsi
call   1040 <nmea_checksum@plt>
cmp    $0x0,%rax
jne    11dc <test_nmea_checksum+0xac>
movzbl -0x111(%rbp),%eax
cmp    $0x41,%eax
jne    11fd <test_nmea_checksum+0xcd>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127a <test_nmea_checksum+0x14a>
lea    -0x110(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    -0x111(%rbp),%rsi
call   1040 <nmea_checksum@plt>
cmp    $0x0,%rax
jne    123d <test_nmea_checksum+0x10d>
movzbl -0x111(%rbp),%eax
cmp    $0x41,%eax
jne    125e <test_nmea_checksum+0x12e>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127a <test_nmea_checksum+0x14a>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_nmea_checksum>:
push   %rbx
sub    $0x110,%rsp
lea    0xec1(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <nmea_checksum@plt>
test   %rax,%rax
jne    11db <test_nmea_checksum+0xab>
cmpb   $0x1b,0xf(%rsp)
jne    11db <test_nmea_checksum+0xab>
lea    0xee0(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <nmea_checksum@plt>
test   %rax,%rax
jne    11ed <test_nmea_checksum+0xbd>
cmpb   $0x41,0xf(%rsp)
je     11ed <test_nmea_checksum+0xbd>
lea    0xefe(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <nmea_checksum@plt>
mov    0x2e26(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
jne    11ff <test_nmea_checksum+0xcf>
cmpb   $0x41,0xf(%rsp)
je     11ff <test_nmea_checksum+0xcf>
lea    0xf11(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    120d <test_nmea_checksum+0xdd>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
jmp    1206 <test_nmea_checksum+0xd6>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
jmp    1206 <test_nmea_checksum+0xd6>
lea    0xebf(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [49 x i8] c"!AIVDM,1,1,,A,15N;<J0P00Jro1<H>bAP0?vL00Rb,0*1B\0A\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"nmea_checksum() 1: Failed\0A\00"
@.str.2 = [48 x i8] c"!AIVDM,1,1,,A,403OwpiuFt3Sdo=sbvK=CG7008J3,0*41\00"
@.str.3 = [27 x i8] c"nmea_checksum() 2: Failed\0A\00"
@.str.4 = [46 x i8] c"!AIVDM,1,1,,A,403OwpiuFt3Sdo=sbvK=CG7008J3,0*\00"
@.str.5 = [27 x i8] c"nmea_checksum() 4: Failed\0A\00"
@.str.6 = [25 x i8] c"nmea_checksum(): Passed\0A\00"
define i32 @test_nmea_checksum() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca i8
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%7 = call i64 @nmea_checksum(i8* %6, i8* %3)
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %0
%10 = load i8, i8* %3
%11 = zext i8 %10 to i32
%12 = icmp ne i32 %11, 27
br i1 %12, label %13, label %16
13: ; preds = %9, %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %45
16: ; preds = %9
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%20 = call i64 @nmea_checksum(i8* %19, i8* %3)
%21 = icmp ne i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = load i8, i8* %3
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %24, 65
br i1 %25, label %26, label %29
26: ; preds = %22, %16
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %45
29: ; preds = %22
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%33 = call i64 @nmea_checksum(i8* %32, i8* %3)
%34 = icmp ne i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %29
%36 = load i8, i8* %3
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 65
br i1 %38, label %39, label %42
39: ; preds = %35, %29
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %45
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %45
45: ; preds = %42, %39, %26, %13
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [49 x i8] c"!AIVDM,1,1,,A,15N;<J0P00Jro1<H>bAP0?vL00Rb,0*1B\0A\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"nmea_checksum() 1: Failed\0A\00"
@.str.2 = [48 x i8] c"!AIVDM,1,1,,A,403OwpiuFt3Sdo=sbvK=CG7008J3,0*41\00"
@.str.3 = [27 x i8] c"nmea_checksum() 2: Failed\0A\00"
@.str.4 = [46 x i8] c"!AIVDM,1,1,,A,403OwpiuFt3Sdo=sbvK=CG7008J3,0*\00"
@.str.5 = [27 x i8] c"nmea_checksum() 4: Failed\0A\00"
@.str.6 = [25 x i8] c"nmea_checksum(): Passed\0A\00"
define i32 @test_nmea_checksum() {
%1 = alloca [255 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @nmea_checksum(i8* %3, i8* %2)
%6 = icmp ne i64 %5, 0
%7 = load i8, i8* %2
%8 = icmp ne i8 %7, 27
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %35
13: ; preds = %0
%14 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%15 = call i64 @nmea_checksum(i8* %3, i8* %2)
%16 = icmp ne i64 %15, 0
%17 = load i8, i8* %2
%18 = icmp eq i8 %17, 65
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %35
23: ; preds = %13
%24 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%25 = call i64 @nmea_checksum(i8* %3, i8* %2)
%26 = icmp ne i64 %25, 0
%27 = load i8, i8* %2
%28 = icmp eq i8 %27, 65
%29 = select i1 %26, i1 true, i1 %28
%30 = load i32, i32* @stderr
br i1 %29, label %31, label %33
31: ; preds = %23
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %35
33: ; preds = %23
%34 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %33, %31, %20, %10
%36 = phi i32 [ 0, %10 ], [ 0, %20 ], [ 0, %31 ], [ 1, %33 ]
ret i32 %36
}