#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;
struct passwd {
  scalar_t__ pw_uid;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ err_exit(char *, char *);
int /*<<< orphan*/ errno;
struct passwd *getpwnam(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
char *strtok(char *, char *);
void print_procs_by_login(char *login) {
  char filename[64], read_buf[512], *line, token[20], token1[20],
      cmdline_file[64];
  struct passwd *pwd;
  DIR *dirp;
  struct dirent *direntp;
  int fd, i;
  size_t num_bytes_read;
  uid_t uid;
  char uid_str[] = "Uid:";
  if ((pwd = getpwnam(login)) != NULL) {
    printf("Processes run by %s\n", login);
    printf("\nPID COMMAND\n");
    uid = pwd->pw_uid;
    dirp = opendir("/proc");
    if (dirp != NULL) {
      while ((direntp = readdir(dirp)) != NULL) {
        if (atoi(direntp->d_name) != 0) {
          sprintf(filename, "/proc/%s/status", direntp->d_name);
          fd = open(filename, O_RDONLY);
          if (fd != -1) {
            if ((num_bytes_read = read(fd, read_buf, 512)) != 0) {
              if (num_bytes_read != -1) {
                line = strtok(read_buf, "\n");
                while (line != NULL) {
                  sscanf(line, "%s", token);
                  if (strcmp(token, uid_str) == 0) {
                    sscanf(line, "%s %s", token, token1);
                    if (atoi(token1) == uid) {
                      sprintf(cmdline_file, "/proc/%s/cmdline",
                              direntp->d_name);
                      if ((fd = open(cmdline_file, O_RDONLY)) != -1) {
                        memset(read_buf, 0, 512);
                        if ((num_bytes_read = read(fd, read_buf, 512)) != 0) {
                          if (num_bytes_read != -1) {
                            printf("%s ", direntp->d_name);
                            for (i = 0; i < num_bytes_read; i++) {
                              if (read_buf[i] == 0) {
                                printf(" ");
                              } else {
                                printf("%c", read_buf[i]);
                              }
                            }
                            printf("\n");
                          }
                        }
                      }
                    }
                  }
                  line = strtok(NULL, "\n");
                }
              }
            } else {
              err_exit("Error on read, %s\n", strerror(errno));
            }
            close(fd);
          }
        }
      }
      closedir(dirp);
    } else {
      err_exit("Error on opendir, %s\n", strerror(errno));
    }
  } else {
    err_exit("Invalid login, %s\n", login);
  }
}


x86 assembly (clang, -O0):
<print_procs_by_login>:
push   %rbp
mov    %rsp,%rbp
sub    $0x310,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xdeb(%rip),%eax
mov    %eax,-0x305(%rbp)
mov    0xde3(%rip),%al
mov    %al,-0x301(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <getpwnam@plt>
mov    %rax,-0x2d8(%rbp)
cmp    $0x0,%rax
je     15ae <print_procs_by_login+0x3ae>
mov    -0x8(%rbp),%rsi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2d8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x300(%rbp)
lea    0xdaf(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x2e0(%rbp)
cmpq   $0x0,-0x2e0(%rbp)
je     158c <print_procs_by_login+0x38c>
jmp    1298 <print_procs_by_login+0x98>
mov    -0x2e0(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x2e8(%rbp)
cmp    $0x0,%rax
je     157b <print_procs_by_login+0x37b>
mov    -0x2e8(%rbp),%rax
mov    (%rax),%rdi
call   1100 <atoi@plt>
cmp    $0x0,%rax
je     1576 <print_procs_by_login+0x376>
lea    -0x50(%rbp),%rdi
mov    -0x2e8(%rbp),%rax
mov    (%rax),%rdx
lea    0xd4b(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2cf5(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x2ec(%rbp)
cmpl   $0xffffffff,-0x2ec(%rbp)
je     1571 <print_procs_by_login+0x371>
mov    -0x2ec(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %rax,-0x2f8(%rbp)
cmp    $0x0,%rax
je     1549 <print_procs_by_login+0x349>
cmpq   $0xffffffffffffffff,-0x2f8(%rbp)
ff
je     1544 <print_procs_by_login+0x344>
lea    -0x250(%rbp),%rdi
lea    0xcd5(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x258(%rbp)
cmpq   $0x0,-0x258(%rbp)
je     153f <print_procs_by_login+0x33f>
mov    -0x258(%rbp),%rdi
lea    -0x270(%rbp),%rdx
lea    0xcc1(%rip),%rsi
mov    $0x0,%al
call   10d0 <sscanf@plt>
lea    -0x270(%rbp),%rdi
lea    -0x305(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1523 <print_procs_by_login+0x323>
mov    -0x258(%rbp),%rdi
lea    -0x270(%rbp),%rdx
lea    -0x290(%rbp),%rcx
lea    0xc7e(%rip),%rsi
mov    $0x0,%al
call   10d0 <sscanf@plt>
lea    -0x290(%rbp),%rdi
call   1100 <atoi@plt>
cmp    -0x300(%rbp),%rax
jne    151e <print_procs_by_login+0x31e>
lea    -0x2d0(%rbp),%rdi
mov    -0x2e8(%rbp),%rax
mov    (%rax),%rdx
lea    0xc4c(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0x2d0(%rbp),%rdi
mov    0x2bdd(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x2ec(%rbp)
cmp    $0xffffffff,%eax
je     1519 <print_procs_by_login+0x319>
lea    -0x250(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
mov    -0x2ec(%rbp),%edi
lea    -0x250(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %rax,-0x2f8(%rbp)
cmp    $0x0,%rax
je     1514 <print_procs_by_login+0x314>
cmpq   $0xffffffffffffffff,-0x2f8(%rbp)
ff
je     150f <print_procs_by_login+0x30f>
mov    -0x2e8(%rbp),%rax
mov    (%rax),%rsi
lea    0xbda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2f0(%rbp)
movslq -0x2f0(%rbp),%rax
cmp    -0x2f8(%rbp),%rax
jae    1501 <print_procs_by_login+0x301>
movslq -0x2f0(%rbp),%rax
movsbl -0x250(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    14cb <print_procs_by_login+0x2cb>
lea    0xb98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14e8 <print_procs_by_login+0x2e8>
movslq -0x2f0(%rbp),%rax
movsbl -0x250(%rbp,%rax,1),%esi
ff
lea    0xb78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14ed <print_procs_by_login+0x2ed>
mov    -0x2f0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2f0(%rbp)
jmp    148c <print_procs_by_login+0x28c>
lea    0xb1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1514 <print_procs_by_login+0x314>
jmp    1519 <print_procs_by_login+0x319>
jmp    151e <print_procs_by_login+0x31e>
jmp    1523 <print_procs_by_login+0x323>
xor    %eax,%eax
mov    %eax,%edi
lea    0xaf8(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x258(%rbp)
jmp    135d <print_procs_by_login+0x15d>
jmp    1544 <print_procs_by_login+0x344>
jmp    1566 <print_procs_by_login+0x366>
mov    0x2a88(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xafb(%rip),%rdi
call   10c0 <err_exit@plt>
mov    -0x2ec(%rbp),%edi
call   1060 <close@plt>
jmp    1576 <print_procs_by_login+0x376>
jmp    1298 <print_procs_by_login+0x98>
mov    -0x2e0(%rbp),%rdi
call   1070 <closedir@plt>
jmp    15a9 <print_procs_by_login+0x3a9>
mov    0x2a45(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xacb(%rip),%rdi
call   10c0 <err_exit@plt>
jmp    15be <print_procs_by_login+0x3be>
mov    -0x8(%rbp),%rsi
lea    0xacc(%rip),%rdi
call   10c0 <err_exit@plt>
add    $0x310,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_procs_by_login>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2e8,%rsp
mov    %rdi,%rbx
movb   $0x0,0xc(%rsp)
movl   $0x3a646955,0x8(%rsp)
3a
call   10c0 <getpwnam@plt>
test   %rax,%rax
je     14db <print_procs_by_login+0x2bb>
mov    %rax,%rbp
lea    0xdac(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe1d(%rip),%rdi
call   1040 <puts@plt>
mov    0x0(%rbp),%rax
mov    %rax,0x18(%rsp)
lea    0xd9b(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     14e7 <print_procs_by_login+0x2c7>
mov    %rax,%r13
mov    %rax,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     14c1 <print_procs_by_login+0x2a1>
mov    %rax,%r15
mov    %r13,0x10(%rsp)
jmp    12e9 <print_procs_by_login+0xc9>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xd8b(%rip),%rdi
mov    %rax,%rsi
call   10e0 <err_exit@plt>
mov    %r12d,%edi
call   1080 <close@plt>
mov    0x10(%rsp),%r13
mov    %r13,%rdi
call   10d0 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     14c1 <print_procs_by_login+0x2a1>
mov    (%r15),%rbx
mov    %rbx,%rdi
call   1120 <atoi@plt>
test   %rax,%rax
je     12d5 <print_procs_by_login+0xb5>
lea    0xa0(%rsp),%rbp
mov    %rbp,%rdi
lea    0xd15(%rip),%rsi
mov    %rbx,%rdx
call   1130 <sprintf@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
lea    0xd0d(%rip),%r14
lea    0x20(%rsp),%rbp
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     12d5 <print_procs_by_login+0xb5>
mov    %eax,%r12d
mov    %eax,%edi
lea    0xe0(%rsp),%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
cmp    $0xffffffffffffffff,%rax
je     12c8 <print_procs_by_login+0xa8>
test   %rax,%rax
je     12ab <print_procs_by_login+0x8b>
lea    0xe0(%rsp),%rdi
lea    0xcee(%rip),%rbx
mov    %rbx,%rsi
call   1110 <strtok@plt>
test   %rax,%rax
je     12c8 <print_procs_by_login+0xa8>
mov    %rax,%r13
jmp    13a6 <print_procs_by_login+0x186>
mov    $0xffffffff,%r12d
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbx,%rsi
call   1110 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
je     12c8 <print_procs_by_login+0xa8>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10f0 <sscanf@plt>
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
jne    1390 <print_procs_by_login+0x170>
mov    %r13,%rdi
lea    0xc5e(%rip),%rsi
mov    %rbp,%rdx
lea    0x40(%rsp),%rbp
mov    %rbp,%rcx
xor    %eax,%eax
call   10f0 <sscanf@plt>
mov    %rbp,%rdi
lea    0x20(%rsp),%rbp
call   1120 <atoi@plt>
cmp    0x18(%rsp),%rax
jne    1390 <print_procs_by_login+0x170>
mov    (%r15),%rdx
lea    0x60(%rsp),%r12
mov    %r12,%rdi
lea    0xc2c(%rip),%rsi
call   1130 <sprintf@plt>
mov    0x2bd2(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     1384 <print_procs_by_login+0x164>
mov    %eax,%r12d
lea    0xe0(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
mov    %rax,%rbp
add    $0xffffffffffffffff,%rax
cmp    $0xfffffffffffffffd,%rax
ja     14a9 <print_procs_by_login+0x289>
mov    (%r15),%rsi
lea    0xbdd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %ebx,%ebx
mov    $0x20,%r14d
nopl   0x0(%rax)
movzbl 0xe0(%rsp,%rbx,1),%eax
test   %al,%al
cmove  %r14d,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1480 <print_procs_by_login+0x260>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xbac(%rip),%rbx
lea    0xb7c(%rip),%r14
lea    0x20(%rsp),%rbp
jmp    1390 <print_procs_by_login+0x170>
mov    %r13,%rdi
call   1090 <closedir@plt>
add    $0x2e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb92(%rip),%rdi
mov    %rbx,%rsi
jmp    14ff <print_procs_by_login+0x2df>
mov    0x2aea(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xb62(%rip),%rdi
mov    %rax,%rsi
add    $0x2e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10e0 <err_exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i64 }
%struct.dirent = type { i8* }
@__const.print_procs_by_login.uid_str = [5 x i8] c"Uid:\00"
@.str = [21 x i8] c"Processes run by %s\0A\00"
@.str.1 = [14 x i8] c"\0APID COMMAND\0A\00"
@.str.2 = [6 x i8] c"/proc\00"
@.str.3 = [16 x i8] c"/proc/%s/status\00"
@O_RDONLY = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [6 x i8] c"%s %s\00"
@.str.7 = [17 x i8] c"/proc/%s/cmdline\00"
@.str.8 = [4 x i8] c"%s \00"
@.str.9 = [2 x i8] c" \00"
@.str.10 = [3 x i8] c"%c\00"
@.str.11 = [19 x i8] c"Error on read, %s\0A\00"
@errno = global i32 0
@.str.12 = [22 x i8] c"Error on opendir, %s\0A\00"
@.str.13 = [19 x i8] c"Invalid login, %s\0A\00"
define void @print_procs_by_login(i8* %0) {
%2 = alloca i8*
%3 = alloca [64 x i8]
%4 = alloca [512 x i8]
%5 = alloca i8*
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = alloca [64 x i8]
%9 = alloca %struct.passwd*
%10 = alloca i32*
%11 = alloca %struct.dirent*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
%16 = alloca [5 x i8]
store i8* %0, i8** %2
%17 = bitcast [5 x i8]* %16 to i8*
%18 = load i8*, i8** %2
%19 = call %struct.passwd* @getpwnam(i8* %18)
store %struct.passwd* %19, %struct.passwd** %9
%20 = icmp ne %struct.passwd* %19, null
br i1 %20, label %21, label %161
21: ; preds = %1
%22 = load i8*, i8** %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = load %struct.passwd*, %struct.passwd** %9
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %25, i32 0, i32 0
%27 = load i64, i64* %26
store i64 %27, i64* %15
%28 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %10
%29 = load i32*, i32** %10
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %156
31: ; preds = %21
br label %32
32: ; preds = %152, %31
%33 = load i32*, i32** %10
%34 = call %struct.dirent* @readdir(i32* %33)
store %struct.dirent* %34, %struct.dirent** %11
%35 = icmp ne %struct.dirent* %34, null
br i1 %35, label %36, label %153
36: ; preds = %32
%37 = load %struct.dirent*, %struct.dirent** %11
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 0
%39 = load i8*, i8** %38
%40 = call i64 @atoi(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %152
42: ; preds = %36
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%44 = load %struct.dirent*, %struct.dirent** %11
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%49 = load i32, i32* @O_RDONLY
%50 = call i32 @open(i8* %48, i32 %49)
store i32 %50, i32* %12
%51 = load i32, i32* %12
%52 = icmp ne i32 %51, -1
br i1 %52, label %53, label %151
53: ; preds = %42
%54 = load i32, i32* %12
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%56 = call i64 @read(i32 %54, i8* %55, i32 512)
store i64 %56, i64* %14
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %144
58: ; preds = %53
%59 = load i64, i64* %14
%60 = icmp ne i64 %59, -1
br i1 %60, label %61, label %143
61: ; preds = %58
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%63 = call i8* @strtok(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %63, i8** %5
br label %64
64: ; preds = %140, %61
%65 = load i8*, i8** %5
%66 = icmp ne i8* %65, null
br i1 %66, label %67, label %142
67: ; preds = %64
%68 = load i8*, i8** %5
%69 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%70 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %69)
%71 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%72 = getelementptr inbounds [5 x i8], [5 x i8]* %16, i64 0, i64 0
%73 = call i64 @strcmp(i8* %71, i8* %72)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %140
75: ; preds = %67
%76 = load i8*, i8** %5
%77 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%78 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%79 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %76, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %77, i8* %78)
%80 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%81 = call i64 @atoi(i8* %80)
%82 = load i64, i64* %15
%83 = icmp eq i64 %81, %82
br i1 %83, label %84, label %139
84: ; preds = %75
%85 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%86 = load %struct.dirent*, %struct.dirent** %11
%87 = getelementptr inbounds %struct.dirent, %struct.dirent* %86, i32 0, i32 0
%88 = load i8*, i8** %87
%89 = call i32 @sprintf(i8* %85, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %88)
%90 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%91 = load i32, i32* @O_RDONLY
%92 = call i32 @open(i8* %90, i32 %91)
store i32 %92, i32* %12
%93 = icmp ne i32 %92, -1
br i1 %93, label %94, label %138
94: ; preds = %84
%95 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%96 = call i32 @memset(i8* %95, i32 0, i32 512)
%97 = load i32, i32* %12
%98 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%99 = call i64 @read(i32 %97, i8* %98, i32 512)
store i64 %99, i64* %14
%100 = icmp ne i64 %99, 0
br i1 %100, label %101, label %137
101: ; preds = %94
%102 = load i64, i64* %14
%103 = icmp ne i64 %102, -1
br i1 %103, label %104, label %136
104: ; preds = %101
%105 = load %struct.dirent*, %struct.dirent** %11
%106 = getelementptr inbounds %struct.dirent, %struct.dirent* %105, i32 0, i32 0
%107 = load i8*, i8** %106
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %107)
store i32 0, i32* %13
br label %109
109: ; preds = %131, %104
%110 = load i32, i32* %13
%111 = sext i32 %110 to i64
%112 = load i64, i64* %14
%113 = icmp ult i64 %111, %112
br i1 %113, label %114, label %134
114: ; preds = %109
%115 = load i32, i32* %13
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %116
%118 = load i8, i8* %117
%119 = sext i8 %118 to i32
%120 = icmp eq i32 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %114
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %130
123: ; preds = %114
%124 = load i32, i32* %13
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %125
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %128)
br label %130
130: ; preds = %123, %121
br label %131
131: ; preds = %130
%132 = load i32, i32* %13
%133 = add nsw i32 %132, 1
store i32 %133, i32* %13
br label %109
134: ; preds = %109
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %136
136: ; preds = %134, %101
br label %137
137: ; preds = %136, %94
br label %138
138: ; preds = %137, %84
br label %139
139: ; preds = %138, %75
br label %140
140: ; preds = %139, %67
%141 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %141, i8** %5
br label %64
142: ; preds = %64
br label %143
143: ; preds = %142, %58
br label %148
144: ; preds = %53
%145 = load i32, i32* @errno
%146 = call i8* @strerror(i32 %145)
%147 = call i32 @err_exit(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %146)
br label %148
148: ; preds = %144, %143
%149 = load i32, i32* %12
%150 = call i32 @close(i32 %149)
br label %151
151: ; preds = %148, %42
br label %152
152: ; preds = %151, %36
br label %32
153: ; preds = %32
%154 = load i32*, i32** %10
%155 = call i32 @closedir(i32* %154)
br label %160
156: ; preds = %21
%157 = load i32, i32* @errno
%158 = call i8* @strerror(i32 %157)
%159 = call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %158)
br label %160
160: ; preds = %156, %153
br label %164
161: ; preds = %1
%162 = load i8*, i8** %2
%163 = call i32 @err_exit(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i8* %162)
br label %164
164: ; preds = %161, %160
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i64 }
%struct.dirent = type { i8* }
@__const.print_procs_by_login.uid_str = [5 x i8] c"Uid:\00"
@.str = [21 x i8] c"Processes run by %s\0A\00"
@.str.2 = [6 x i8] c"/proc\00"
@.str.3 = [16 x i8] c"/proc/%s/status\00"
@O_RDONLY = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [6 x i8] c"%s %s\00"
@.str.7 = [17 x i8] c"/proc/%s/cmdline\00"
@.str.8 = [4 x i8] c"%s \00"
@.str.11 = [19 x i8] c"Error on read, %s\0A\00"
@errno = global i32 0
@.str.12 = [22 x i8] c"Error on opendir, %s\0A\00"
@.str.13 = [19 x i8] c"Invalid login, %s\0A\00"
@str = [13 x i8] c"\0APID COMMAND\00"
define void @print_procs_by_login(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [512 x i8]
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
%6 = alloca [64 x i8]
%7 = alloca [5 x i8]
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%14 = tail call %struct.passwd* @getpwnam(i8* %0)
%15 = icmp eq %struct.passwd* %14, null
br i1 %15, label %98, label %16
16: ; preds = %1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%19 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i64 0, i32 0
%20 = load i64, i64* %19
%21 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %94, label %23
23: ; preds = %16
%24 = call %struct.dirent* @readdir(i32* %21)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %92, label %26
26: ; preds = %23, %89
%27 = phi %struct.dirent* [ %90, %89 ], [ %24, %23 ]
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i64 0, i32 0
%29 = load i8*, i8** %28
%30 = call i64 @atoi(i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %89, label %32
32: ; preds = %26
%33 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* %8, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %89, label %37
37: ; preds = %32
%38 = call i64 @read(i32 %35, i8* %9, i32 512)
switch i64 %38, label %39 [
i64 0, label %82
i64 -1, label %86
]
39: ; preds = %37
%40 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i8* %40, null
br i1 %41, label %86, label %42
42: ; preds = %39, %78
%43 = phi i8* [ %80, %78 ], [ %40, %39 ]
%44 = phi i32 [ %79, %78 ], [ %35, %39 ]
%45 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%46 = call i64 @strcmp(i8* %10, i8* %13)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %78
48: ; preds = %42
%49 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %10, i8* %11)
%50 = call i64 @atoi(i8* %11)
%51 = icmp eq i64 %50, %20
br i1 %51, label %52, label %78
52: ; preds = %48
%53 = load i8*, i8** %28
%54 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %53)
%55 = load i32, i32* @O_RDONLY
%56 = call i32 @open(i8* %12, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %78, label %58
58: ; preds = %52
%59 = call i32 @memset(i8* %9, i32 0, i32 512)
%60 = call i64 @read(i32 %56, i8* %9, i32 512)
%61 = add i64 %60, -1
%62 = icmp ult i64 %61, -2
br i1 %62, label %63, label %78
63: ; preds = %58
%64 = load i8*, i8** %28
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %63, %66
%67 = phi i64 [ 0, %63 ], [ %74, %66 ]
%68 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = icmp eq i8 %69, 0
%71 = select i1 %70, i8 32, i8 %69
%72 = sext i8 %71 to i32
%73 = call i32 @putchar(i32 %72)
%74 = add nuw i64 %67, 1
%75 = icmp eq i64 %74, %60
br i1 %75, label %76, label %66
76: ; preds = %66
%77 = call i32 @putchar(i32 10)
br label %78
78: ; preds = %48, %58, %76, %52, %42
%79 = phi i32 [ %56, %76 ], [ %56, %58 ], [ -1, %52 ], [ %44, %48 ], [ %44, %42 ]
%80 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%81 = icmp eq i8* %80, null
br i1 %81, label %86, label %42
82: ; preds = %37
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 @err_exit(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i8* %84)
br label %86
86: ; preds = %78, %39, %37, %82
%87 = phi i32 [ %35, %82 ], [ %35, %37 ], [ %35, %39 ], [ %79, %78 ]
%88 = call i32 @close(i32 %87)
br label %89
89: ; preds = %32, %86, %26
%90 = call %struct.dirent* @readdir(i32* %21)
%91 = icmp eq %struct.dirent* %90, null
br i1 %91, label %92, label %26
92: ; preds = %89, %23
%93 = call i32 @closedir(i32* %21)
br label %100
94: ; preds = %16
%95 = load i32, i32* @errno
%96 = tail call i8* @strerror(i32 %95)
%97 = tail call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* %96)
br label %100
98: ; preds = %1
%99 = tail call i32 @err_exit(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i8* %0)
br label %100
100: ; preds = %92, %94, %98
ret void
}