#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int snprintf(char *, int, char *);
void wc_processnum() {
  FILE *fp = NULL;
  char buf[128] = "";
  int rv;
  fp = popen("ps aux |grep 'auto_add_del$'"
             "|grep -v grep |wc -l",
             "r");
  if (fp == NULL) {
    return;
  }
  rv = snprintf(buf, sizeof(buf), "current process number:");
  fgets(buf + rv, sizeof(buf) - rv, fp);
  pclose(fp);
  printf("%s\n", buf);
}


x86 assembly (clang, -O0):
<wc_processnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movq   $0x0,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe73(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11ad <wc_processnum+0x4d>
jmp    1212 <wc_processnum+0xb2>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
lea    0xe73(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
movslq -0x94(%rbp),%rax
add    %rax,%rdi
movslq -0x94(%rbp),%rcx
mov    $0x80,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
call   1070 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1040 <pclose@plt>
lea    -0x90(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wc_processnum>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe74(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <popen@plt>
test   %rax,%rax
je     11e5 <wc_processnum+0x95>
mov    %rax,%rbx
lea    0xe8c(%rip),%rdx
mov    %rsp,%r14
mov    $0x80,%ebp
mov    %r14,%rdi
mov    $0x80,%esi
call   1050 <snprintf@plt>
cltq
lea    (%rsp,%rax,1),%rdi
sub    %eax,%ebp
mov    %ebp,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"ps aux |grep 'auto_add_del$'|grep -v grep |wc -l\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"current process number:\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @wc_processnum() {
%1 = alloca i32*
%2 = alloca [128 x i8]
%3 = alloca i32
store i32* null, i32** %1
%4 = bitcast [128 x i8]* %2 to i8*
%5 = call i32* @popen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
br label %26
9: ; preds = %0
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 128, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 %11, i32* %3
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = sub i64 128, %17
%19 = trunc i64 %18 to i32
%20 = load i32*, i32** %1
%21 = call i32 @fgets(i8* %15, i32 %19, i32* %20)
%22 = load i32*, i32** %1
%23 = call i32 @pclose(i32* %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %9, %8
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"ps aux |grep 'auto_add_del$'|grep -v grep |wc -l\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"current process number:\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @wc_processnum() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %13, label %5
5: ; preds = %0
%6 = call i32 @snprintf(i8* %2, i32 128, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %7
%9 = sub i32 128, %6
%10 = call i32 @fgets(i8* %8, i32 %9, i32* %3)
%11 = call i32 @pclose(i32* %3)
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %13
13: ; preds = %0, %5
ret void
}