#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 alt_lookup_nspid(int);
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 -1;
  }
  char *line = NULL;
  size_t size;
  int nspid_found = 0;
  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'));
      nspid_found = 1;
    }
  }
  free(line);
  fclose(status_file);
  if (!nspid_found) {
    *nspid = alt_lookup_nspid(pid);
  }
  return 0;
}


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    0xe33(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11fd <get_process_info+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1339 <get_process_info+0x199>
movq   $0x0,-0x70(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x68(%rbp),%rdx
lea    -0x70(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
je     1306 <get_process_info+0x166>
mov    -0x70(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    126d <get_process_info+0xcd>
mov    -0x70(%rbp),%rdi
add    $0x5,%rdi
mov    $0x9,%esi
call   1070 <strchr@plt>
mov    %eax,%edi
call   10b0 <atoi@plt>
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1301 <get_process_info+0x161>
mov    -0x70(%rbp),%rdi
lea    0xd9f(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12b4 <get_process_info+0x114>
mov    -0x70(%rbp),%rdi
add    $0x5,%rdi
mov    $0x9,%esi
call   1070 <strchr@plt>
mov    %eax,%edi
call   10b0 <atoi@plt>
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    12fc <get_process_info+0x15c>
mov    -0x70(%rbp),%rdi
lea    0xd5d(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12f7 <get_process_info+0x157>
mov    -0x70(%rbp),%rdi
mov    $0x9,%esi
call   1090 <strrchr@plt>
mov    %eax,%edi
call   10b0 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x7c(%rbp)
jmp    12fc <get_process_info+0x15c>
jmp    1301 <get_process_info+0x161>
jmp    120c <get_process_info+0x6c>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x7c(%rbp)
jne    1332 <get_process_info+0x192>
mov    -0x8(%rbp),%edi
call   1050 <alt_lookup_nspid@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-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    $0x78,%rsp
mov    %rcx,0x18(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rsi,%r13
mov    %edi,%ebx
lea    0xe3c(%rip),%rdx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %ebx,%ecx
call   1080 <snprintf@plt>
lea    0xe31(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1314 <get_process_info+0x174>
mov    %rax,%rbp
mov    %ebx,0x14(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x28(%rsp),%rsi
mov    %rax,%rdx
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
je     131b <get_process_info+0x17b>
movl   $0x0,0x10(%rsp)
lea    0xde8(%rip),%rbx
lea    0x8(%rsp),%r14
lea    0x28(%rsp),%r15
lea    0xddc(%rip),%r12
jmp    1272 <get_process_info+0xd2>
nopl   (%rax)
add    $0x5,%rdi
mov    $0x9,%esi
call   1070 <strchr@plt>
mov    %eax,%edi
call   10b0 <atoi@plt>
cltq
mov    %rax,0x0(%r13)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
je     1323 <get_process_info+0x183>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    0x8(%rsp),%rdi
test   %rax,%rax
je     1240 <get_process_info+0xa0>
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    0x8(%rsp),%rdi
test   %rax,%rax
je     12f0 <get_process_info+0x150>
lea    0xd70(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    125b <get_process_info+0xbb>
mov    0x8(%rsp),%rdi
mov    $0x9,%esi
call   1090 <strrchr@plt>
mov    %eax,%edi
call   10b0 <atoi@plt>
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx)
movl   $0x1,0x10(%rsp)
jmp    125b <get_process_info+0xbb>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x5,%rdi
mov    $0x9,%esi
call   1070 <strchr@plt>
mov    %eax,%edi
call   10b0 <atoi@plt>
cltq
mov    0x20(%rsp),%rcx
mov    %rax,(%rcx)
jmp    125b <get_process_info+0xbb>
mov    $0xffffffff,%eax
jmp    134e <get_process_info+0x1ae>
movl   $0x0,0x10(%rsp)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
cmpl   $0x0,0x10(%rsp)
jne    134c <get_process_info+0x1ac>
mov    0x14(%rsp),%edi
call   1050 <alt_lookup_nspid@plt>
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
add    $0x78,%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
%14 = alloca i32
store i32 %0, i32* %6
store i64* %1, i64** %7
store i64* %2, i64** %8
store i32* %3, i32** %9
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%16 = load i32, i32* %6
%17 = call i32 @snprintf(i8* %15, i32 64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %11
%20 = load i32*, i32** %11
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %4
store i32 -1, i32* %5
br label %74
23: ; preds = %4
store i8* null, i8** %12
store i32 0, i32* %14
br label %24
24: ; preds = %61, %23
%25 = load i32*, i32** %11
%26 = call i32 @getline(i8** %12, i64* %13, i32* %25)
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %62
28: ; preds = %24
%29 = load i8*, i8** %12
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i8*, i8** %12
%34 = getelementptr inbounds i8, i8* %33, i64 5
%35 = call i32 @strchr(i8* %34, i8 signext 9)
%36 = call i32 @atoi(i32 %35)
%37 = sext i32 %36 to i64
%38 = load i64*, i64** %7
store i64 %37, i64* %38
br label %61
39: ; preds = %28
%40 = load i8*, i8** %12
%41 = call i64 @strncmp(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i8*, i8** %12
%45 = getelementptr inbounds i8, i8* %44, i64 5
%46 = call i32 @strchr(i8* %45, i8 signext 9)
%47 = call i32 @atoi(i32 %46)
%48 = sext i32 %47 to i64
%49 = load i64*, i64** %8
store i64 %48, i64* %49
br label %60
50: ; preds = %39
%51 = load i8*, i8** %12
%52 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i8*, i8** %12
%56 = call i32 @strrchr(i8* %55, i8 signext 9)
%57 = call i32 @atoi(i32 %56)
%58 = load i32*, i32** %9
store i32 %57, i32* %58
store i32 1, i32* %14
br label %59
59: ; preds = %54, %50
br label %60
60: ; preds = %59, %43
br label %61
61: ; preds = %60, %32
br label %24
62: ; preds = %24
%63 = load i8*, i8** %12
%64 = call i32 @free(i8* %63)
%65 = load i32*, i32** %11
%66 = call i32 @fclose(i32* %65)
%67 = load i32, i32* %14
%68 = icmp ne i32 %67, 0
br i1 %68, label %73, label %69
69: ; preds = %62
%70 = load i32, i32* %6
%71 = call i32 @alt_lookup_nspid(i32 %70)
%72 = load i32*, i32** %9
store i32 %71, i32* %72
br label %73
73: ; preds = %69, %62
store i32 0, i32* %5
br label %74
74: ; preds = %73, %22
%75 = load i32, i32* %5
ret i32 %75
}

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 %57, 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 %48, label %17
17: ; preds = %12, %44
%18 = phi i32 [ %45, %44 ], [ 0, %12 ]
%19 = load i8*, i8** %6
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%21 = icmp eq i64 %20, 0
%22 = load i8*, i8** %6
br i1 %21, label %23, label %28
23: ; preds = %17
%24 = getelementptr inbounds i8, i8* %22, i64 5
%25 = call i32 @strchr(i8* %24, i8 signext 9)
%26 = call i32 @atoi(i32 %25)
%27 = sext i32 %26 to i64
store i64 %27, i64* %1
br label %44
28: ; preds = %17
%29 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%30 = icmp eq i64 %29, 0
%31 = load i8*, i8** %6
br i1 %30, label %32, label %37
32: ; preds = %28
%33 = getelementptr inbounds i8, i8* %31, i64 5
%34 = call i32 @strchr(i8* %33, i8 signext 9)
%35 = call i32 @atoi(i32 %34)
%36 = sext i32 %35 to i64
store i64 %36, i64* %2
br label %44
37: ; preds = %28
%38 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i8*, i8** %6
%42 = call i32 @strrchr(i8* %41, i8 signext 9)
%43 = call i32 @atoi(i32 %42)
store i32 %43, i32* %3
br label %44
44: ; preds = %32, %40, %37, %23
%45 = phi i32 [ %18, %23 ], [ %18, %32 ], [ 1, %40 ], [ %18, %37 ]
%46 = call i32 @getline(i8** %6, i64* %7, i32* %10)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %17
48: ; preds = %44, %12
%49 = phi i32 [ 0, %12 ], [ %45, %44 ]
%50 = load i8*, i8** %6
%51 = call i32 @free(i8* %50)
%52 = call i32 @fclose(i32* %10)
%53 = icmp eq i32 %49, 0
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @alt_lookup_nspid(i32 %0)
store i32 %55, i32* %3
br label %56
56: ; preds = %54, %48
br label %57
57: ; preds = %4, %56
%58 = phi i32 [ 0, %56 ], [ -1, %4 ]
ret i32 %58
}