#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 */
struct __user_cap_header_struct {
  scalar_t__ pid;
  int /*<<< orphan*/ version;
};
struct __user_cap_data_struct {
  int dummy;
};
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int _LINUX_CAPABILITY_U32S_3;
int /*<<< orphan*/ _LINUX_CAPABILITY_VERSION_3;
int capset(struct __user_cap_header_struct *, struct __user_cap_data_struct *);
int /*<<< orphan*/ memset(struct __user_cap_data_struct *, int /*<<< orphan*/,
                          int);
int dropcaps(void) {
  struct __user_cap_header_struct header;
  struct __user_cap_data_struct data[_LINUX_CAPABILITY_U32S_3];
  header.version = _LINUX_CAPABILITY_VERSION_3;
  header.pid = 0;
  memset(data, 0, sizeof(data));
  return capset(&header, data);
}


x86 assembly (clang, -O0):
<dropcaps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1030 <capset@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dropcaps>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%r14
mov    0x2ec3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    0x2e85(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0x0(,%rax,4),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    -0x20(%rbp),%rdi
mov    %rbx,%rsi
call   1030 <capset@plt>
mov    %r14,%rsp
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.__user_cap_header_struct = type { i64, i32 }
%struct.__user_cap_data_struct = type { i32 }
@_LINUX_CAPABILITY_U32S_3 = global i32 0
@_LINUX_CAPABILITY_VERSION_3 = global i32 0
define i32 @dropcaps() {
%1 = alloca %struct.__user_cap_header_struct
%2 = alloca i8*
%3 = alloca i64
%4 = load i32, i32* @_LINUX_CAPABILITY_U32S_3
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %2
%7 = alloca %struct.__user_cap_data_struct, i64 %5
store i64 %5, i64* %3
%8 = load i32, i32* @_LINUX_CAPABILITY_VERSION_3
%9 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %1, i32 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %1, i32 0, i32 0
store i64 0, i64* %10
%11 = mul nuw i64 4, %5
%12 = trunc i64 %11 to i32
%13 = call i32 @memset(%struct.__user_cap_data_struct* %7, i32 0, i32 %12)
%14 = call i32 @capset(%struct.__user_cap_header_struct* %1, %struct.__user_cap_data_struct* %7)
%15 = load i8*, i8** %2
ret i32 %14
}

LLVM IR (-O2):
%struct.__user_cap_header_struct = type { i64, i32 }
%struct.__user_cap_data_struct = type { i32 }
@_LINUX_CAPABILITY_U32S_3 = global i32 0
@_LINUX_CAPABILITY_VERSION_3 = global i32 0
define i32 @dropcaps() {
%1 = alloca %struct.__user_cap_header_struct
%2 = bitcast %struct.__user_cap_header_struct* %1 to i8*
%3 = load i32, i32* @_LINUX_CAPABILITY_U32S_3
%4 = zext i32 %3 to i64
%5 = tail call i8* @llvm.stacksave()
%6 = alloca %struct.__user_cap_data_struct, i64 %4
%7 = load i32, i32* @_LINUX_CAPABILITY_VERSION_3
%8 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %1, i64 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %1, i64 0, i32 0
store i64 0, i64* %9
%10 = shl i32 %3, 2
%11 = call i32 @memset(%struct.__user_cap_data_struct* %6, i32 0, i32 %10)
%12 = call i32 @capset(%struct.__user_cap_header_struct* %1, %struct.__user_cap_data_struct* %6)
ret i32 %12
}