#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 long __u64;

/* Variables and functions */
int /*<<< orphan*/ F_ADD_SEALS;
int /*<<< orphan*/ F_GET_SEALS;
int /*<<< orphan*/ abort();
long fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ printf(char *, int, unsigned long long, unsigned long long);
void mfd_fail_add_seals(int fd, __u64 seals) {
  long r;
  __u64 s;
  r = fcntl(fd, F_GET_SEALS);
  if (r < 0)
    s = 0;
  else
    s = r;
  r = fcntl(fd, F_ADD_SEALS, seals);
  if (r >= 0) {
    printf("ADD_SEALS(%d, %llu -> %llu) didn't fail as expected\n", fd,
           (unsigned long long)s, (unsigned long long)seals);
    abort();
  }
}


x86 assembly (clang, -O0):
<mfd_fail_add_seals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    116e <mfd_fail_add_seals+0x3e>
movq   $0x0,-0x20(%rbp)
jmp    1176 <mfd_fail_add_seals+0x46>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jl     11ba <mfd_fail_add_seals+0x8a>
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfd_fail_add_seals>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    %rax,%r14
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fcntl@plt>
test   %rax,%rax
jns    116b <mfd_fail_add_seals+0x3b>
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
test   %r14,%r14
cmovs  %rax,%r14
lea    0xe85(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
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 = [53 x i8] c"ADD_SEALS(%d, %llu -> %llu) didn't fail as expected\0A\00"
define void @mfd_fail_add_seals(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %3
store i64 %1, i64* %4
%7 = load i32, i32* %3
%8 = load i32, i32* @F_GET_SEALS
%9 = call i64 (i32, i32, ...) @fcntl(i32 %7, i32 %8)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i64 0, i64* %6
br label %15
13: ; preds = %2
%14 = load i64, i64* %5
store i64 %14, i64* %6
br label %15
15: ; preds = %13, %12
%16 = load i32, i32* %3
%17 = load i32, i32* @F_ADD_SEALS
%18 = load i64, i64* %4
%19 = call i64 (i32, i32, ...) @fcntl(i32 %16, i32 %17, i64 %18)
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = icmp sge i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %15
%23 = load i32, i32* %3
%24 = load i64, i64* %6
%25 = load i64, i64* %4
%26 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %23, i64 %24, i64 %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 = [53 x i8] c"ADD_SEALS(%d, %llu -> %llu) didn't fail as expected\0A\00"
define void @mfd_fail_add_seals(i32 %0, i64 %1) {
%3 = load i32, i32* @F_GET_SEALS
%4 = tail call i64 (i32, i32, ...) @fcntl(i32 %0, i32 %3)
%5 = load i32, i32* @F_ADD_SEALS
%6 = tail call i64 (i32, i32, ...) @fcntl(i32 %0, i32 %5, i64 %1)
%7 = icmp sgt i64 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = icmp sgt i64 %4, 0
%10 = select i1 %9, i64 %4, i64 0
%11 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %0, i64 %10, i64 %1)
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %2
ret void
}