#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*/ F_ADD_SEALS;
int /*<<< orphan*/ F_GET_SEALS;
int /*<<< orphan*/ abort();
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ printf(char *, int, unsigned int, unsigned int);
void mfd_fail_add_seals(int fd, unsigned int seals) {
  int r;
  unsigned int s;
  r = fcntl(fd, F_GET_SEALS);
  if (r < 0) {
    s = 0;
  } else {
    s = (unsigned int)r;
  }
  r = fcntl(fd, F_ADD_SEALS, seals);
  if (r >= 0) {
    printf("ADD_SEALS(%d, %u -> %u) didn't fail as expected\n", fd, s, seals);
    abort();
  }
}


x86 assembly (clang, -O0):
<mfd_fail_add_seals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    116a <mfd_fail_add_seals+0x3a>
movl   $0x0,-0x10(%rbp)
jmp    1170 <mfd_fail_add_seals+0x40>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11af <mfd_fail_add_seals+0x7f>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfd_fail_add_seals>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    %eax,%r14d
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
test   %eax,%eax
jns    1174 <mfd_fail_add_seals+0x44>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r14d,%r14d
cmovs  %r15d,%r14d
lea    0xe7e(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %ebx,%ecx
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@F_GET_SEALS = global i32 0
@F_ADD_SEALS = global i32 0
@.str = [49 x i8] c"ADD_SEALS(%d, %u -> %u) didn't fail as expected\0A\00"
define void @mfd_fail_add_seals(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* @F_GET_SEALS
%9 = call i32 (i32, i32, ...) @fcntl(i32 %7, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %6
br label %15
13: ; preds = %2
%14 = load i32, i32* %5
store i32 %14, i32* %6
br label %15
15: ; preds = %13, %12
%16 = load i32, i32* %3
%17 = load i32, i32* @F_ADD_SEALS
%18 = load i32, i32* %4
%19 = call i32 (i32, i32, ...) @fcntl(i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* %3
%24 = load i32, i32* %6
%25 = load i32, i32* %4
%26 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24, i32 %25)
%27 = call i32 (...) @abort()
unreachable
28: ; preds = %15
ret void
}

LLVM IR (-O2):
@F_GET_SEALS = global i32 0
@F_ADD_SEALS = global i32 0
@.str = [49 x i8] c"ADD_SEALS(%d, %u -> %u) didn't fail as expected\0A\00"
define void @mfd_fail_add_seals(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GET_SEALS
%4 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %3)
%5 = load i32, i32* @F_ADD_SEALS
%6 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %5, i32 %1)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = icmp sgt i32 %4, 0
%10 = select i1 %9, i32 %4, i32 0
%11 = tail call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %10, i32 %1)
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %2
ret void
}