#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int generic_check_for_running_stress() {
  FILE *fp;
  char pid[10];
  fp = popen("pgrep -x stress", "r");
  if (fgets(pid, 10, fp) == NULL) {
    fclose(fp);
    return 0;
  } else {
    fclose(fp);
    return 1000;
  }
}


x86 assembly (clang, -O0):
<generic_check_for_running_stress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
lea    0xeca(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1a(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1180 <generic_check_for_running_stress+0x50>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1190 <generic_check_for_running_stress+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x3e8,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_check_for_running_stress>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xec2(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rbx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ecx,%ecx
test   %r14,%r14
mov    $0x3e8,%eax
cmove  %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"pgrep -x stress\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @generic_check_for_running_stress() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [10 x i8]
%4 = call i32* @popen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = load i32*, i32** %2
%7 = call i32* @fgets(i8* %5, i32 10, i32* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @fclose(i32* %10)
store i32 0, i32* %1
br label %15
12: ; preds = %0
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
store i32 1000, i32* %1
br label %15
15: ; preds = %12, %9
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [16 x i8] c"pgrep -x stress\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @generic_check_for_running_stress() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32* @fgets(i8* %2, i32 10, i32* %3)
%5 = icmp eq i32* %4, null
%6 = call i32 @fclose(i32* %3)
%7 = select i1 %5, i32 0, i32 1000
ret i32 %7
}