#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int MFD_ALLOW_SEALING;
int MFD_CLOEXEC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int, int);
int mfd_assert_new(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mfd_fail_new(char *, int);
void test_create(void) {
  char buf[2048];
  int fd;
  mfd_fail_new(NULL, 0);
  memset(buf, 0xff, sizeof(buf));
  mfd_fail_new(buf, 0);
  memset(buf, 0xff, sizeof(buf));
  buf[sizeof(buf) - 1] = 0;
  mfd_fail_new(buf, 0);
  fd = mfd_assert_new("", 0, 0);
  close(fd);
  mfd_fail_new("", 0x0100);
  mfd_fail_new("", ~MFD_CLOEXEC);
  mfd_fail_new("", ~MFD_ALLOW_SEALING);
  mfd_fail_new("", ~0);
  mfd_fail_new("", 0x80000000U);
  fd = mfd_assert_new("", 0, MFD_CLOEXEC);
  close(fd);
  fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING);
  close(fd);
  fd = mfd_assert_new("", 0, MFD_ALLOW_SEALING | MFD_CLOEXEC);
  close(fd);
}


x86 assembly (clang, -O0):
<test_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1060 <mfd_fail_new@plt>
lea    -0x800(%rbp),%rdi
mov    $0xff,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
lea    -0x800(%rbp),%rdi
xor    %esi,%esi
call   1060 <mfd_fail_new@plt>
lea    -0x800(%rbp),%rdi
mov    $0xff,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
movb   $0x0,-0x1(%rbp)
lea    -0x800(%rbp),%rdi
xor    %esi,%esi
call   1060 <mfd_fail_new@plt>
lea    0xe57(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,-0x804(%rbp)
mov    -0x804(%rbp),%edi
call   1050 <close@plt>
lea    0xe36(%rip),%rdi
mov    $0x100,%esi
call   1060 <mfd_fail_new@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
xor    $0xffffffff,%esi
lea    0xe19(%rip),%rdi
call   1060 <mfd_fail_new@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
xor    $0xffffffff,%esi
lea    0xe01(%rip),%rdi
call   1060 <mfd_fail_new@plt>
lea    0xdf5(%rip),%rdi
mov    $0xffffffff,%esi
call   1060 <mfd_fail_new@plt>
lea    0xde4(%rip),%rdi
mov    $0x80000000,%esi
call   1060 <mfd_fail_new@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
lea    0xdca(%rip),%rdi
xor    %esi,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,-0x804(%rbp)
mov    -0x804(%rbp),%edi
call   1050 <close@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
lea    0xda2(%rip),%rdi
xor    %esi,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,-0x804(%rbp)
mov    -0x804(%rbp),%edi
call   1050 <close@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
mov    0x2d52(%rip),%rax
or     (%rax),%edx
lea    0xd71(%rip),%rdi
xor    %esi,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,-0x804(%rbp)
mov    -0x804(%rbp),%edi
call   1050 <close@plt>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_create>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
xor    %edi,%edi
xor    %esi,%esi
call   1060 <mfd_fail_new@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <mfd_fail_new@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
movb   $0x0,0x7ff(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <mfd_fail_new@plt>
lea    0xe61(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <mfd_assert_new@plt>
mov    %eax,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   1060 <mfd_fail_new@plt>
mov    0x2e12(%rip),%r14
mov    (%r14),%esi
not    %esi
mov    %rbx,%rdi
call   1060 <mfd_fail_new@plt>
mov    0x2e0e(%rip),%r15
mov    (%r15),%esi
not    %esi
mov    %rbx,%rdi
call   1060 <mfd_fail_new@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1060 <mfd_fail_new@plt>
mov    %rbx,%rdi
mov    $0x80000000,%esi
call   1060 <mfd_fail_new@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,%edi
call   1050 <close@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,%edi
call   1050 <close@plt>
mov    (%r14),%edx
or     (%r15),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <mfd_assert_new@plt>
mov    %eax,%edi
call   1050 <close@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@MFD_CLOEXEC = global i32 0
@MFD_ALLOW_SEALING = global i32 0
define void @test_create() {
%1 = alloca [2048 x i8]
%2 = alloca i32
%3 = call i32 @mfd_fail_new(i8* null, i32 0)
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 255, i32 2048)
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%7 = call i32 @mfd_fail_new(i8* %6, i32 0)
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 255, i32 2048)
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 2047
store i8 0, i8* %10
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%12 = call i32 @mfd_fail_new(i8* %11, i32 0)
%13 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 256)
%17 = load i32, i32* @MFD_CLOEXEC
%18 = xor i32 %17, -1
%19 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @MFD_ALLOW_SEALING
%21 = xor i32 %20, -1
%22 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -1)
%24 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -2147483648)
%25 = load i32, i32* @MFD_CLOEXEC
%26 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 %25)
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* @MFD_ALLOW_SEALING
%30 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 %29)
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* @MFD_ALLOW_SEALING
%34 = load i32, i32* @MFD_CLOEXEC
%35 = or i32 %33, %34
%36 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 %35)
store i32 %36, i32* %2
%37 = load i32, i32* %2
%38 = call i32 @close(i32 %37)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@MFD_CLOEXEC = global i32 0
@MFD_ALLOW_SEALING = global i32 0
define void @test_create() {
%1 = alloca [2048 x i8]
%2 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @mfd_fail_new(i8* null, i32 0)
%4 = call i32 @memset(i8* %2, i32 255, i32 2048)
%5 = call i32 @mfd_fail_new(i8* %2, i32 0)
%6 = call i32 @memset(i8* %2, i32 255, i32 2048)
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 2047
store i8 0, i8* %7
%8 = call i32 @mfd_fail_new(i8* %2, i32 0)
%9 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%10 = call i32 @close(i32 %9)
%11 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 256)
%12 = load i32, i32* @MFD_CLOEXEC
%13 = xor i32 %12, -1
%14 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @MFD_ALLOW_SEALING
%16 = xor i32 %15, -1
%17 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -1)
%19 = call i32 @mfd_fail_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -2147483648)
%20 = load i32, i32* @MFD_CLOEXEC
%21 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 %20)
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* @MFD_ALLOW_SEALING
%24 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 %23)
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* @MFD_ALLOW_SEALING
%27 = load i32, i32* @MFD_CLOEXEC
%28 = or i32 %27, %26
%29 = call i32 @mfd_assert_new(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0, i32 %28)
%30 = call i32 @close(i32 %29)
ret void
}