#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 scalar_t__ uid_t;
typedef int /*<<< orphan*/ path;
typedef scalar_t__ gid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strrchr(char *, char);
int get_process_info(int pid, uid_t *uid, gid_t *gid, int *nspid) {
  char path[64];
  snprintf(path, sizeof(path), "/proc/%d/status", pid);
  FILE *status_file = fopen(path, "r");
  if (status_file == NULL) {
    return 0;
  }
  char *line = NULL;
  size_t size;
  while (getline(&line, &size, status_file) != -1) {
    if (strncmp(line, "Uid:", 4) == 0) {
      *uid = (uid_t)atoi(strchr(line + 5, '\t'));
    } else if (strncmp(line, "Gid:", 4) == 0) {
      *gid = (gid_t)atoi(strchr(line + 5, '\t'));
    } else if (strncmp(line, "NStgid:", 7) == 0) {
      *nspid = atoi(strrchr(line, '\t'));
    }
  }
  free(line);
  fclose(status_file);
  return 1;
}


x86 assembly (clang, -O0):
<get_process_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x40,%esi
lea    0xe43(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11ed <get_process_info+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    1301 <get_process_info+0x171>
movq   $0x0,-0x70(%rbp)
mov    -0x68(%rbp),%rdx
lea    -0x70(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     12e8 <get_process_info+0x158>
mov    -0x70(%rbp),%rdi
lea    0xdf8(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1256 <get_process_info+0xc6>
mov    -0x70(%rbp),%rdi
add    $0x5,%rdi
mov    $0x9,%esi
call   1060 <strchr@plt>
mov    %eax,%edi
call   10a0 <atoi@plt>
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    12e3 <get_process_info+0x153>
mov    -0x70(%rbp),%rdi
lea    0xdb6(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    129d <get_process_info+0x10d>
mov    -0x70(%rbp),%rdi
add    $0x5,%rdi
mov    $0x9,%esi
call   1060 <strchr@plt>
mov    %eax,%edi
call   10a0 <atoi@plt>
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    12de <get_process_info+0x14e>
mov    -0x70(%rbp),%rdi
lea    0xd74(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12d9 <get_process_info+0x149>
mov    -0x70(%rbp),%rdi
mov    $0x9,%esi
call   1080 <strrchr@plt>
mov    %eax,%edi
call   10a0 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12de <get_process_info+0x14e>
jmp    12e3 <get_process_info+0x153>
jmp    11f5 <get_process_info+0x65>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_process_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r12
mov    %edi,%ecx
lea    0xe4c(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1070 <snprintf@plt>
lea    0xe43(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12fc <get_process_info+0x16c>
mov    %rax,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%rdi
lea    0x18(%rsp),%rsi
mov    %rax,%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     12e4 <get_process_info+0x154>
lea    0xe09(%rip),%r13
mov    %rsp,%rbp
lea    0x18(%rsp),%r14
lea    0xdff(%rip),%r15
jmp    1252 <get_process_info+0xc2>
nopw   0x0(%rax,%rax,1)
add    $0x5,%rdi
mov    $0x9,%esi
call   1060 <strchr@plt>
mov    %eax,%edi
call   10a0 <atoi@plt>
cltq
mov    %rax,(%r12)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     12e4 <get_process_info+0x154>
mov    (%rsp),%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    (%rsp),%rdi
test   %rax,%rax
je     1220 <get_process_info+0x90>
mov    %r15,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    (%rsp),%rdi
test   %rax,%rax
je     12c0 <get_process_info+0x130>
lea    0xd93(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    123b <get_process_info+0xab>
mov    (%rsp),%rdi
mov    $0x9,%esi
call   1080 <strrchr@plt>
mov    %eax,%edi
call   10a0 <atoi@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
jmp    123b <get_process_info+0xab>
cs nopw 0x0(%rax,%rax,1)
add    $0x5,%rdi
mov    $0x9,%esi
call   1060 <strchr@plt>
mov    %eax,%edi
call   10a0 <atoi@plt>
cltq
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
jmp    123b <get_process_info+0xab>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
jmp    12fe <get_process_info+0x16e>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/%d/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"Uid:\00"
@.str.3 = [5 x i8] c"Gid:\00"
@.str.4 = [8 x i8] c"NStgid:\00"
define i32 @get_process_info(i32 %0, i64* %1, i64* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i32*
%10 = alloca [64 x i8]
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i64
store i32 %0, i32* %6
store i64* %1, i64** %7
store i64* %2, i64** %8
store i32* %3, i32** %9
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%15 = load i32, i32* %6
%16 = call i32 @snprintf(i8* %14, i32 64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %11
%19 = load i32*, i32** %11
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 0, i32* %5
br label %66
22: ; preds = %4
store i8* null, i8** %12
br label %23
23: ; preds = %60, %22
%24 = load i32*, i32** %11
%25 = call i32 @getline(i8** %12, i64* %13, i32* %24)
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %61
27: ; preds = %23
%28 = load i8*, i8** %12
%29 = call i64 @strncmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i8*, i8** %12
%33 = getelementptr inbounds i8, i8* %32, i64 5
%34 = call i32 @strchr(i8* %33, i8 signext 9)
%35 = call i32 @atoi(i32 %34)
%36 = sext i32 %35 to i64
%37 = load i64*, i64** %7
store i64 %36, i64* %37
br label %60
38: ; preds = %27
%39 = load i8*, i8** %12
%40 = call i64 @strncmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i8*, i8** %12
%44 = getelementptr inbounds i8, i8* %43, i64 5
%45 = call i32 @strchr(i8* %44, i8 signext 9)
%46 = call i32 @atoi(i32 %45)
%47 = sext i32 %46 to i64
%48 = load i64*, i64** %8
store i64 %47, i64* %48
br label %59
49: ; preds = %38
%50 = load i8*, i8** %12
%51 = call i64 @strncmp(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %49
%54 = load i8*, i8** %12
%55 = call i32 @strrchr(i8* %54, i8 signext 9)
%56 = call i32 @atoi(i32 %55)
%57 = load i32*, i32** %9
store i32 %56, i32* %57
br label %58
58: ; preds = %53, %49
br label %59
59: ; preds = %58, %42
br label %60
60: ; preds = %59, %31
br label %23
61: ; preds = %23
%62 = load i8*, i8** %12
%63 = call i32 @free(i8* %62)
%64 = load i32*, i32** %11
%65 = call i32 @fclose(i32* %64)
store i32 1, i32* %5
br label %66
66: ; preds = %61, %21
%67 = load i32, i32* %5
ret i32 %67
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/%d/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"Uid:\00"
@.str.3 = [5 x i8] c"Gid:\00"
@.str.4 = [8 x i8] c"NStgid:\00"
define i32 @get_process_info(i32 %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [64 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = call i32 @snprintf(i8* %8, i32 64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %0)
%10 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %50, label %12
12: ; preds = %4
%13 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%14 = bitcast i64* %7 to i8*
%15 = call i32 @getline(i8** %6, i64* %7, i32* %10)
%16 = icmp eq i32 %15, -1
br i1 %16, label %46, label %17
17: ; preds = %12, %43
%18 = load i8*, i8** %6
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%20 = icmp eq i64 %19, 0
%21 = load i8*, i8** %6
br i1 %20, label %22, label %27
22: ; preds = %17
%23 = getelementptr inbounds i8, i8* %21, i64 5
%24 = call i32 @strchr(i8* %23, i8 signext 9)
%25 = call i32 @atoi(i32 %24)
%26 = sext i32 %25 to i64
store i64 %26, i64* %1
br label %43
27: ; preds = %17
%28 = call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%29 = icmp eq i64 %28, 0
%30 = load i8*, i8** %6
br i1 %29, label %31, label %36
31: ; preds = %27
%32 = getelementptr inbounds i8, i8* %30, i64 5
%33 = call i32 @strchr(i8* %32, i8 signext 9)
%34 = call i32 @atoi(i32 %33)
%35 = sext i32 %34 to i64
store i64 %35, i64* %2
br label %43
36: ; preds = %27
%37 = call i64 @strncmp(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i8*, i8** %6
%41 = call i32 @strrchr(i8* %40, i8 signext 9)
%42 = call i32 @atoi(i32 %41)
store i32 %42, i32* %3
br label %43
43: ; preds = %31, %39, %36, %22
%44 = call i32 @getline(i8** %6, i64* %7, i32* %10)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %17
46: ; preds = %43, %12
%47 = load i8*, i8** %6
%48 = call i32 @free(i8* %47)
%49 = call i32 @fclose(i32* %10)
br label %50
50: ; preds = %4, %46
%51 = phi i32 [ 1, %46 ], [ 0, %4 ]
ret i32 %51
}