#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 *, ...);
scalar_t__ getuid();
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;
  if (getuid() == 0)
    fprintf(stderr, "Running as root\n");
  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    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x0,%rax
jne    1177 <main+0x37>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <syscall@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11d4 <main+0x94>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11e0 <main+0xa0>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
xor    %eax,%eax
call   1030 <getuid@plt>
test   %rax,%rax
jne    1167 <main+0x27>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1050 <syscall@plt>
test   %eax,%eax
js     11c4 <main+0x84>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret
lea    0xe86(%rip),%rdi
call   1060 <perror@plt>
jmp    11bd <main+0x7d>

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

LLVM IR (-O2):
%struct.__user_cap_header_struct = type { i64, i32 }
%struct.__user_cap_data_struct = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [17 x i8] c"Running as root\0A\00"
@_LINUX_CAPABILITY_VERSION = global i32 0
@__NR_capget = global i32 0
@.str.1 = [64 x i8] c"capget result:\0Aeffective %#x\0Apermitted %#x\0Ainheritable %#x\0A\00"
@.str.2 = [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 = tail call i64 (...) @getuid()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %0
%11 = load i32, i32* @_LINUX_CAPABILITY_VERSION
%12 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %1, i64 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.__user_cap_header_struct, %struct.__user_cap_header_struct* %1, i64 0, i32 0
store i64 0, i64* %13
%14 = load i32, i32* @__NR_capget
%15 = call i32 @syscall(i32 %14, %struct.__user_cap_header_struct* %1, %struct.__user_cap_data_struct* %2)
%16 = icmp sgt i32 %15, -1
br i1 %16, label %17, label %26
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %2, i64 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %2, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.__user_cap_data_struct, %struct.__user_cap_data_struct* %2, i64 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %22, i32 %24)
br label %28
26: ; preds = %10
%27 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %17
ret i32 0
}