#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*/ evaluate_test(int /*<<< orphan*/, char *);
scalar_t__ ksft_get_fail_cnt();
int /*<<< orphan*/ ksft_print_cnts();
int /*<<< orphan*/ ksft_set_plan(int);
int mte_default_setup();
int /*<<< orphan*/ mte_gcr_fork_test();
int /*<<< orphan*/ mte_restore_setup();
int main(int argc, char *argv[]) {
  int err;
  err = mte_default_setup();
  if (err)
    return err;
  ksft_set_plan(1);
  evaluate_test(mte_gcr_fork_test(),
                "Verify that GCR_EL1 is set correctly on context switch\n");
  mte_restore_setup();
  ksft_print_cnts();
  return ksft_get_fail_cnt() == 0 ? 0 : 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <mte_default_setup@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a5 <main+0x35>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ed <main+0x7d>
mov    $0x1,%edi
call   1050 <ksft_set_plan@plt>
mov    $0x0,%al
call   1040 <mte_gcr_fork_test@plt>
mov    %eax,%edi
lea    0xe41(%rip),%rsi
call   1030 <evaluate_test@plt>
mov    $0x0,%al
call   1080 <mte_restore_setup@plt>
mov    $0x0,%al
call   1090 <ksft_print_cnts@plt>
mov    $0x0,%al
call   1060 <ksft_get_fail_cnt@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <mte_default_setup@plt>
test   %eax,%eax
je     117e <main+0xe>
pop    %rcx
ret
mov    $0x1,%edi
call   1050 <ksft_set_plan@plt>
xor    %eax,%eax
call   1040 <mte_gcr_fork_test@plt>
lea    0xe6a(%rip),%rsi
mov    %eax,%edi
call   1030 <evaluate_test@plt>
xor    %eax,%eax
call   1080 <mte_restore_setup@plt>
xor    %eax,%eax
call   1090 <ksft_print_cnts@plt>
xor    %eax,%eax
call   1060 <ksft_get_fail_cnt@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
pop    %rcx
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Verify that GCR_EL1 is set correctly on context switch\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @mte_default_setup()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* %6
store i32 %11, i32* %3
br label %22
12: ; preds = %2
%13 = call i32 @ksft_set_plan(i32 1)
%14 = call i32 (...) @mte_gcr_fork_test()
%15 = call i32 @evaluate_test(i32 %14, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @mte_restore_setup()
%17 = call i32 (...) @ksft_print_cnts()
%18 = call i64 (...) @ksft_get_fail_cnt()
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 0, i32 1
store i32 %21, i32* %3
br label %22
22: ; preds = %12, %10
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [56 x i8] c"Verify that GCR_EL1 is set correctly on context switch\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @mte_default_setup()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i32 @ksft_set_plan(i32 1)
%7 = tail call i32 (...) @mte_gcr_fork_test()
%8 = tail call i32 @evaluate_test(i32 %7, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 (...) @mte_restore_setup()
%10 = tail call i32 (...) @ksft_print_cnts()
%11 = tail call i64 (...) @ksft_get_fail_cnt()
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %2, %5
%15 = phi i32 [ %13, %5 ], [ %3, %2 ]
ret i32 %15
}