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

/* Variables and functions */
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ _exit(int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fork();
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
int waitpid(scalar_t__, int *, int /*<<< orphan*/);
int cancel_lru_locks(char *prefix) {
  char cmd[256], line[1024];
  FILE *file;
  pid_t child;
  int len = 1024, rc = 0;
  child = fork();
  if (child < 0)
    return -errno;
  else if (child) {
    int status;
    rc = waitpid(child, &status, WNOHANG);
    if (rc == child)
      rc = 0;
    return rc;
  }
  if (prefix)
    sprintf(cmd, "ls /proc/fs/lustre/ldlm/namespaces/*-%s-*/lru_size", prefix);
  else
    sprintf(cmd, "ls /proc/fs/lustre/ldlm/namespaces/*/lru_size");
  file = popen(cmd, "r");
  if (file == NULL) {
    perror("popen()");
    return -errno;
  }
  while (fgets(line, len, file)) {
    FILE *f;
    if (!strlen(line))
      continue;
    *(line + strlen(line) - 1) = '\0';
    f = fopen(line, "w");
    if (f == NULL) {
      perror("fopen()");
      rc = -errno;
      break;
    }
    rc = fwrite("clear", strlen("clear") + 1, 1, f);
    if (rc < 1) {
      perror("fwrite()");
      rc = -errno;
      fclose(f);
      break;
    }
    fclose(f);
  }
  pclose(file);
  _exit(rc);
}


x86 assembly (clang, -O0):
<cancel_lru_locks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x400,-0x524(%rbp)
movl   $0x0,-0x528(%rbp)
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0x520(%rbp)
cmpq   $0x0,-0x520(%rbp)
jge    1212 <cancel_lru_locks+0x52>
xor    %eax,%eax
mov    0x2dd0(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    142c <cancel_lru_locks+0x26c>
cmpq   $0x0,-0x520(%rbp)
je     126e <cancel_lru_locks+0xae>
mov    -0x520(%rbp),%rdi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
lea    -0x52c(%rbp),%rsi
call   1080 <waitpid@plt>
mov    %eax,-0x528(%rbp)
movslq -0x528(%rbp),%rax
cmp    -0x520(%rbp),%rax
jne    1260 <cancel_lru_locks+0xa0>
movl   $0x0,-0x528(%rbp)
mov    -0x528(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    142c <cancel_lru_locks+0x26c>
jmp    1273 <cancel_lru_locks+0xb3>
cmpq   $0x0,-0x10(%rbp)
je     129c <cancel_lru_locks+0xdc>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
jmp    12b1 <cancel_lru_locks+0xf1>
lea    -0x110(%rbp),%rdi
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xdb8(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x518(%rbp)
cmpq   $0x0,-0x518(%rbp)
jne    12f8 <cancel_lru_locks+0x138>
lea    0xd81(%rip),%rdi
call   10b0 <perror@plt>
xor    %eax,%eax
mov    0x2cea(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    142c <cancel_lru_locks+0x26c>
jmp    12fd <cancel_lru_locks+0x13d>
lea    -0x510(%rbp),%rdi
mov    -0x524(%rbp),%esi
mov    -0x518(%rbp),%rdx
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1415 <cancel_lru_locks+0x255>
lea    -0x510(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    133a <cancel_lru_locks+0x17a>
jmp    12fd <cancel_lru_locks+0x13d>
lea    -0x510(%rbp),%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x511(%rbp,%rax,1)
lea    -0x510(%rbp),%rdi
lea    0xd0b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x538(%rbp)
cmpq   $0x0,-0x538(%rbp)
jne    139a <cancel_lru_locks+0x1da>
lea    0xcec(%rip),%rdi
call   10b0 <perror@plt>
xor    %eax,%eax
mov    0x2c4b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x528(%rbp)
jmp    1415 <cancel_lru_locks+0x255>
lea    0xcd2(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
add    $0x1,%esi
mov    -0x538(%rbp),%rcx
lea    0xcba(%rip),%rdi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    %eax,-0x528(%rbp)
cmpl   $0x1,-0x528(%rbp)
jge    1404 <cancel_lru_locks+0x244>
lea    0xc9c(%rip),%rdi
call   10b0 <perror@plt>
xor    %eax,%eax
mov    0x2bed(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x528(%rbp)
mov    -0x538(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1415 <cancel_lru_locks+0x255>
mov    -0x538(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12fd <cancel_lru_locks+0x13d>
mov    -0x518(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x528(%rbp),%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cancel_lru_locks>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x508,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
js     120d <cancel_lru_locks+0x4d>
je     122a <cancel_lru_locks+0x6a>
mov    %rax,%rbp
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
lea    0x100(%rsp),%rsi
mov    %rbp,%rdi
call   1080 <waitpid@plt>
movslq %eax,%rbx
xor    %eax,%eax
cmp    %rbx,%rbp
cmove  %eax,%ebx
jmp    1216 <cancel_lru_locks+0x56>
mov    0x2dc4(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x508,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r14,%r14
jne    1254 <cancel_lru_locks+0x94>
movups 0xe1b(%rip),%xmm0
movups %xmm0,0x1e(%rsp)
movups 0xe01(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xde5(%rip),%xmm0
movaps %xmm0,(%rsp)
jmp    1268 <cancel_lru_locks+0xa8>
lea    0xda5(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
lea    0xe08(%rip),%rsi
mov    %rsp,%rdi
call   1090 <popen@plt>
test   %rax,%rax
jne    1293 <cancel_lru_locks+0xd3>
lea    0xdde(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d49(%rip),%rax
xor    %ebx,%ebx
jmp    1214 <cancel_lru_locks+0x54>
mov    %rax,%rbx
lea    0x100(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     1381 <cancel_lru_locks+0x1c1>
lea    0x100(%rsp),%r14
lea    0xda3(%rip),%r15
lea    0xda6(%rip),%r12
jmp    12e8 <cancel_lru_locks+0x128>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1381 <cancel_lru_locks+0x1c1>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     12cf <cancel_lru_locks+0x10f>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,0xff(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1345 <cancel_lru_locks+0x185>
mov    %rax,%rbp
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r12,%rdi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10d0 <fwrite@plt>
test   %eax,%eax
jle    1360 <cancel_lru_locks+0x1a0>
mov    %eax,%r13d
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    12cf <cancel_lru_locks+0x10f>
lea    0xd1f(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c80(%rip),%rax
xor    %r13d,%r13d
sub    (%rax),%r13d
jmp    1381 <cancel_lru_locks+0x1c1>
lea    0xd12(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c65(%rip),%rax
xor    %r13d,%r13d
sub    (%rax),%r13d
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1060 <pclose@plt>
mov    %r13d,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@WNOHANG = global i32 0
@.str = [51 x i8] c"ls /proc/fs/lustre/ldlm/namespaces/*-%s-*/lru_size\00"
@.str.1 = [46 x i8] c"ls /proc/fs/lustre/ldlm/namespaces/*/lru_size\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"popen()\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [8 x i8] c"fopen()\00"
@.str.6 = [6 x i8] c"clear\00"
@.str.7 = [9 x i8] c"fwrite()\00"
define i32 @cancel_lru_locks(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i8* %0, i8** %3
store i32 1024, i32* %8
store i32 0, i32* %9
%12 = call i64 (...) @fork()
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i32, i32* @errno
%17 = sub nsw i32 0, %16
store i32 %17, i32* %2
br label %100
18: ; preds = %1
%19 = load i64, i64* %7
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i64, i64* %7
%23 = load i32, i32* @WNOHANG
%24 = call i32 @waitpid(i64 %22, i32* %10, i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = load i64, i64* %7
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 0, i32* %9
br label %30
30: ; preds = %29, %21
%31 = load i32, i32* %9
store i32 %31, i32* %2
br label %100
32: ; preds = %18
br label %33
33: ; preds = %32
%34 = load i8*, i8** %3
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%38 = load i8*, i8** %3
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %38)
br label %43
40: ; preds = %33
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %40, %36
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%45 = call i32* @popen(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %45, i32** %6
%46 = load i32*, i32** %6
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* @errno
%51 = sub nsw i32 0, %50
store i32 %51, i32* %2
br label %100
52: ; preds = %43
br label %53
53: ; preds = %92, %63, %52
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%55 = load i32, i32* %8
%56 = load i32*, i32** %6
%57 = call i64 @fgets(i8* %54, i32 %55, i32* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %95
59: ; preds = %53
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %59
br label %53
64: ; preds = %59
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%67 = call i32 @strlen(i8* %66)
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %65, i64 %68
%70 = getelementptr inbounds i8, i8* %69, i64 -1
store i8 0, i8* %70
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%72 = call i32* @fopen(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %72, i32** %11
%73 = load i32*, i32** %11
%74 = icmp eq i32* %73, null
br i1 %74, label %75, label %79
75: ; preds = %64
%76 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%77 = load i32, i32* @errno
%78 = sub nsw i32 0, %77
store i32 %78, i32* %9
br label %95
79: ; preds = %64
%80 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%81 = add nsw i32 %80, 1
%82 = load i32*, i32** %11
%83 = call i32 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %81, i32 1, i32* %82)
store i32 %83, i32* %9
%84 = load i32, i32* %9
%85 = icmp slt i32 %84, 1
br i1 %85, label %86, label %92
86: ; preds = %79
%87 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%88 = load i32, i32* @errno
%89 = sub nsw i32 0, %88
store i32 %89, i32* %9
%90 = load i32*, i32** %11
%91 = call i32 @fclose(i32* %90)
br label %95
92: ; preds = %79
%93 = load i32*, i32** %11
%94 = call i32 @fclose(i32* %93)
br label %53
95: ; preds = %86, %75, %53
%96 = load i32*, i32** %6
%97 = call i32 @pclose(i32* %96)
%98 = load i32, i32* %9
%99 = call i32 @_exit(i32 %98)
unreachable
100: ; preds = %48, %30, %15
%101 = load i32, i32* %2
ret i32 %101
}

LLVM IR (-O2):
@errno = global i32 0
@WNOHANG = global i32 0
@.str = [51 x i8] c"ls /proc/fs/lustre/ldlm/namespaces/*-%s-*/lru_size\00"
@.str.1 = [46 x i8] c"ls /proc/fs/lustre/ldlm/namespaces/*/lru_size\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"popen()\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [8 x i8] c"fopen()\00"
@.str.6 = [6 x i8] c"clear\00"
@.str.7 = [9 x i8] c"fwrite()\00"
define i32 @cancel_lru_locks(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = tail call i64 (...) @fork()
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = sub nsw i32 0, %10
br label %71
12: ; preds = %1
%13 = icmp eq i64 %7, 0
br i1 %13, label %21, label %14
14: ; preds = %12
%15 = bitcast i32* %4 to i8*
%16 = load i32, i32* @WNOHANG
%17 = call i32 @waitpid(i64 %7, i32* %4, i32 %16)
%18 = sext i32 %17 to i64
%19 = icmp eq i64 %7, %18
%20 = select i1 %19, i32 0, i32 %17
br label %71
21: ; preds = %12
%22 = icmp eq i8* %0, null
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %26
25: ; preds = %21
br label %26
26: ; preds = %25, %23
%27 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i64 @fgets(i8* %6, i32 1024, i32* %27)
%31 = icmp eq i64 %30, 0
br i1 %31, label %67, label %36
32: ; preds = %26
%33 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @errno
%35 = sub nsw i32 0, %34
br label %71
36: ; preds = %29, %63
%37 = phi i32 [ %64, %63 ], [ 0, %29 ]
%38 = call i32 @strlen(i8* %6)
%39 = icmp eq i32 %38, 0
br i1 %39, label %63, label %40
40: ; preds = %36
%41 = call i32 @strlen(i8* %6)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 -1
store i8 0, i8* %44
%45 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %51
47: ; preds = %40
%48 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32, i32* @errno
%50 = sub nsw i32 0, %49
br label %67
51: ; preds = %40
%52 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%53 = add nsw i32 %52, 1
%54 = call i32 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %53, i32 1, i32* %45)
%55 = icmp slt i32 %54, 1
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%58 = load i32, i32* @errno
%59 = sub nsw i32 0, %58
%60 = call i32 @fclose(i32* %45)
br label %67
61: ; preds = %51
%62 = call i32 @fclose(i32* %45)
br label %63
63: ; preds = %36, %61
%64 = phi i32 [ %54, %61 ], [ %37, %36 ]
%65 = call i64 @fgets(i8* %6, i32 1024, i32* %27)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %36
67: ; preds = %63, %29, %56, %47
%68 = phi i32 [ %59, %56 ], [ %50, %47 ], [ 0, %29 ], [ %64, %63 ]
%69 = call i32 @pclose(i32* %27)
%70 = call i32 @_exit(i32 %68)
unreachable
71: ; preds = %32, %14, %9
%72 = phi i32 [ %11, %9 ], [ %20, %14 ], [ %35, %32 ]
ret i32 %72
}