#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ log2file(char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int isProcessExist(char *processName) {
  char buf[1024];
  char command[1024];
  FILE *fp;
  int ret = 0;
  sprintf(command, "ps -c | grep %s", processName);
  if ((fp = popen(command, "r")) == NULL) {
    printf("popen failed\n");
    exit(1);
  }
  if ((fgets(buf, 1024, fp)) != NULL) {
    ret = 1;
    log2file("ps info:%s\n", buf);
  } else {
    log2file("process: %s not running.\n", processName);
  }
  pclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<isProcessExist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x81c(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x810(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x818(%rbp)
cmp    $0x0,%rax
jne    11da <isProcessExist+0x6a>
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x410(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     121e <isProcessExist+0xae>
movl   $0x1,-0x81c(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xe0c(%rip),%rdi
call   1060 <log2file@plt>
jmp    122e <isProcessExist+0xbe>
mov    -0x8(%rbp),%rsi
lea    0xe03(%rip),%rdi
call   1060 <log2file@plt>
mov    -0x818(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x81c(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isProcessExist>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%r14
lea    0xe7b(%rip),%rsi
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     1201 <isProcessExist+0x91>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11da <isProcessExist+0x6a>
lea    0xe47(%rip),%rdi
mov    %rsp,%rsi
call   1060 <log2file@plt>
mov    $0x1,%ebp
jmp    11eb <isProcessExist+0x7b>
lea    0xe3d(%rip),%rdi
mov    %r14,%rsi
call   1060 <log2file@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %ebp,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"ps -c | grep %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"popen failed\0A\00"
@.str.3 = [12 x i8] c"ps info:%s\0A\00"
@.str.4 = [26 x i8] c"process: %s not running.\0A\00"
define i32 @isProcessExist(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %6
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i32* @fgets(i8* %17, i32 1024, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
store i32 1, i32* %6
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = call i32 @log2file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %27
24: ; preds = %16
%25 = load i8*, i8** %2
%26 = call i32 @log2file(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %21
%28 = load i32*, i32** %5
%29 = call i32 @pclose(i32* %28)
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
@.str = [16 x i8] c"ps -c | grep %s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"ps info:%s\0A\00"
@.str.4 = [26 x i8] c"process: %s not running.\0A\00"
@str = [13 x i8] c"popen failed\00"
define i32 @isProcessExist(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = call i32* @fgets(i8* %4, i32 1024, i32* %7)
%14 = icmp eq i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @log2file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %19
17: ; preds = %12
%18 = call i32 @log2file(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ 1, %15 ], [ 0, %17 ]
%21 = call i32 @pclose(i32* %7)
ret i32 %20
}