#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
char *basename(char *);
int /*<<< orphan*/ debugMsg(char *);
char *readFile(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ stat(char const *, struct stat *);
char *strstr(char *, char *);
int isActive(int pid) {
  debugMsg("isActive() ...");
  if (pid == 0) {
    return 1;
  }
  const char *dir_nya;
  char pid_dir[512];
  char cmd_line_proc[512];
  sprintf(pid_dir, "/proc/%d", pid);
  dir_nya = pid_dir;
  sprintf(cmd_line_proc, "%s/cmdline", dir_nya);
  struct stat sb;
  debugMsg("isActive() ... ok ...");
  if (stat(dir_nya, &sb) == 0 && S_ISDIR(sb.st_mode)) {
    char *cmdline_str = readFile((char *)cmd_line_proc);
    char *lbr_basename = basename("/usr/bin/linuxBr");
    char *fnd_str = strstr(cmdline_str, lbr_basename);
    if (fnd_str == NULL) {
      return 1;
    } else {
      return 0;
    }
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<isActive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
lea    0xe7b(%rip),%rdi
call   1040 <debugMsg@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11a0 <isActive+0x30>
movl   $0x1,-0x4(%rbp)
jmp    1284 <isActive+0x114>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    0xe40(%rip),%rdi
call   1040 <debugMsg@plt>
mov    -0x10(%rbp),%rdi
lea    -0x418(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    127d <isActive+0x10d>
mov    -0x418(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     127d <isActive+0x10d>
lea    -0x410(%rbp),%rdi
call   1080 <readFile@plt>
mov    %rax,-0x420(%rbp)
lea    0xe08(%rip),%rdi
call   1050 <basename@plt>
mov    %rax,-0x428(%rbp)
mov    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    1271 <isActive+0x101>
movl   $0x1,-0x4(%rbp)
jmp    1284 <isActive+0x114>
movl   $0x0,-0x4(%rbp)
jmp    1284 <isActive+0x114>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isActive>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %edi,%ebx
lea    0xe7d(%rip),%rdi
call   1040 <debugMsg@plt>
test   %ebx,%ebx
je     1220 <isActive+0xb0>
lea    0xe78(%rip),%rsi
lea    0x210(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xe66(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xe5b(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1060 <stat@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1225 <isActive+0xb5>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
je     1225 <isActive+0xb5>
lea    0x10(%rsp),%rdi
call   1080 <readFile@plt>
mov    %rax,%rbx
lea    0xe33(%rip),%rdi
call   1050 <basename@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1090 <strstr@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
jmp    1225 <isActive+0xb5>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [15 x i8] c"isActive() ...\00"
@.str.1 = [9 x i8] c"/proc/%d\00"
@.str.2 = [11 x i8] c"%s/cmdline\00"
@.str.3 = [22 x i8] c"isActive() ... ok ...\00"
@.str.4 = [17 x i8] c"/usr/bin/linuxBr\00"
define i32 @isActive(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 %0, i32* %3
%11 = call i32 @debugMsg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 1, i32* %2
br label %44
15: ; preds = %1
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%17 = load i32, i32* %3
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
store i8* %19, i8** %4
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 @debugMsg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%24 = load i8*, i8** %4
%25 = call i64 @stat(i8* %24, %struct.stat* %7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %15
%28 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i64 @S_ISDIR(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %27
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%34 = call i8* @readFile(i8* %33)
store i8* %34, i8** %8
%35 = call i8* @basename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i8* %35, i8** %9
%36 = load i8*, i8** %8
%37 = load i8*, i8** %9
%38 = call i8* @strstr(i8* %36, i8* %37)
store i8* %38, i8** %10
%39 = load i8*, i8** %10
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %42
41: ; preds = %32
store i32 1, i32* %2
br label %44
42: ; preds = %32
store i32 0, i32* %2
br label %44
43: ; preds = %27, %15
store i32 1, i32* %2
br label %44
44: ; preds = %43, %42, %41, %14
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"isActive() ...\00"
@.str.1 = [9 x i8] c"/proc/%d\00"
@.str.2 = [11 x i8] c"%s/cmdline\00"
@.str.3 = [22 x i8] c"isActive() ... ok ...\00"
@.str.4 = [17 x i8] c"/usr/bin/linuxBr\00"
define i32 @isActive(i32 %0) {
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = alloca %struct.stat
%5 = tail call i32 @debugMsg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %0, 0
br i1 %6, label %29, label %7
7: ; preds = %1
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%12 = bitcast %struct.stat* %4 to i8*
%13 = call i32 @debugMsg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%14 = call i64 @stat(i8* %8, %struct.stat* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %7
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %16
%22 = call i8* @readFile(i8* %9)
%23 = call i8* @basename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%24 = call i8* @strstr(i8* dereferenceable(1) %22, i8* dereferenceable(1) %23)
%25 = icmp eq i8* %24, null
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %7, %16, %21
%28 = phi i32 [ %26, %21 ], [ 1, %16 ], [ 1, %7 ]
br label %29
29: ; preds = %1, %27
%30 = phi i32 [ %28, %27 ], [ 1, %1 ]
ret i32 %30
}