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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
scalar_t__ get_file(int, char *, char *);
int sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strstr(char *, char *);
void get_name_user_group_id(int pid, char *comm, unsigned int *uid,
                            unsigned int *euid, unsigned int *suid,
                            unsigned int *gid, unsigned int *egid,
                            unsigned int *sgid) {
  char buf[512];
  char *str;
  int ret;
  int dummy;
  if (get_file(pid, "status", buf) <= 0)
    return;
  ret = sscanf(buf, "Name:\t%s\n", comm);
  if (ret < 1) {
    fprintf(stderr, "get_user_group_id: %d: name not found\n", pid);
  }
  comm[16 - 1] = 0;
  str = strstr(buf, "Uid:");
  if (!str) {
    fprintf(stderr, "get_user_group_id: %d: uid not found\n", pid);
    return;
  }
  ret = sscanf(str, "Uid:\t%d\t%d\t%d\t%d\nGid:\t%d\t%d\t%d\t%d\n", uid, euid,
               suid, &dummy, gid, egid, sgid, &dummy);
  if (ret < 8) {
    fprintf(stderr, "get_user_group_id: %d: %d uids found\n", pid, ret);
  }
}


x86 assembly (clang, -O0):
<get_name_user_group_id>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x268,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x240(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1030 <get_file@plt>
cmp    $0x0,%rax
jg     1190 <get_name_user_group_id+0x50>
jmp    12a2 <get_name_user_group_id+0x162>
lea    -0x240(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    %eax,-0x24c(%rbp)
cmpl   $0x1,-0x24c(%rbp)
jge    11d6 <get_name_user_group_id+0x96>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0xf(%rax)
lea    -0x240(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x248(%rbp)
cmpq   $0x0,-0x248(%rbp)
jne    1225 <get_name_user_group_id+0xe5>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12a2 <get_name_user_group_id+0x162>
mov    -0x248(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x38(%rbp),%rbx
mov    0x10(%rbp),%r11
mov    0x18(%rbp),%r10
lea    0xe18(%rip),%rsi
lea    -0x250(%rbp),%rax
mov    %rax,%r9
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    %eax,-0x24c(%rbp)
cmpl   $0x8,-0x24c(%rbp)
jge    12a2 <get_name_user_group_id+0x162>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x24c(%rbp),%ecx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x268,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_name_user_group_id>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xe97(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1030 <get_file@plt>
test   %rax,%rax
jle    1239 <get_name_user_group_id+0xf9>
lea    0xe84(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
test   %eax,%eax
jg     11af <get_name_user_group_id+0x6f>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
movb   $0x0,0xf(%rbp)
lea    0xe7e(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     1220 <get_name_user_group_id+0xe0>
lea    0xc(%rsp),%r9
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15,%r8
xor    %eax,%eax
push   %r9
push   0x260(%rsp)
push   0x260(%rsp)
push   %r14
call   1050 <sscanf@plt>
add    $0x20,%rsp
cmp    $0x7,%eax
jg     1239 <get_name_user_group_id+0xf9>
mov    0x2dd6(%rip),%rcx
mov    (%rcx),%edi
lea    0xe73(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1239 <get_name_user_group_id+0xf9>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"status\00"
@.str.1 = [10 x i8] c"Name:\09%s\0A\00"
@stderr = global i32 0
@.str.2 = [39 x i8] c"get_user_group_id: %d: name not found\0A\00"
@.str.3 = [5 x i8] c"Uid:\00"
@.str.4 = [38 x i8] c"get_user_group_id: %d: uid not found\0A\00"
@.str.5 = [35 x i8] c"Uid:\09%d\09%d\09%d\09%d\0AGid:\09%d\09%d\09%d\09%d\0A\00"
@.str.6 = [38 x i8] c"get_user_group_id: %d: %d uids found\0A\00"
define void @get_name_user_group_id(i32 %0, i8* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca [512 x i8]
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
store i32 %0, i32* %9
store i8* %1, i8** %10
store i32* %2, i32** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i32* %5, i32** %14
store i32* %6, i32** %15
store i32* %7, i32** %16
%21 = load i32, i32* %9
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%23 = call i64 @get_file(i32 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = icmp sle i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %8
br label %63
26: ; preds = %8
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%28 = load i8*, i8** %10
%29 = call i32 (i8*, i8*, ...) @sscanf(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 %29, i32* %19
%30 = load i32, i32* %19
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = load i32, i32* %9
%35 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32, %26
%37 = load i8*, i8** %10
%38 = getelementptr inbounds i8, i8* %37, i64 15
store i8 0, i8* %38
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%40 = call i8* @strstr(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %40, i8** %18
%41 = load i8*, i8** %18
%42 = icmp ne i8* %41, null
br i1 %42, label %47, label %43
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = load i32, i32* %9
%46 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %63
47: ; preds = %36
%48 = load i8*, i8** %18
%49 = load i32*, i32** %11
%50 = load i32*, i32** %12
%51 = load i32*, i32** %13
%52 = load i32*, i32** %14
%53 = load i32*, i32** %15
%54 = load i32*, i32** %16
%55 = call i32 (i8*, i8*, ...) @sscanf(i8* %48, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32* %49, i32* %50, i32* %51, i32* %20, i32* %52, i32* %53, i32* %54, i32* %20)
store i32 %55, i32* %19
%56 = load i32, i32* %19
%57 = icmp slt i32 %56, 8
br i1 %57, label %58, label %63
58: ; preds = %47
%59 = load i32, i32* @stderr
%60 = load i32, i32* %9
%61 = load i32, i32* %19
%62 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %60, i32 %61)
br label %63
63: ; preds = %25, %43, %58, %47
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"status\00"
@.str.1 = [10 x i8] c"Name:\09%s\0A\00"
@stderr = global i32 0
@.str.2 = [39 x i8] c"get_user_group_id: %d: name not found\0A\00"
@.str.3 = [5 x i8] c"Uid:\00"
@.str.4 = [38 x i8] c"get_user_group_id: %d: uid not found\0A\00"
@.str.5 = [35 x i8] c"Uid:\09%d\09%d\09%d\09%d\0AGid:\09%d\09%d\09%d\09%d\0A\00"
@.str.6 = [38 x i8] c"get_user_group_id: %d: %d uids found\0A\00"
define void @get_name_user_group_id(i32 %0, i8* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7) {
%9 = alloca [512 x i8]
%10 = alloca i32
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%12 = bitcast i32* %10 to i8*
%13 = call i64 @get_file(i32 %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %11)
%14 = icmp slt i64 %13, 1
br i1 %14, label %34, label %15
15: ; preds = %8
%16 = call i32 (i8*, i8*, ...) @sscanf(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %21
21: ; preds = %18, %15
%22 = getelementptr inbounds i8, i8* %1, i64 15
store i8 0, i8* %22
%23 = call i8* @strstr(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %34
28: ; preds = %21
%29 = call i32 (i8*, i8*, ...) @sscanf(i8* %23, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %10, i32* %5, i32* %6, i32* %7, i32* %10)
%30 = icmp slt i32 %29, 8
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %0, i32 %29)
br label %34
34: ; preds = %28, %31, %8, %25
ret void
}