#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 fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ sys_error(char *, char *, int);
scalar_t__ system(char *);
int process_slots_in_use() {
  FILE *psfile;
  int usedslots;
  if (system("ps -e | wc -l > ps.out") < 0)
    sys_error("system failed",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/chenhuacai/ltp/refs/heads/cve/"
              "testcases/kernel/sched/sched_stress/sched_driver.c",
              372);
  if ((psfile = fopen("ps.out", "r")) == NULL) {
    exit(-1);
  }
  fscanf(psfile, "%d", &usedslots);
  if (fclose(psfile) == -1) {
    exit(-1);
  }
  if (system("/bin/rm ps.out") < 0)
    sys_error("system failed",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/chenhuacai/ltp/refs/heads/cve/"
              "testcases/kernel/sched/sched_stress/sched_driver.c",
              397);
  return (usedslots - 1);
}


x86 assembly (clang, -O0):
<process_slots_in_use>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1040 <system@plt>
cmp    $0x0,%rax
jge    1196 <process_slots_in_use+0x36>
lea    0xe92(%rip),%rdi
lea    0xe99(%rip),%rsi
mov    $0x174,%edx
call   1060 <sys_error@plt>
lea    0xe73(%rip),%rdi
lea    0xf2c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11c1 <process_slots_in_use+0x61>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xf06(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0xffffffff,%eax
jne    11f1 <process_slots_in_use+0x91>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xedd(%rip),%rdi
call   1040 <system@plt>
cmp    $0x0,%rax
jge    121f <process_slots_in_use+0xbf>
lea    0xe09(%rip),%rdi
lea    0xe10(%rip),%rsi
mov    $0x18d,%edx
call   1060 <sys_error@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_slots_in_use>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
call   1040 <system@plt>
test   %rax,%rax
jns    118e <process_slots_in_use+0x2e>
lea    0xe9a(%rip),%rdi
lea    0xea1(%rip),%rsi
mov    $0x174,%edx
call   1060 <sys_error@plt>
lea    0xe7b(%rip),%rdi
lea    0xf34(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1200 <process_slots_in_use+0xa0>
mov    %rax,%rbx
lea    0xf22(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0xffffffff,%eax
je     1200 <process_slots_in_use+0xa0>
lea    0xf04(%rip),%rdi
call   1040 <system@plt>
test   %rax,%rax
jns    11f3 <process_slots_in_use+0x93>
lea    0xe35(%rip),%rdi
lea    0xe3c(%rip),%rsi
mov    $0x18d,%edx
call   1060 <sys_error@plt>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"ps -e | wc -l > ps.out\00"
@.str.1 = [14 x i8] c"system failed\00"
@.str.2 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/chenhuacai/ltp/refs/heads/cve/testcases/kernel/sched/sched_stress/sched_driver.c\00"
@.str.3 = [7 x i8] c"ps.out\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [15 x i8] c"/bin/rm ps.out\00"
define i32 @process_slots_in_use() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i64 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @sys_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.2, i64 0, i64 0), i32 372)
br label %7
7: ; preds = %5, %0
%8 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %8, i32** %1
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %7
%13 = load i32*, i32** %1
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%15 = load i32*, i32** %1
%16 = call i32 @fclose(i32* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %12
%21 = call i64 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @sys_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.2, i64 0, i64 0), i32 397)
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %2
%27 = sub nsw i32 %26, 1
ret i32 %27
}

LLVM IR (-O2):
@.str = [23 x i8] c"ps -e | wc -l > ps.out\00"
@.str.1 = [14 x i8] c"system failed\00"
@.str.2 = [171 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/chenhuacai/ltp/refs/heads/cve/testcases/kernel/sched/sched_stress/sched_driver.c\00"
@.str.3 = [7 x i8] c"ps.out\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%d\00"
@.str.6 = [15 x i8] c"/bin/rm ps.out\00"
define i32 @process_slots_in_use() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @sys_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.2, i64 0, i64 0), i32 372)
br label %7
7: ; preds = %5, %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %7
%13 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%14 = call i32 @fclose(i32* %8)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %12
%19 = call i64 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @sys_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str.2, i64 0, i64 0), i32 397)
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* %1
%25 = add nsw i32 %24, -1
ret i32 %25
}