#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 */
scalar_t__ EINVAL;
int /*<<< orphan*/ PR_CAPBSET_DROP;
int /*<<< orphan*/ PR_SET_NO_NEW_PRIVS;
scalar_t__ errno;
int prctl(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/,
          int /*<<< orphan*/);
int dropcaps() {
  unsigned long cap;
  int code;
  for (cap = 0; cap <= 63; cap++) {
    code = prctl(PR_CAPBSET_DROP, cap, 0, 0, 0);
    if (code == -1 && errno != EINVAL) {
      return -1;
    }
  }
  if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<dropcaps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
cmpq   $0x3f,-0x10(%rbp)
ja     1191 <dropcaps+0x81>
mov    0x2eae(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    %eax,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <prctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117b <dropcaps+0x6b>
mov    0x2e7c(%rip),%rax
mov    (%rax),%rax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
je     117b <dropcaps+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <dropcaps+0xb9>
jmp    1180 <dropcaps+0x70>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <dropcaps+0x10>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <prctl@plt>
cmp    $0xffffffff,%eax
jne    11c2 <dropcaps+0xb2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <dropcaps+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dropcaps>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    0x2ebf(%rip),%r14
mov    0x2eb0(%rip),%r15
mov    0x2e99(%rip),%r12
jmp    114a <dropcaps+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x40,%rbx
je     1170 <dropcaps+0x60>
mov    (%r14),%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <prctl@plt>
cmp    $0xffffffff,%eax
jne    1140 <dropcaps+0x30>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1140 <dropcaps+0x30>
mov    $0xffffffff,%eax
jmp    1196 <dropcaps+0x86>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <prctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PR_CAPBSET_DROP = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@PR_SET_NO_NEW_PRIVS = global i32 0
define i32 @dropcaps() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i64 0, i64* %2
br label %4
4: ; preds = %20, %0
%5 = load i64, i64* %2
%6 = icmp ule i64 %5, 63
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = load i32, i32* @PR_CAPBSET_DROP
%9 = load i64, i64* %2
%10 = trunc i64 %9 to i32
%11 = call i32 @prctl(i32 %8, i32 %10, i32 0, i32 0, i32 0)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %7
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINVAL
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -1, i32* %1
br label %29
19: ; preds = %14, %7
br label %20
20: ; preds = %19
%21 = load i64, i64* %2
%22 = add i64 %21, 1
store i64 %22, i64* %2
br label %4
23: ; preds = %4
%24 = load i32, i32* @PR_SET_NO_NEW_PRIVS
%25 = call i32 @prctl(i32 %24, i32 1, i32 0, i32 0, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %1
br label %29
28: ; preds = %23
store i32 0, i32* %1
br label %29
29: ; preds = %28, %27, %18
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@PR_CAPBSET_DROP = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@PR_SET_NO_NEW_PRIVS = global i32 0
define i32 @dropcaps() {
br label %1
1: ; preds = %0, %11
%2 = phi i64 [ 0, %0 ], [ %12, %11 ]
%3 = load i32, i32* @PR_CAPBSET_DROP
%4 = trunc i64 %2 to i32
%5 = tail call i32 @prctl(i32 %3, i32 %4, i32 0, i32 0, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINVAL
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %1, %7
%12 = add nuw nsw i64 %2, 1
%13 = icmp eq i64 %12, 64
br i1 %13, label %14, label %1
14: ; preds = %11
%15 = load i32, i32* @PR_SET_NO_NEW_PRIVS
%16 = tail call i32 @prctl(i32 %15, i32 1, i32 0, i32 0, i32 0)
%17 = icmp eq i32 %16, -1
%18 = sext i1 %17 to i32
br label %19
19: ; preds = %7, %14
%20 = phi i32 [ %18, %14 ], [ -1, %7 ]
ret i32 %20
}