#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 */
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strncmp(char *, char *, int);
void show_capset() {
  FILE *filp;
  char line[256];
  filp = fopen("/proc/self/status", "r");
  if (filp == NULL) {
    perror("fopen");
    return;
  }
  while (fgets(line, sizeof(line), filp)) {
    if (strncmp(line, "Cap", 3) == 0)
      printf("%s", line);
  }
  fclose(filp);
}


x86 assembly (clang, -O0):
<show_capset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119e <show_capset+0x3e>
lea    0xe80(%rip),%rdi
call   1080 <perror@plt>
jmp    1205 <show_capset+0xa5>
jmp    11a3 <show_capset+0x43>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11fc <show_capset+0x9c>
lea    -0x110(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11f7 <show_capset+0x97>
lea    -0x110(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
jmp    11a3 <show_capset+0x43>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_capset>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     120e <show_capset+0xae>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f7 <show_capset+0x97>
lea    0xe71(%rip),%r14
mov    %rsp,%rbx
lea    0xe6b(%rip),%r12
jmp    11d5 <show_capset+0x75>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f7 <show_capset+0x97>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11c0 <show_capset+0x60>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    11c0 <show_capset+0x60>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdff(%rip),%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <perror@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [4 x i8] c"Cap\00"
@.str.4 = [3 x i8] c"%s\00"
define void @show_capset() {
%1 = alloca i32*
%2 = alloca [256 x i8]
%3 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %25
8: ; preds = %0
br label %9
9: ; preds = %21, %8
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %1
%12 = call i64 @fgets(i8* %10, i32 256, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %14
br label %9
22: ; preds = %9
%23 = load i32*, i32** %1
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %22, %6
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [4 x i8] c"Cap\00"
@.str.4 = [3 x i8] c"%s\00"
define void @show_capset() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i64 @fgets(i8* %2, i32 256, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %18, label %10
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %20
10: ; preds = %5, %15
%11 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %15
15: ; preds = %13, %10
%16 = call i64 @fgets(i8* %2, i32 256, i32* %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %15, %5
%19 = call i32 @fclose(i32* %3)
br label %20
20: ; preds = %18, %8
ret void
}