#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 F_SEAL_GROW;
int F_SEAL_SEAL;
int F_SEAL_SHRINK;
int F_SEAL_WRITE;
int MFD_ALLOW_SEALING;
int MFD_CLOEXEC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ mfd_assert_add_seals(int, int);
int /*<<< orphan*/ mfd_assert_has_seals(int, int);
int mfd_assert_new(char *, int, int);
int /*<<< orphan*/ mfd_fail_add_seals(int, int);
void test_basic(void) {
  int fd;
  fd =
      mfd_assert_new("kern_memfd_basic", 8192, MFD_CLOEXEC | MFD_ALLOW_SEALING);
  mfd_assert_has_seals(fd, 0);
  mfd_assert_add_seals(fd, F_SEAL_SHRINK | F_SEAL_WRITE);
  mfd_assert_has_seals(fd, F_SEAL_SHRINK | F_SEAL_WRITE);
  mfd_assert_add_seals(fd, F_SEAL_SHRINK | F_SEAL_WRITE);
  mfd_assert_has_seals(fd, F_SEAL_SHRINK | F_SEAL_WRITE);
  mfd_assert_add_seals(fd, F_SEAL_GROW | F_SEAL_SEAL);
  mfd_assert_has_seals(fd, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE |
                               F_SEAL_SEAL);
  mfd_fail_add_seals(fd, F_SEAL_GROW);
  mfd_fail_add_seals(fd, 0);
  close(fd);
  fd = mfd_assert_new("kern_memfd_basic", 8192, MFD_CLOEXEC);
  mfd_assert_has_seals(fd, F_SEAL_SEAL);
  mfd_fail_add_seals(fd, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
  mfd_assert_has_seals(fd, F_SEAL_SEAL);
  close(fd);
}


x86 assembly (clang, -O0):
<test_basic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    0x2e80(%rip),%rax
or     (%rax),%edx
lea    0xe8f(%rip),%rdi
mov    $0x2000,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1040 <mfd_assert_has_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    0x2e2d(%rip),%rax
or     (%rax),%esi
call   1070 <mfd_assert_add_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
or     (%rax),%esi
call   1040 <mfd_assert_has_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    0x2df9(%rip),%rax
or     (%rax),%esi
call   1070 <mfd_assert_add_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    0x2ddf(%rip),%rax
or     (%rax),%esi
call   1040 <mfd_assert_has_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    0x2dad(%rip),%rax
or     (%rax),%esi
call   1070 <mfd_assert_add_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    0x2dc3(%rip),%rax
or     (%rax),%esi
mov    0x2da2(%rip),%rax
or     (%rax),%esi
mov    0x2d81(%rip),%rax
or     (%rax),%esi
call   1040 <mfd_assert_has_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
call   1050 <mfd_fail_add_seals@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1050 <mfd_fail_add_seals@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edx
lea    0xd97(%rip),%rdi
mov    $0x2000,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
call   1040 <mfd_assert_has_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
mov    0x2d46(%rip),%rax
or     (%rax),%esi
mov    0x2d25(%rip),%rax
or     (%rax),%esi
call   1050 <mfd_fail_add_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
call   1040 <mfd_assert_has_seals@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_basic>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5e(%rip),%rcx
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
or     (%rcx),%edx
lea    0xe8c(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2000,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1040 <mfd_assert_has_seals@plt>
mov    0x2e45(%rip),%r12
mov    0x2e2e(%rip),%r15
mov    (%r15),%esi
or     (%r12),%esi
mov    %ebp,%edi
call   1070 <mfd_assert_add_seals@plt>
mov    (%r15),%esi
or     (%r12),%esi
mov    %ebp,%edi
call   1040 <mfd_assert_has_seals@plt>
mov    (%r15),%esi
or     (%r12),%esi
mov    %ebp,%edi
call   1070 <mfd_assert_add_seals@plt>
mov    (%r15),%esi
or     (%r12),%esi
mov    %ebp,%edi
call   1040 <mfd_assert_has_seals@plt>
mov    0x2e07(%rip),%r14
mov    0x2dd0(%rip),%r13
mov    0x0(%r13),%esi
or     (%r14),%esi
mov    %ebp,%edi
call   1070 <mfd_assert_add_seals@plt>
mov    (%r14),%esi
or     (%r12),%esi
or     (%r15),%esi
or     0x0(%r13),%esi
mov    %ebp,%edi
call   1040 <mfd_assert_has_seals@plt>
mov    (%r14),%esi
mov    %ebp,%edi
call   1050 <mfd_fail_add_seals@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <mfd_fail_add_seals@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x2000,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,%ebx
mov    0x0(%r13),%esi
mov    %eax,%edi
call   1040 <mfd_assert_has_seals@plt>
mov    (%r14),%esi
or     (%r12),%esi
or     (%r15),%esi
mov    %ebx,%edi
call   1050 <mfd_fail_add_seals@plt>
mov    0x0(%r13),%esi
mov    %ebx,%edi
call   1040 <mfd_assert_has_seals@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <close@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"kern_memfd_basic\00"
@MFD_CLOEXEC = global i32 0
@MFD_ALLOW_SEALING = global i32 0
@F_SEAL_SHRINK = global i32 0
@F_SEAL_WRITE = global i32 0
@F_SEAL_GROW = global i32 0
@F_SEAL_SEAL = global i32 0
define void @test_basic() {
%1 = alloca i32
%2 = load i32, i32* @MFD_CLOEXEC
%3 = load i32, i32* @MFD_ALLOW_SEALING
%4 = or i32 %2, %3
%5 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 8192, i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = call i32 @mfd_assert_has_seals(i32 %6, i32 0)
%8 = load i32, i32* %1
%9 = load i32, i32* @F_SEAL_SHRINK
%10 = load i32, i32* @F_SEAL_WRITE
%11 = or i32 %9, %10
%12 = call i32 @mfd_assert_add_seals(i32 %8, i32 %11)
%13 = load i32, i32* %1
%14 = load i32, i32* @F_SEAL_SHRINK
%15 = load i32, i32* @F_SEAL_WRITE
%16 = or i32 %14, %15
%17 = call i32 @mfd_assert_has_seals(i32 %13, i32 %16)
%18 = load i32, i32* %1
%19 = load i32, i32* @F_SEAL_SHRINK
%20 = load i32, i32* @F_SEAL_WRITE
%21 = or i32 %19, %20
%22 = call i32 @mfd_assert_add_seals(i32 %18, i32 %21)
%23 = load i32, i32* %1
%24 = load i32, i32* @F_SEAL_SHRINK
%25 = load i32, i32* @F_SEAL_WRITE
%26 = or i32 %24, %25
%27 = call i32 @mfd_assert_has_seals(i32 %23, i32 %26)
%28 = load i32, i32* %1
%29 = load i32, i32* @F_SEAL_GROW
%30 = load i32, i32* @F_SEAL_SEAL
%31 = or i32 %29, %30
%32 = call i32 @mfd_assert_add_seals(i32 %28, i32 %31)
%33 = load i32, i32* %1
%34 = load i32, i32* @F_SEAL_SHRINK
%35 = load i32, i32* @F_SEAL_GROW
%36 = or i32 %34, %35
%37 = load i32, i32* @F_SEAL_WRITE
%38 = or i32 %36, %37
%39 = load i32, i32* @F_SEAL_SEAL
%40 = or i32 %38, %39
%41 = call i32 @mfd_assert_has_seals(i32 %33, i32 %40)
%42 = load i32, i32* %1
%43 = load i32, i32* @F_SEAL_GROW
%44 = call i32 @mfd_fail_add_seals(i32 %42, i32 %43)
%45 = load i32, i32* %1
%46 = call i32 @mfd_fail_add_seals(i32 %45, i32 0)
%47 = load i32, i32* %1
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* @MFD_CLOEXEC
%50 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 8192, i32 %49)
store i32 %50, i32* %1
%51 = load i32, i32* %1
%52 = load i32, i32* @F_SEAL_SEAL
%53 = call i32 @mfd_assert_has_seals(i32 %51, i32 %52)
%54 = load i32, i32* %1
%55 = load i32, i32* @F_SEAL_SHRINK
%56 = load i32, i32* @F_SEAL_GROW
%57 = or i32 %55, %56
%58 = load i32, i32* @F_SEAL_WRITE
%59 = or i32 %57, %58
%60 = call i32 @mfd_fail_add_seals(i32 %54, i32 %59)
%61 = load i32, i32* %1
%62 = load i32, i32* @F_SEAL_SEAL
%63 = call i32 @mfd_assert_has_seals(i32 %61, i32 %62)
%64 = load i32, i32* %1
%65 = call i32 @close(i32 %64)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"kern_memfd_basic\00"
@MFD_CLOEXEC = global i32 0
@MFD_ALLOW_SEALING = global i32 0
@F_SEAL_SHRINK = global i32 0
@F_SEAL_WRITE = global i32 0
@F_SEAL_GROW = global i32 0
@F_SEAL_SEAL = global i32 0
define void @test_basic() {
%1 = load i32, i32* @MFD_CLOEXEC
%2 = load i32, i32* @MFD_ALLOW_SEALING
%3 = or i32 %2, %1
%4 = tail call i32 @mfd_assert_new(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 8192, i32 %3)
%5 = tail call i32 @mfd_assert_has_seals(i32 %4, i32 0)
%6 = load i32, i32* @F_SEAL_SHRINK
%7 = load i32, i32* @F_SEAL_WRITE
%8 = or i32 %7, %6
%9 = tail call i32 @mfd_assert_add_seals(i32 %4, i32 %8)
%10 = load i32, i32* @F_SEAL_SHRINK
%11 = load i32, i32* @F_SEAL_WRITE
%12 = or i32 %11, %10
%13 = tail call i32 @mfd_assert_has_seals(i32 %4, i32 %12)
%14 = load i32, i32* @F_SEAL_SHRINK
%15 = load i32, i32* @F_SEAL_WRITE
%16 = or i32 %15, %14
%17 = tail call i32 @mfd_assert_add_seals(i32 %4, i32 %16)
%18 = load i32, i32* @F_SEAL_SHRINK
%19 = load i32, i32* @F_SEAL_WRITE
%20 = or i32 %19, %18
%21 = tail call i32 @mfd_assert_has_seals(i32 %4, i32 %20)
%22 = load i32, i32* @F_SEAL_GROW
%23 = load i32, i32* @F_SEAL_SEAL
%24 = or i32 %23, %22
%25 = tail call i32 @mfd_assert_add_seals(i32 %4, i32 %24)
%26 = load i32, i32* @F_SEAL_SHRINK
%27 = load i32, i32* @F_SEAL_GROW
%28 = or i32 %27, %26
%29 = load i32, i32* @F_SEAL_WRITE
%30 = or i32 %28, %29
%31 = load i32, i32* @F_SEAL_SEAL
%32 = or i32 %30, %31
%33 = tail call i32 @mfd_assert_has_seals(i32 %4, i32 %32)
%34 = load i32, i32* @F_SEAL_GROW
%35 = tail call i32 @mfd_fail_add_seals(i32 %4, i32 %34)
%36 = tail call i32 @mfd_fail_add_seals(i32 %4, i32 0)
%37 = tail call i32 @close(i32 %4)
%38 = load i32, i32* @MFD_CLOEXEC
%39 = tail call i32 @mfd_assert_new(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 8192, i32 %38)
%40 = load i32, i32* @F_SEAL_SEAL
%41 = tail call i32 @mfd_assert_has_seals(i32 %39, i32 %40)
%42 = load i32, i32* @F_SEAL_SHRINK
%43 = load i32, i32* @F_SEAL_GROW
%44 = or i32 %43, %42
%45 = load i32, i32* @F_SEAL_WRITE
%46 = or i32 %44, %45
%47 = tail call i32 @mfd_fail_add_seals(i32 %39, i32 %46)
%48 = load i32, i32* @F_SEAL_SEAL
%49 = tail call i32 @mfd_assert_has_seals(i32 %39, i32 %48)
%50 = tail call i32 @close(i32 %39)
ret void
}