#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
void print_status(void) {
  FILE *fp = fopen("/proc/self/status", "r");
  if (!fp) {
    fprintf(stderr, "Error, cannot open status file\n");
    exit(1);
  }
  char buf[4096];
  while (fgets(buf, 4096, fp)) {
    if (strncmp(buf, "Uid", 3) == 0 || strncmp(buf, "Gid", 3) == 0)
      printf("%s", buf);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<print_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
lea    0xe7e(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11bc <print_status+0x4c>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11c1 <print_status+0x51>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     123c <print_status+0xcc>
lea    -0x1010(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1224 <print_status+0xb4>
lea    -0x1010(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1237 <print_status+0xc7>
lea    -0x1010(%rbp),%rsi
lea    0xe0a(%rip),%rdi
call   1050 <printf@plt>
jmp    11c1 <print_status+0x51>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_status>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1000,%rsp
lea    0xe79(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1235 <print_status+0xc5>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     121c <print_status+0xac>
lea    0xe79(%rip),%r14
mov    %rsp,%rbx
lea    0xe77(%rip),%r12
lea    0xe6c(%rip),%r13
jmp    11f0 <print_status+0x80>
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     121c <print_status+0xac>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11d0 <print_status+0x60>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11db <print_status+0x6b>
jmp    11d0 <print_status+0x60>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Error, cannot open status file\0A\00"
@.str.3 = [4 x i8] c"Uid\00"
@.str.4 = [4 x i8] c"Gid\00"
@.str.5 = [3 x i8] c"%s\00"
define void @print_status() {
%1 = alloca i32*
%2 = alloca [4096 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 ne i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
br label %11
11: ; preds = %27, %10
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** %1
%14 = call i64 @fgets(i8* %12, i32 4096, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%18 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%22 = call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20, %16
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %20
br label %11
28: ; preds = %11
%29 = load i32*, i32** %1
%30 = call i32 @fclose(i32* %29)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Error, cannot open status file\0A\00"
@.str.3 = [4 x i8] c"Uid\00"
@.str.4 = [4 x i8] c"Gid\00"
@.str.5 = [3 x i8] c"%s\00"
define void @print_status() {
%1 = alloca [4096 x i8]
%2 = 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%10 = call i64 @fgets(i8* %9, i32 4096, i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %8, %20
%13 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15, %12
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %9)
br label %20
20: ; preds = %18, %15
%21 = call i64 @fgets(i8* %9, i32 4096, i32* %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %12
23: ; preds = %20, %8
%24 = call i32 @fclose(i32* %2)
ret void
}