#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 */
struct passwd {
  char *pw_name;
};

/* Variables and functions */
struct passwd *getpwuid(int);
int /*<<< orphan*/ mark_seen(int);
int /*<<< orphan*/ printf(char *, int, char *, char *);
int read_int(int, char *, int *);
int readlink(char *, char *, int);
scalar_t__ saw_this_pid(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void print_proc(int pid) {
  if (saw_this_pid(pid))
    return;
  int uid;
  if (read_int(pid, "uid", &uid) == -1)
    return;
  char path[256];
  char link[156];
  sprintf(path, "/proc/%d/exe", pid);
  if (readlink(path, link, 256) == -1)
    link[0] = 0;
  struct passwd *pw;
  pw = getpwuid(uid);
  mark_seen(pid);
  printf("%4d %s %s\n", pid, pw ? pw->pw_name : "???", link);
}


x86 assembly (clang, -O0):
<print_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <saw_this_pid@plt>
cmp    $0x0,%rax
je     1195 <print_proc+0x25>
jmp    126b <print_proc+0xfb>
mov    -0x4(%rbp),%edi
lea    0xe61(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1080 <read_int@plt>
cmp    $0xffffffff,%eax
jne    11b6 <print_proc+0x46>
jmp    126b <print_proc+0xfb>
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe3d(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x1b0(%rbp),%rsi
mov    $0x100,%edx
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
jne    11f4 <print_proc+0x84>
movb   $0x0,-0x1b0(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x1b8(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <mark_seen@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1bc(%rbp)
cmpq   $0x0,-0x1b8(%rbp)
je     1238 <print_proc+0xc8>
mov    -0x1b8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1c8(%rbp)
jmp    124b <print_proc+0xdb>
lea    0xddd(%rip),%rax
mov    %rax,-0x1c8(%rbp)
jmp    124b <print_proc+0xdb>
mov    -0x1bc(%rbp),%esi
mov    -0x1c8(%rbp),%rdx
lea    -0x1b0(%rbp),%rcx
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_proc>:
push   %r14
push   %rbx
sub    $0x1b8,%rsp
mov    %edi,%ebx
call   1070 <saw_this_pid@plt>
test   %rax,%rax
jne    120e <print_proc+0x9e>
lea    0xe6f(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1080 <read_int@plt>
cmp    $0xffffffff,%eax
je     120e <print_proc+0x9e>
lea    0xe5b(%rip),%rsi
lea    0xb0(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1090 <sprintf@plt>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0x100,%edx
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
jne    11d7 <print_proc+0x67>
movb   $0x0,0x10(%rsp)
mov    0xc(%rsp),%edi
call   1040 <getpwuid@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1060 <mark_seen@plt>
test   %r14,%r14
je     11f4 <print_proc+0x84>
mov    (%r14),%rdx
jmp    11fb <print_proc+0x8b>
lea    0xe21(%rip),%rdx
lea    0xe0f(%rip),%rdi
lea    0x10(%rsp),%rcx
mov    %ebx,%esi
call   1050 <printf@plt>
add    $0x1b8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [4 x i8] c"uid\00"
@.str.1 = [13 x i8] c"/proc/%d/exe\00"
@.str.2 = [11 x i8] c"%4d %s %s\0A\00"
@.str.3 = [4 x i8] c"???\00"
define void @print_proc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca [156 x i8]
%6 = alloca %struct.passwd*
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i64 @saw_this_pid(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %43
11: ; preds = %1
%12 = load i32, i32* %2
%13 = call i32 @read_int(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %11
br label %43
16: ; preds = %11
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* %2
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds [156 x i8], [156 x i8]* %5, i64 0, i64 0
%22 = call i32 @readlink(i8* %20, i8* %21, i32 256)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = getelementptr inbounds [156 x i8], [156 x i8]* %5, i64 0, i64 0
store i8 0, i8* %25
br label %26
26: ; preds = %24, %16
%27 = load i32, i32* %3
%28 = call %struct.passwd* @getpwuid(i32 %27)
store %struct.passwd* %28, %struct.passwd** %6
%29 = load i32, i32* %2
%30 = call i32 @mark_seen(i32 %29)
%31 = load i32, i32* %2
%32 = load %struct.passwd*, %struct.passwd** %6
%33 = icmp ne %struct.passwd* %32, null
br i1 %33, label %34, label %38
34: ; preds = %26
%35 = load %struct.passwd*, %struct.passwd** %6
%36 = getelementptr inbounds %struct.passwd, %struct.passwd* %35, i32 0, i32 0
%37 = load i8*, i8** %36
br label %39
38: ; preds = %26
br label %39
39: ; preds = %38, %34
%40 = phi i8* [ %37, %34 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %38 ]
%41 = getelementptr inbounds [156 x i8], [156 x i8]* %5, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %31, i8* %40, i8* %41)
br label %43
43: ; preds = %39, %15, %10
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [4 x i8] c"uid\00"
@.str.1 = [13 x i8] c"/proc/%d/exe\00"
@.str.2 = [11 x i8] c"%4d %s %s\0A\00"
@.str.3 = [4 x i8] c"???\00"
define void @print_proc(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca [156 x i8]
%5 = tail call i64 @saw_this_pid(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %30
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
%9 = call i32 @read_int(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %29, label %11
11: ; preds = %7
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [156 x i8], [156 x i8]* %4, i64 0, i64 0
%14 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%15 = call i32 @readlink(i8* %12, i8* %13, i32 256)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %11
store i8 0, i8* %13
br label %18
18: ; preds = %17, %11
%19 = load i32, i32* %2
%20 = call %struct.passwd* @getpwuid(i32 %19)
%21 = call i32 @mark_seen(i32 %0)
%22 = icmp eq %struct.passwd* %20, null
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %20, i64 0, i32 0
%25 = load i8*, i8** %24
br label %26
26: ; preds = %18, %23
%27 = phi i8* [ %25, %23 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %18 ]
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %27, i8* %13)
br label %29
29: ; preds = %7, %26
br label %30
30: ; preds = %1, %29
ret void
}