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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *get_group_name(int /*<<< orphan*/);
char *get_program_name(scalar_t__);
int get_rss(scalar_t__);
int get_uid_gid(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char *get_user_name(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, char *, char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ xmalloc(int);
char *format_process_info(pid_t pid) {
  int rval;
  uid_t uid;
  gid_t gid;
  char *user_name;
  char *group_name;
  int rss;
  char *program_name;
  char *result;
  rval = get_uid_gid(pid, &uid, &gid);
  if (rval != 0) {
    fprintf(stderr, "get_uid_gid error\n");
    return NULL;
  }
  rss = get_rss(pid);
  if (rss == -1) {
    fprintf(stderr, "get_rss error\n");
    return NULL;
  }
  program_name = get_program_name(pid);
  if (program_name == NULL) {
    fprintf(stderr, "get_program_name error\n");
    return NULL;
  }
  user_name = get_user_name(uid);
  group_name = get_group_name(gid);
  result = (char *)xmalloc(512);
  sprintf(result,
          "<tr><td "
          "align=\"right\">%d</td><td><tt>%s</tt></td><td>%s</td><td>%s</"
          "td><td align=\"right\">%d</td></tr>",
          (int)pid, program_name, user_name, group_name, rss);
  printf("%s\n", result);
  free(program_name);
  free(user_name);
  free(group_name);
  return result;
}


x86 assembly (clang, -O0):
<format_process_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <get_uid_gid@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11ec <format_process_info+0x4c>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12df <format_process_info+0x13f>
mov    -0x10(%rbp),%rdi
call   1080 <get_rss@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1224 <format_process_info+0x84>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12df <format_process_info+0x13f>
mov    -0x10(%rbp),%rdi
call   10b0 <get_program_name@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    125e <format_process_info+0xbe>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12df <format_process_info+0x13f>
mov    -0x18(%rbp),%edi
call   10a0 <get_user_name@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <get_group_name@plt>
mov    %rax,-0x30(%rbp)
mov    $0x200,%edi
call   1060 <xmalloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x34(%rbp),%eax
lea    0xd96(%rip),%rsi
mov    %eax,(%rsp)
call   10c0 <sprintf@plt>
mov    -0x48(%rbp),%rsi
lea    0xde9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_process_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1040 <get_uid_gid@plt>
test   %eax,%eax
je     11ee <format_process_info+0x4e>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1070 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1080 <get_rss@plt>
cmp    $0xffffffff,%eax
je     1283 <format_process_info+0xe3>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10b0 <get_program_name@plt>
test   %rax,%rax
je     1298 <format_process_info+0xf8>
mov    %rax,%r15
mov    0x14(%rsp),%edi
call   10a0 <get_user_name@plt>
mov    %rax,%r12
mov    0x10(%rsp),%edi
call   1090 <get_group_name@plt>
mov    %rax,%r13
mov    $0x200,%edi
call   1060 <xmalloc@plt>
mov    %rax,%r14
mov    %ebp,(%rsp)
lea    0xdf6(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r13,%r9
call   10c0 <sprintf@plt>
lea    0xe42(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11dc <format_process_info+0x3c>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
jmp    11d4 <format_process_info+0x34>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
jmp    11d4 <format_process_info+0x34>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"get_uid_gid error\0A\00"
@.str.1 = [15 x i8] c"get_rss error\0A\00"
@.str.2 = [24 x i8] c"get_program_name error\0A\00"
@.str.3 = [102 x i8] c"<tr><td align=\22right\22>%d</td><td><tt>%s</tt></td><td>%s</td><td>%s</td><td align=\22right\22>%d</td></tr>\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i8* @format_process_info(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i64 %0, i64* %3
%12 = load i64, i64* %3
%13 = call i32 @get_uid_gid(i64 %12, i32* %5, i32* %6)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %59
19: ; preds = %1
%20 = load i64, i64* %3
%21 = call i32 @get_rss(i64 %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %59
27: ; preds = %19
%28 = load i64, i64* %3
%29 = call i8* @get_program_name(i64 %28)
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %2
br label %59
35: ; preds = %27
%36 = load i32, i32* %5
%37 = call i8* @get_user_name(i32 %36)
store i8* %37, i8** %7
%38 = load i32, i32* %6
%39 = call i8* @get_group_name(i32 %38)
store i8* %39, i8** %8
%40 = call i64 @xmalloc(i32 512)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %11
%42 = load i8*, i8** %11
%43 = load i64, i64* %3
%44 = trunc i64 %43 to i32
%45 = load i8*, i8** %10
%46 = load i8*, i8** %7
%47 = load i8*, i8** %8
%48 = load i32, i32* %9
%49 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.3, i64 0, i64 0), i32 %44, i8* %45, i8* %46, i8* %47, i32 %48)
%50 = load i8*, i8** %11
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %10
%53 = call i32 @free(i8* %52)
%54 = load i8*, i8** %7
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %8
%57 = call i32 @free(i8* %56)
%58 = load i8*, i8** %11
store i8* %58, i8** %2
br label %59
59: ; preds = %35, %32, %24, %16
%60 = load i8*, i8** %2
ret i8* %60
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"get_uid_gid error\0A\00"
@.str.1 = [15 x i8] c"get_rss error\0A\00"
@.str.2 = [24 x i8] c"get_program_name error\0A\00"
@.str.3 = [102 x i8] c"<tr><td align=\22right\22>%d</td><td><tt>%s</tt></td><td>%s</td><td>%s</td><td align=\22right\22>%d</td></tr>\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i8* @format_process_info(i64 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @get_uid_gid(i64 %0, i32* %2, i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %36
11: ; preds = %1
%12 = call i32 @get_rss(i64 %0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %36
17: ; preds = %11
%18 = call i8* @get_program_name(i64 %0)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %36
23: ; preds = %17
%24 = load i32, i32* %2
%25 = call i8* @get_user_name(i32 %24)
%26 = load i32, i32* %3
%27 = call i8* @get_group_name(i32 %26)
%28 = call i64 @xmalloc(i32 512)
%29 = inttoptr i64 %28 to i8*
%30 = trunc i64 %0 to i32
%31 = call i32 @sprintf(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([102 x i8], [102 x i8]* @.str.3, i64 0, i64 0), i32 %30, i8* %18, i8* %25, i8* %27, i32 %12)
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%33 = call i32 @free(i8* %18)
%34 = call i32 @free(i8* %25)
%35 = call i32 @free(i8* %27)
br label %36
36: ; preds = %23, %20, %14, %8
%37 = phi i8* [ null, %8 ], [ null, %14 ], [ null, %20 ], [ %29, %23 ]
ret i8* %37
}