#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*/ 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*/ snprintf(char *, size_t, char *, int, char *, char *, char *,
                            int);
int strlen(char *);
scalar_t__ xmalloc(size_t);
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;
  size_t result_length;
  char *result;
  rval = get_uid_gid(pid, &uid, &gid);
  if (rval != 0)
    return NULL;
  rss = get_rss(pid);
  if (rss == -1)
    return NULL;
  program_name = get_program_name(pid);
  if (program_name == NULL)
    return NULL;
  user_name = get_user_name(uid);
  group_name = get_group_name(gid);
  result_length =
      strlen(program_name) + strlen(user_name) + strlen(group_name) + 128;
  result = (char *)xmalloc(result_length);
  snprintf(result, result_length,
           "<tr><td align=\"right\">%d</td><td><tt>%s</tt></td><td>%s</td>"
           "<td>%s</td><td align=\"right\">%d</td></tr>\n",
           (int)pid, program_name, user_name, group_name, rss);
  free(program_name);
  free(user_name);
  free(group_name);
  return result;
}


x86 assembly (clang, -O0):
<format_process_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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     11c7 <format_process_info+0x37>
movq   $0x0,-0x8(%rbp)
jmp    12c2 <format_process_info+0x132>
mov    -0x10(%rbp),%rdi
call   1080 <get_rss@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    11ea <format_process_info+0x5a>
movq   $0x0,-0x8(%rbp)
jmp    12c2 <format_process_info+0x132>
mov    -0x10(%rbp),%rdi
call   10b0 <get_program_name@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    120f <format_process_info+0x7f>
movq   $0x0,-0x8(%rbp)
jmp    12c2 <format_process_info+0x132>
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    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
add    $0x80,%eax
cltq
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1070 <xmalloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    -0x40(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x30(%rbp),%r10
mov    -0x34(%rbp),%eax
lea    0xd6e(%rip),%rdx
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <snprintf@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    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%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    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <get_uid_gid@plt>
test   %eax,%eax
je     11c8 <format_process_info+0x38>
xor    %ebp,%ebp
mov    %rbp,%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     11b4 <format_process_info+0x24>
mov    %eax,%r14d
mov    %rbx,%rdi
call   10b0 <get_program_name@plt>
test   %rax,%rax
je     11b4 <format_process_info+0x24>
mov    %rax,%r15
mov    0xc(%rsp),%edi
call   10a0 <get_user_name@plt>
mov    %rax,%rbp
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%edi
call   1090 <get_group_name@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,0x4(%rsp)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %r13,%rdi
call   1050 <strlen@plt>
add    0x4(%rsp),%r12d
add    %r12d,%eax
add    $0x80,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1070 <xmalloc@plt>
mov    %rax,%rbp
lea    0xdba(%rip),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%ecx
mov    %r15,%r8
mov    0x10(%rsp),%rbx
mov    %rbx,%r9
push   %r14
push   %r13
call   1060 <snprintf@plt>
add    $0x10,%rsp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11b6 <format_process_info+0x26>

LLVM IR (-O0):
@.str = [103 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>\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 i64
%12 = alloca i8*
store i64 %0, i64* %3
%13 = load i64, i64* %3
%14 = call i32 @get_uid_gid(i64 %13, i32* %5, i32* %6)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %1
store i8* null, i8** %2
br label %64
18: ; preds = %1
%19 = load i64, i64* %3
%20 = call i32 @get_rss(i64 %19)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %18
store i8* null, i8** %2
br label %64
24: ; preds = %18
%25 = load i64, i64* %3
%26 = call i8* @get_program_name(i64 %25)
store i8* %26, i8** %10
%27 = load i8*, i8** %10
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
store i8* null, i8** %2
br label %64
30: ; preds = %24
%31 = load i32, i32* %5
%32 = call i8* @get_user_name(i32 %31)
store i8* %32, i8** %7
%33 = load i32, i32* %6
%34 = call i8* @get_group_name(i32 %33)
store i8* %34, i8** %8
%35 = load i8*, i8** %10
%36 = call i32 @strlen(i8* %35)
%37 = load i8*, i8** %7
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %36, %38
%40 = load i8*, i8** %8
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %39, %41
%43 = add nsw i32 %42, 128
%44 = sext i32 %43 to i64
store i64 %44, i64* %11
%45 = load i64, i64* %11
%46 = call i64 @xmalloc(i64 %45)
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %12
%48 = load i8*, i8** %12
%49 = load i64, i64* %11
%50 = load i64, i64* %3
%51 = trunc i64 %50 to i32
%52 = load i8*, i8** %10
%53 = load i8*, i8** %7
%54 = load i8*, i8** %8
%55 = load i32, i32* %9
%56 = call i32 @snprintf(i8* %48, i64 %49, i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str, i64 0, i64 0), i32 %51, i8* %52, i8* %53, i8* %54, i32 %55)
%57 = load i8*, i8** %10
%58 = call i32 @free(i8* %57)
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
%61 = load i8*, i8** %8
%62 = call i32 @free(i8* %61)
%63 = load i8*, i8** %12
store i8* %63, i8** %2
br label %64
64: ; preds = %30, %29, %23, %17
%65 = load i8*, i8** %2
ret i8* %65
}

LLVM IR (-O2):
@.str = [103 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>\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 %8, label %33
8: ; preds = %1
%9 = call i32 @get_rss(i64 %0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %33, label %11
11: ; preds = %8
%12 = call i8* @get_program_name(i64 %0)
%13 = icmp eq i8* %12, null
br i1 %13, label %33, label %14
14: ; preds = %11
%15 = load i32, i32* %2
%16 = call i8* @get_user_name(i32 %15)
%17 = load i32, i32* %3
%18 = call i8* @get_group_name(i32 %17)
%19 = call i32 @strlen(i8* %12)
%20 = call i32 @strlen(i8* %16)
%21 = call i32 @strlen(i8* %18)
%22 = add i32 %19, 128
%23 = add i32 %22, %20
%24 = add i32 %23, %21
%25 = sext i32 %24 to i64
%26 = call i64 @xmalloc(i64 %25)
%27 = inttoptr i64 %26 to i8*
%28 = trunc i64 %0 to i32
%29 = call i32 @snprintf(i8* %27, i64 %25, i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str, i64 0, i64 0), i32 %28, i8* %12, i8* %16, i8* %18, i32 %9)
%30 = call i32 @free(i8* %12)
%31 = call i32 @free(i8* %16)
%32 = call i32 @free(i8* %18)
br label %33
33: ; preds = %11, %8, %1, %14
%34 = phi i8* [ %27, %14 ], [ null, %1 ], [ null, %8 ], [ null, %11 ]
ret i8* %34
}