#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_SHRINK;
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_assert_read(int);
int /*<<< orphan*/ mfd_assert_write(int);
int /*<<< orphan*/ mfd_fail_grow(int);
int /*<<< orphan*/ mfd_fail_grow_write(int);
int /*<<< orphan*/ mfd_fail_shrink(int);
void test_seal_resize(void) {
  int fd;
  fd = mfd_assert_new("kern_memfd_seal_resize", 8192,
                      MFD_CLOEXEC | MFD_ALLOW_SEALING);
  mfd_assert_has_seals(fd, 0);
  mfd_assert_add_seals(fd, F_SEAL_SHRINK | F_SEAL_GROW);
  mfd_assert_has_seals(fd, F_SEAL_SHRINK | F_SEAL_GROW);
  mfd_assert_read(fd);
  mfd_assert_write(fd);
  mfd_fail_shrink(fd);
  mfd_fail_grow(fd);
  mfd_fail_grow_write(fd);
  close(fd);
}


x86 assembly (clang, -O0):
<test_seal_resize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
mov    0x2e40(%rip),%rax
or     (%rax),%edx
lea    0xe4f(%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    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    0x2e05(%rip),%rax
or     (%rax),%esi
call   10b0 <mfd_assert_add_seals@plt>
mov    -0x4(%rbp),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
call   1040 <mfd_assert_has_seals@plt>
mov    -0x4(%rbp),%edi
call   10a0 <mfd_assert_read@plt>
mov    -0x4(%rbp),%edi
call   1080 <mfd_assert_write@plt>
mov    -0x4(%rbp),%edi
call   1050 <mfd_fail_shrink@plt>
mov    -0x4(%rbp),%edi
call   1070 <mfd_fail_grow@plt>
mov    -0x4(%rbp),%edi
call   1090 <mfd_fail_grow_write@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_seal_resize>:
push   %r15
push   %r14
push   %rbx
mov    0x2e2c(%rip),%rax
mov    0x2e45(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe52(%rip),%rdi
mov    $0x2000,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1040 <mfd_assert_has_seals@plt>
mov    0x2e0e(%rip),%r14
mov    0x2e0f(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
mov    %ebx,%edi
call   10b0 <mfd_assert_add_seals@plt>
mov    (%r15),%esi
or     (%r14),%esi
mov    %ebx,%edi
call   1040 <mfd_assert_has_seals@plt>
mov    %ebx,%edi
call   10a0 <mfd_assert_read@plt>
mov    %ebx,%edi
call   1080 <mfd_assert_write@plt>
mov    %ebx,%edi
call   1050 <mfd_fail_shrink@plt>
mov    %ebx,%edi
call   1070 <mfd_fail_grow@plt>
mov    %ebx,%edi
call   1090 <mfd_fail_grow_write@plt>
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <close@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"kern_memfd_seal_resize\00"
@MFD_CLOEXEC = global i32 0
@MFD_ALLOW_SEALING = global i32 0
@F_SEAL_SHRINK = global i32 0
@F_SEAL_GROW = global i32 0
define void @test_seal_resize() {
%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 ([23 x i8], [23 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_GROW
%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_GROW
%16 = or i32 %14, %15
%17 = call i32 @mfd_assert_has_seals(i32 %13, i32 %16)
%18 = load i32, i32* %1
%19 = call i32 @mfd_assert_read(i32 %18)
%20 = load i32, i32* %1
%21 = call i32 @mfd_assert_write(i32 %20)
%22 = load i32, i32* %1
%23 = call i32 @mfd_fail_shrink(i32 %22)
%24 = load i32, i32* %1
%25 = call i32 @mfd_fail_grow(i32 %24)
%26 = load i32, i32* %1
%27 = call i32 @mfd_fail_grow_write(i32 %26)
%28 = load i32, i32* %1
%29 = call i32 @close(i32 %28)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"kern_memfd_seal_resize\00"
@MFD_CLOEXEC = global i32 0
@MFD_ALLOW_SEALING = global i32 0
@F_SEAL_SHRINK = global i32 0
@F_SEAL_GROW = global i32 0
define void @test_seal_resize() {
%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 ([23 x i8], [23 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_GROW
%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_GROW
%12 = or i32 %11, %10
%13 = tail call i32 @mfd_assert_has_seals(i32 %4, i32 %12)
%14 = tail call i32 @mfd_assert_read(i32 %4)
%15 = tail call i32 @mfd_assert_write(i32 %4)
%16 = tail call i32 @mfd_fail_shrink(i32 %4)
%17 = tail call i32 @mfd_fail_grow(i32 %4)
%18 = tail call i32 @mfd_fail_grow_write(i32 %4)
%19 = tail call i32 @close(i32 %4)
ret void
}