#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*/ ksft_print_msg(char *, ...);
int /*<<< orphan*/ mte_free_memory_tag_range(void *, size_t, int, size_t,
                                             size_t);
int check_allocated_memory_range(void *ptr, size_t size, int mem_type,
                                 size_t range_before, size_t range_after) {
  if (ptr == NULL) {
    ksft_print_msg("FAIL: memory allocation\n");
    return 1;
  }
  if (!(((uintptr_t)ptr >> 56) & (0xFUL))) {
    ksft_print_msg("FAIL: tag not found at addr(%p)\n", ptr);
    mte_free_memory_tag_range((void *)ptr, size, mem_type, range_before,
                              range_after);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_allocated_memory_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1160 <check_allocated_memory_range+0x40>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <check_allocated_memory_range+0x93>
mov    -0x10(%rbp),%rax
shr    $0x38,%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11ac <check_allocated_memory_range+0x8c>
mov    -0x10(%rbp),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <ksft_print_msg@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1030 <mte_free_memory_tag_range@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b3 <check_allocated_memory_range+0x93>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_allocated_memory_range>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1174 <check_allocated_memory_range+0x54>
mov    %rcx,%r15
mov    %rdi,%rbp
xor    %eax,%eax
movabs $0xf00000000000000,%rcx
test   %rcx,%rdi
jne    1187 <check_allocated_memory_range+0x67>
mov    %r8,%r14
mov    %edx,%r12d
mov    %rsi,%rbx
lea    0xec5(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <ksft_print_msg@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <mte_free_memory_tag_range@plt>
jmp    1182 <check_allocated_memory_range+0x62>
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1040 <ksft_print_msg@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"FAIL: memory allocation\0A\00"
@.str.1 = [33 x i8] c"FAIL: tag not found at addr(%p)\0A\00"
define i32 @check_allocated_memory_range(i8* %0, i64 %1, i32 %2, i64 %3, i64 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %7
store i64 %1, i64* %8
store i32 %2, i32* %9
store i64 %3, i64* %10
store i64 %4, i64* %11
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %32
16: ; preds = %5
%17 = load i8*, i8** %7
%18 = ptrtoint i8* %17 to i64
%19 = lshr i64 %18, 56
%20 = and i64 %19, 15
%21 = icmp ne i64 %20, 0
br i1 %21, label %31, label %22
22: ; preds = %16
%23 = load i8*, i8** %7
%24 = call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %7
%26 = load i64, i64* %8
%27 = load i32, i32* %9
%28 = load i64, i64* %10
%29 = load i64, i64* %11
%30 = call i32 @mte_free_memory_tag_range(i8* %25, i64 %26, i32 %27, i64 %28, i64 %29)
store i32 1, i32* %6
br label %32
31: ; preds = %16
store i32 0, i32* %6
br label %32
32: ; preds = %31, %22, %14
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
@.str = [25 x i8] c"FAIL: memory allocation\0A\00"
@.str.1 = [33 x i8] c"FAIL: tag not found at addr(%p)\0A\00"
define i32 @check_allocated_memory_range(i8* %0, i64 %1, i32 %2, i64 %3, i64 %4) {
%6 = icmp eq i8* %0, null
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %16
9: ; preds = %5
%10 = ptrtoint i8* %0 to i64
%11 = and i64 %10, 1080863910568919040
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 (i8*, ...) @ksft_print_msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%15 = tail call i32 @mte_free_memory_tag_range(i8* %0, i64 %1, i32 %2, i64 %3, i64 %4)
br label %16
16: ; preds = %9, %13, %7
%17 = phi i32 [ 1, %7 ], [ 1, %13 ], [ 0, %9 ]
ret i32 %17
}