#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*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ sscanf(char const *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char const *);
void check_version(const char *header) {
  assert(header != NULL && strlen(header) > 0);
  int version;
  if (sscanf(header, "%d", &version) == 0) {
    fprintf(stderr, "Malformed navigation data header:\n%s\n", header);
    exit(EXIT_FAILURE);
  }
  if (version != 810) {
    fprintf(stderr, "Unsupported navigation data version %d\n", version);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<check_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0xd(%rbp)
je     117f <check_version+0x2f>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x0,%rax
jne    11d3 <check_version+0x83>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x32a,-0xc(%rbp)
je     1208 <check_version+0xb8>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_version>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
test   %rdi,%rdi
je     1170 <check_version+0x20>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
test   %rax,%rax
setg   %dil
jmp    1172 <check_version+0x22>
xor    %edi,%edi
call   1040 <assert@plt>
lea    0xe82(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
test   %rax,%rax
je     11a2 <check_version+0x52>
mov    0xc(%rsp),%edx
cmp    $0x32a,%edx
jne    11be <check_version+0x6e>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11d5 <check_version+0x85>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"Malformed navigation data header:\0A%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [40 x i8] c"Unsupported navigation data version %d\0A\00"
define void @check_version(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = icmp sgt i64 %8, 0
br label %10
10: ; preds = %6, %1
%11 = phi i1 [ false, %1 ], [ %9, %6 ]
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %2
%15 = call i64 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %10
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 810
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i32, i32* %3
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"Malformed navigation data header:\0A%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [40 x i8] c"Unsupported navigation data version %d\0A\00"
define void @check_version(i8* %0) {
%2 = alloca i32
%3 = icmp eq i8* %0, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i64 @strlen(i8* %0)
%6 = icmp sgt i64 %5, 0
%7 = zext i1 %6 to i32
br label %8
8: ; preds = %4, %1
%9 = phi i32 [ 0, %1 ], [ %7, %4 ]
%10 = tail call i32 @assert(i32 %9)
%11 = bitcast i32* %2 to i8*
%12 = call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %8
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 810
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
ret void
}