#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__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int execl(char *, char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ waitpid(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
void printStats() {
  pid_t procid = fork();
  if (procid == 0) {
    if (execl("/bin/ps", "/bin/ps", "-C", "memsched", "-o",
              "cputime,etime,pmem,nice,sched,size,rss,vsz",
              (char *)NULL) == -1) {
      printf("Error in execl(): %s\n", strerror(errno));
      exit(1);
    }
  } else if (procid > 0) {
    if (waitpid(procid, 0, 0) != procid) {
      printf("Error in waitpid(): %s\n", strerror(errno));
    }
  } else {
    printf("Error in fork(): %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<printStats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11e8 <printStats+0x88>
lea    0xe7b(%rip),%rsi
lea    0xe7c(%rip),%rdx
lea    0xe78(%rip),%rcx
lea    0xe7a(%rip),%r8
lea    0xe76(%rip),%r9
xor    %eax,%eax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
call   1070 <execl@plt>
cmp    $0xffffffff,%eax
jne    11e3 <printStats+0x83>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    124e <printStats+0xee>
cmpq   $0x0,-0x8(%rbp)
jle    122c <printStats+0xcc>
mov    -0x8(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <waitpid@plt>
cmp    -0x8(%rbp),%rax
je     1227 <printStats+0xc7>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    1249 <printStats+0xe9>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
jmp    124e <printStats+0xee>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printStats>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1190 <printStats+0x30>
jle    11ce <printStats+0x6e>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    %rbx,%rax
je     11c8 <printStats+0x68>
lea    0xeca(%rip),%rbx
jmp    11d5 <printStats+0x75>
movq   $0x0,(%rsp)
lea    0xe61(%rip),%rdi
lea    0xe62(%rip),%rdx
lea    0xe5e(%rip),%rcx
lea    0xe60(%rip),%r8
lea    0xe5c(%rip),%r9
mov    %rdi,%rsi
call   1070 <execl@plt>
cmp    $0xffffffff,%eax
je     11f3 <printStats+0x93>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe9b(%rip),%rbx
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe3a(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/ps\00"
@.str.1 = [3 x i8] c"-C\00"
@.str.2 = [9 x i8] c"memsched\00"
@.str.3 = [3 x i8] c"-o\00"
@.str.4 = [43 x i8] c"cputime,etime,pmem,nice,sched,size,rss,vsz\00"
@.str.5 = [22 x i8] c"Error in execl(): %s\0A\00"
@errno = global i32 0
@.str.6 = [24 x i8] c"Error in waitpid(): %s\0A\00"
@.str.7 = [21 x i8] c"Error in fork(): %s\0A\00"
define void @printStats() {
%1 = alloca i64
%2 = call i64 (...) @fork()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* null)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %5
br label %32
14: ; preds = %0
%15 = load i64, i64* %1
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i64, i64* %1
%19 = call i64 @waitpid(i64 %18, i32 0, i32 0)
%20 = load i64, i64* %1
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %17
br label %31
27: ; preds = %14
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %26
br label %32
32: ; preds = %31, %13
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/ps\00"
@.str.1 = [3 x i8] c"-C\00"
@.str.2 = [9 x i8] c"memsched\00"
@.str.3 = [3 x i8] c"-o\00"
@.str.4 = [43 x i8] c"cputime,etime,pmem,nice,sched,size,rss,vsz\00"
@.str.5 = [22 x i8] c"Error in execl(): %s\0A\00"
@errno = global i32 0
@.str.6 = [24 x i8] c"Error in waitpid(): %s\0A\00"
@.str.7 = [21 x i8] c"Error in fork(): %s\0A\00"
define void @printStats() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %11
3: ; preds = %0
%4 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* null)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %21
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = icmp sgt i64 %1, 0
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = tail call i64 @waitpid(i64 %1, i32 0, i32 0)
%15 = icmp eq i64 %14, %1
br i1 %15, label %21, label %16
16: ; preds = %11, %13
%17 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), %13 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), %11 ]
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 @printf(i8* %17, i8* %19)
br label %21
21: ; preds = %16, %13, %3
ret void
}