#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef TYPE_1__ *cap_user_data_t;
typedef int /*<<< orphan*/ __u32;
struct TYPE_3__ {
  int /*<<< orphan*/ effective;
  int /*<<< orphan*/ inheritable;
  int /*<<< orphan*/ permitted;
};

/* Variables and functions */
size_t CAP_TO_INDEX(int /*<<< orphan*/);
int /*<<< orphan*/ CAP_TO_MASK(int /*<<< orphan*/);
void add_cap(cap_user_data_t data, __u32 cap) {
  data[CAP_TO_INDEX(cap)].permitted |= CAP_TO_MASK(cap);
  data[CAP_TO_INDEX(cap)].inheritable |= CAP_TO_MASK(cap);
  data[CAP_TO_INDEX(cap)].effective |= CAP_TO_MASK(cap);
}


x86 assembly (clang, -O0):
<add_cap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <CAP_TO_MASK@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <CAP_TO_INDEX@plt>
mov    -0x3c(%rbp),%ecx
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
or     0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
mov    -0xc(%rbp),%edi
call   1040 <CAP_TO_MASK@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <CAP_TO_INDEX@plt>
mov    -0x2c(%rbp),%ecx
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
or     0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%edi
call   1040 <CAP_TO_MASK@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <CAP_TO_INDEX@plt>
mov    -0x1c(%rbp),%ecx
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_cap>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1040 <CAP_TO_MASK@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <CAP_TO_INDEX@plt>
lea    (%rax,%rax,2),%rax
or     %r14d,0x8(%rbx,%rax,4)
mov    %ebp,%edi
call   1040 <CAP_TO_MASK@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <CAP_TO_INDEX@plt>
lea    (%rax,%rax,2),%rax
or     %r14d,0x4(%rbx,%rax,4)
mov    %ebp,%edi
call   1040 <CAP_TO_MASK@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <CAP_TO_INDEX@plt>
lea    (%rax,%rax,2),%rax
or     %r14d,(%rbx,%rax,4)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32, i32 }
define void @add_cap(%struct.TYPE_3__* %0, i32 %1) {
%3 = alloca %struct.TYPE_3__*
%4 = alloca i32
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = call i32 @CAP_TO_MASK(i32 %5)
%7 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%8 = load i32, i32* %4
%9 = call i64 @CAP_TO_INDEX(i32 %8)
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i64 %9
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %10, i32 0, i32 2
%12 = load i32, i32* %11
%13 = or i32 %12, %6
store i32 %13, i32* %11
%14 = load i32, i32* %4
%15 = call i32 @CAP_TO_MASK(i32 %14)
%16 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%17 = load i32, i32* %4
%18 = call i64 @CAP_TO_INDEX(i32 %17)
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i64 %18
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = or i32 %21, %15
store i32 %22, i32* %20
%23 = load i32, i32* %4
%24 = call i32 @CAP_TO_MASK(i32 %23)
%25 = load %struct.TYPE_3__*, %struct.TYPE_3__** %3
%26 = load i32, i32* %4
%27 = call i64 @CAP_TO_INDEX(i32 %26)
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i64 %27
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = or i32 %30, %24
store i32 %31, i32* %29
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32, i32 }
define void @add_cap(%struct.TYPE_3__* nocapture %0, i32 %1) {
%3 = tail call i32 @CAP_TO_MASK(i32 %1)
%4 = tail call i64 @CAP_TO_INDEX(i32 %1)
%5 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 %4, i32 2
%6 = load i32, i32* %5
%7 = or i32 %6, %3
store i32 %7, i32* %5
%8 = tail call i32 @CAP_TO_MASK(i32 %1)
%9 = tail call i64 @CAP_TO_INDEX(i32 %1)
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 %9, i32 1
%11 = load i32, i32* %10
%12 = or i32 %11, %8
store i32 %12, i32* %10
%13 = tail call i32 @CAP_TO_MASK(i32 %1)
%14 = tail call i64 @CAP_TO_INDEX(i32 %1)
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 %14, i32 0
%16 = load i32, i32* %15
%17 = or i32 %16, %13
store i32 %17, i32* %15
ret void
}