#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 countlist(void **);
int find_pid_in_list(scalar_t__ *, scalar_t__);
int /*<<< orphan*/ free(scalar_t__ *);
scalar_t__ grab_parent_of_pid(scalar_t__);
scalar_t__ *pids_of_exe(char const *);
int num_procs_of_exe_no_children(const char *exe) {
  pid_t *pids = pids_of_exe(exe);
  int ret;
  ret = countlist((void **)pids);
  if (ret > 1) {
    pid_t *cur, ppid;
    int pos;
    for (cur = pids; *cur; cur++) {
      ppid = grab_parent_of_pid(*cur);
      pos = find_pid_in_list(pids, ppid);
      if (pos >= 0 && *cur != ppid)
        ret--;
    }
  }
  if (pids)
    free(pids);
  return ret;
}


x86 assembly (clang, -O0):
<num_procs_of_exe_no_children>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <pids_of_exe@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <countlist@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11f4 <num_procs_of_exe_no_children+0xa4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ef <num_procs_of_exe_no_children+0x9f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1060 <grab_parent_of_pid@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <find_pid_in_list@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11d9 <num_procs_of_exe_no_children+0x89>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
je     11d9 <num_procs_of_exe_no_children+0x89>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11de <num_procs_of_exe_no_children+0x8e>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1187 <num_procs_of_exe_no_children+0x37>
jmp    11f4 <num_procs_of_exe_no_children+0xa4>
cmpq   $0x0,-0x10(%rbp)
je     1208 <num_procs_of_exe_no_children+0xb8>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_procs_of_exe_no_children>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1070 <pids_of_exe@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <countlist@plt>
mov    %eax,%r15d
cmp    $0x2,%eax
jl     11b2 <num_procs_of_exe_no_children+0x62>
mov    (%r14),%rdi
test   %rdi,%rdi
je     11b7 <num_procs_of_exe_no_children+0x67>
lea    0x8(%r14),%rbp
jmp    118d <num_procs_of_exe_no_children+0x3d>
nopl   (%rax)
mov    0x0(%rbp),%rdi
add    $0x8,%rbp
test   %rdi,%rdi
je     11b2 <num_procs_of_exe_no_children+0x62>
call   1060 <grab_parent_of_pid@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <find_pid_in_list@plt>
test   %eax,%eax
js     1180 <num_procs_of_exe_no_children+0x30>
xor    %eax,%eax
cmp    %rbx,-0x8(%rbp)
setne  %al
sub    %eax,%r15d
jmp    1180 <num_procs_of_exe_no_children+0x30>
test   %r14,%r14
je     11bf <num_procs_of_exe_no_children+0x6f>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @num_procs_of_exe_no_children(i8* %0) {
%2 = alloca i8*
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i64* @pids_of_exe(i8* %8)
store i64* %9, i64** %3
%10 = load i64*, i64** %3
%11 = bitcast i64* %10 to i8**
%12 = call i32 @countlist(i8** %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %43
15: ; preds = %1
%16 = load i64*, i64** %3
store i64* %16, i64** %5
br label %17
17: ; preds = %39, %15
%18 = load i64*, i64** %5
%19 = load i64, i64* %18
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %42
21: ; preds = %17
%22 = load i64*, i64** %5
%23 = load i64, i64* %22
%24 = call i64 @grab_parent_of_pid(i64 %23)
store i64 %24, i64* %6
%25 = load i64*, i64** %3
%26 = load i64, i64* %6
%27 = call i32 @find_pid_in_list(i64* %25, i64 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %21
%31 = load i64*, i64** %5
%32 = load i64, i64* %31
%33 = load i64, i64* %6
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* %4
%37 = add nsw i32 %36, -1
store i32 %37, i32* %4
br label %38
38: ; preds = %35, %30, %21
br label %39
39: ; preds = %38
%40 = load i64*, i64** %5
%41 = getelementptr inbounds i64, i64* %40, i32 1
store i64* %41, i64** %5
br label %17
42: ; preds = %17
br label %43
43: ; preds = %42, %1
%44 = load i64*, i64** %3
%45 = icmp ne i64* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i64*, i64** %3
%48 = call i32 @free(i64* %47)
br label %49
49: ; preds = %46, %43
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
define i32 @num_procs_of_exe_no_children(i8* %0) {
%2 = tail call i64* @pids_of_exe(i8* %0)
%3 = bitcast i64* %2 to i8**
%4 = tail call i32 @countlist(i8** %3)
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %26
6: ; preds = %1
%7 = load i64, i64* %2
%8 = icmp eq i64 %7, 0
br i1 %8, label %29, label %9
9: ; preds = %6, %21
%10 = phi i64 [ %24, %21 ], [ %7, %6 ]
%11 = phi i32 [ %22, %21 ], [ %4, %6 ]
%12 = phi i64* [ %23, %21 ], [ %2, %6 ]
%13 = tail call i64 @grab_parent_of_pid(i64 %10)
%14 = tail call i32 @find_pid_in_list(i64* %2, i64 %13)
%15 = icmp sgt i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = load i64, i64* %12
%18 = icmp ne i64 %17, %13
%19 = sext i1 %18 to i32
%20 = add nsw i32 %11, %19
br label %21
21: ; preds = %16, %9
%22 = phi i32 [ %11, %9 ], [ %20, %16 ]
%23 = getelementptr inbounds i64, i64* %12, i64 1
%24 = load i64, i64* %23
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %9
26: ; preds = %21, %1
%27 = phi i32 [ %4, %1 ], [ %22, %21 ]
%28 = icmp eq i64* %2, null
br i1 %28, label %32, label %29
29: ; preds = %6, %26
%30 = phi i32 [ %27, %26 ], [ %4, %6 ]
%31 = tail call i32 @free(i64* %2)
br label %32
32: ; preds = %29, %26
%33 = phi i32 [ %30, %29 ], [ %27, %26 ]
ret i32 %33
}