#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 */
int nmea_valid_checksum(char const *);
int /*<<< orphan*/ *strstr(char const *, char *);
uint8_t nmea_get_message_type(const char *message) {
  uint8_t checksum = 0;
  if ((checksum = nmea_valid_checksum(message)) != 0x00) {
    return checksum;
  }
  if (strstr(message, "$GPGGA") != NULL) {
    return 0x02;
  }
  if (strstr(message, "$GPRMC") != NULL) {
    return 0x01;
  }
  return 0x00;
}


x86 assembly (clang, -O0):
<nmea_get_message_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <nmea_valid_checksum@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1153 <nmea_get_message_type+0x33>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <nmea_get_message_type+0x86>
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     1179 <nmea_get_message_type+0x59>
movl   $0x2,-0x4(%rbp)
jmp    11a6 <nmea_get_message_type+0x86>
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     119f <nmea_get_message_type+0x7f>
movl   $0x1,-0x4(%rbp)
jmp    11a6 <nmea_get_message_type+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nmea_get_message_type>:
push   %rbx
mov    %rdi,%rbx
call   1030 <nmea_valid_checksum@plt>
test   %eax,%eax
je     112f <nmea_get_message_type+0xf>
pop    %rbx
ret
lea    0xeca(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
mov    %rax,%rcx
mov    $0x2,%eax
test   %rcx,%rcx
jne    112d <nmea_get_message_type+0xd>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"$GPGGA\00"
@.str.1 = [7 x i8] c"$GPRMC\00"
define i32 @nmea_get_message_type(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%5 = load i8*, i8** %3
%6 = call i32 @nmea_valid_checksum(i8* %5)
store i32 %6, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32, i32* %4
store i32 %9, i32* %2
br label %21
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32* @strstr(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 2, i32* %2
br label %21
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = call i32* @strstr(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 1, i32* %2
br label %21
20: ; preds = %15
store i32 0, i32* %2
br label %21
21: ; preds = %20, %19, %14, %8
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [7 x i8] c"$GPGGA\00"
@.str.1 = [7 x i8] c"$GPRMC\00"
define i32 @nmea_get_message_type(i8* %0) {
%2 = tail call i32 @nmea_valid_checksum(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = tail call i32* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = tail call i32* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp ne i32* %8, null
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %7, %4, %1
%12 = phi i32 [ %2, %1 ], [ 2, %4 ], [ %10, %7 ]
ret i32 %12
}