#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 effective;
  int permitted;
  int inheritable;
};

/* Variables and functions */
int /*<<< orphan*/ _LINUX_CAPABILITY_VERSION;
int /*<<< orphan*/ __NR_capget;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int syscall(int /*<<< orphan*/, struct __user_cap_header_struct *,
            struct __user_cap_data_struct *);
int main() {
  struct __user_cap_header_struct h;
  struct __user_cap_data_struct d;
  int syscall_result;
  h.version = _LINUX_CAPABILITY_VERSION;
  h.pid = 0;
  syscall_result = syscall(__NR_capget, &h, &d);
  if (syscall_result >= 0) {
    fprintf(stderr,
            "capget result:\n"
            "effective   %#x\n"
            "permitted   %#x\n"
            "inheritable %#x\n",
            d.effective, d.permitted, d.inheritable);
  } else {
    perror("capget");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <syscall@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     119a <main+0x6a>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe70(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11a6 <main+0x76>
lea    0xe9f(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <syscall@plt>
test   %eax,%eax
js     118f <main+0x5f>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
lea    0xe7d(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret
lea    0xeaa(%rip),%rdi
call   1050 <perror@plt>
jmp    1188 <main+0x58>

LLVM IR (-O0):
%struct.__user_cap_header_struct = type { i64, i32 }
%struct.__user_cap_data_struct = type { i32, i32, i32 }
@_LINUX_CAPABILITY_VERSION = global i32 0
@__NR_capget = global i32 0
@stderr = global i32 0
@.str = [64 x i8] c"capget result:\0Aeffective %#x\0Apermitted %#x\0Ainheritable %#x\0A\00"
@.str.1 = [7 x i8] c"capget\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.__user_cap_header_struct
%3 = alloca %struct.__user_cap_data_struct
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @_LINUX_CAPABILITY_VERSION
%6 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %2, i32 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %2, i32 0, i32 0
store i64 0, i64* %7
%8 = load i32, i32* @__NR_capget
%9 = call i32 @syscall(i32 %8, %struct.__user_cap_header_struct* %2, %struct.__user_cap_data_struct* %3)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %3, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %3, i32 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %3, i32 0, i32 2
%19 = load i32, i32* %18
%20 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %17, i32 %19)
br label %23
21: ; preds = %0
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %12
ret i32 0
}

LLVM IR (-O2):
%struct.__user_cap_header_struct = type { i64, i32 }
%struct.__user_cap_data_struct = type { i32, i32, i32 }
@_LINUX_CAPABILITY_VERSION = global i32 0
@__NR_capget = global i32 0
@stderr = global i32 0
@.str = [64 x i8] c"capget result:\0Aeffective %#x\0Apermitted %#x\0Ainheritable %#x\0A\00"
@.str.1 = [7 x i8] c"capget\00"
define i32 @main() {
%1 = alloca %struct.__user_cap_header_struct
%2 = alloca %struct.__user_cap_data_struct
%3 = bitcast %struct.__user_cap_header_struct* %1 to i8*
%4 = bitcast %struct.__user_cap_data_struct* %2 to i8*
%5 = load i32, i32* @_LINUX_CAPABILITY_VERSION
%6 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %1, i64 0, i32 1
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %1, i64 0, i32 0
store i64 0, i64* %7
%8 = load i32, i32* @__NR_capget
%9 = call i32 @syscall(i32 %8, %struct.__user_cap_header_struct* %1, %struct.__user_cap_data_struct* %2)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %20
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %2, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %2, i64 0, i32 2
%18 = load i32, i32* %17
%19 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %16, i32 %18)
br label %22
20: ; preds = %0
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %11
ret i32 0
}