#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    1210 <cancel_lru_locks+0x50>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1424 <cancel_lru_locks+0x264>
cmpq   $0x0,-0x520(%rbp)
je     126c <cancel_lru_locks+0xac>
mov    -0x520(%rbp),%rdi
mov    0x2dbc(%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    125e <cancel_lru_locks+0x9e>
movl   $0x0,-0x528(%rbp)
mov    -0x528(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1424 <cancel_lru_locks+0x264>
jmp    1271 <cancel_lru_locks+0xb1>
cmpq   $0x0,-0x10(%rbp)
je     129a <cancel_lru_locks+0xda>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
jmp    12af <cancel_lru_locks+0xef>
lea    -0x110(%rbp),%rdi
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x518(%rbp)
cmpq   $0x0,-0x518(%rbp)
jne    12f4 <cancel_lru_locks+0x134>
lea    0xd83(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1424 <cancel_lru_locks+0x264>
jmp    12f9 <cancel_lru_locks+0x139>
lea    -0x510(%rbp),%rdi
mov    -0x524(%rbp),%esi
mov    -0x518(%rbp),%rdx
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     140d <cancel_lru_locks+0x24d>
lea    -0x510(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    1336 <cancel_lru_locks+0x176>
jmp    12f9 <cancel_lru_locks+0x139>
lea    -0x510(%rbp),%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x511(%rbp,%rax,1)
lea    -0x510(%rbp),%rdi
lea    0xd0f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x538(%rbp)
cmpq   $0x0,-0x538(%rbp)
jne    1394 <cancel_lru_locks+0x1d4>
lea    0xcf0(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x528(%rbp)
jmp    140d <cancel_lru_locks+0x24d>
lea    0xcd8(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
add    $0x1,%esi
mov    -0x538(%rbp),%rcx
lea    0xcc0(%rip),%rdi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    %eax,-0x528(%rbp)
cmpl   $0x1,-0x528(%rbp)
jge    13fc <cancel_lru_locks+0x23c>
lea    0xca2(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2bf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x528(%rbp)
mov    -0x538(%rbp),%rdi
call   1040 <fclose@plt>
jmp    140d <cancel_lru_locks+0x24d>
mov    -0x538(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12f9 <cancel_lru_locks+0x139>
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,%rbx
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
js     126c <cancel_lru_locks+0xac>
je     120e <cancel_lru_locks+0x4e>
mov    %rax,%rbp
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
lea    0x100(%rsp),%rsi
mov    %rbp,%rdi
call   1080 <waitpid@plt>
cltq
xor    %ecx,%ecx
cmp    %rax,%rbp
cmove  %ecx,%eax
jmp    1275 <cancel_lru_locks+0xb5>
test   %rbx,%rbx
jne    1238 <cancel_lru_locks+0x78>
movups 0xe37(%rip),%xmm0
movups %xmm0,0x1e(%rsp)
movups 0xe1d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xe01(%rip),%xmm0
movaps %xmm0,(%rsp)
jmp    124c <cancel_lru_locks+0x8c>
lea    0xdc1(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
lea    0xe24(%rip),%rsi
mov    %rsp,%rdi
call   1090 <popen@plt>
test   %rax,%rax
jne    1287 <cancel_lru_locks+0xc7>
lea    0xdfa(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
add    $0x508,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%rbx
lea    0x100(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     136f <cancel_lru_locks+0x1af>
lea    0x100(%rsp),%r14
lea    0xdaf(%rip),%r15
lea    0xdb2(%rip),%r12
jmp    12dc <cancel_lru_locks+0x11c>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     136f <cancel_lru_locks+0x1af>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     12c3 <cancel_lru_locks+0x103>
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     1339 <cancel_lru_locks+0x179>
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    1351 <cancel_lru_locks+0x191>
mov    %eax,%r13d
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    12c3 <cancel_lru_locks+0x103>
lea    0xd2b(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%r13d
jmp    136f <cancel_lru_locks+0x1af>
lea    0xd21(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c74(%rip),%rax
mov    (%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 %17
15: ; preds = %1
%16 = load i32, i32* @errno
store i32 %16, i32* %2
br label %96
17: ; preds = %1
%18 = load i64, i64* %7
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load i64, i64* %7
%22 = load i32, i32* @WNOHANG
%23 = call i32 @waitpid(i64 %21, i32* %10, i32 %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = load i64, i64* %7
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 0, i32* %9
br label %29
29: ; preds = %28, %20
%30 = load i32, i32* %9
store i32 %30, i32* %2
br label %96
31: ; preds = %17
br label %32
32: ; preds = %31
%33 = load i8*, i8** %3
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%37 = load i8*, i8** %3
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %37)
br label %42
39: ; preds = %32
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %39, %35
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%44 = call i32* @popen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %44, i32** %6
%45 = load i32*, i32** %6
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @errno
store i32 %49, i32* %2
br label %96
50: ; preds = %42
br label %51
51: ; preds = %88, %61, %50
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%53 = load i32, i32* %8
%54 = load i32*, i32** %6
%55 = call i64 @fgets(i8* %52, i32 %53, i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %91
57: ; preds = %51
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%59 = call i32 @strlen(i8* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %62, label %61
61: ; preds = %57
br label %51
62: ; preds = %57
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%65 = call i32 @strlen(i8* %64)
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
%68 = getelementptr inbounds i8, i8* %67, i64 -1
store i8 0, i8* %68
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%70 = call i32* @fopen(i8* %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %70, i32** %11
%71 = load i32*, i32** %11
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %76
73: ; preds = %62
%74 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%75 = load i32, i32* @errno
store i32 %75, i32* %9
br label %91
76: ; preds = %62
%77 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%78 = add nsw i32 %77, 1
%79 = load i32*, i32** %11
%80 = call i32 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %78, i32 1, i32* %79)
store i32 %80, i32* %9
%81 = load i32, i32* %9
%82 = icmp slt i32 %81, 1
br i1 %82, label %83, label %88
83: ; preds = %76
%84 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%85 = load i32, i32* @errno
store i32 %85, i32* %9
%86 = load i32*, i32** %11
%87 = call i32 @fclose(i32* %86)
br label %91
88: ; preds = %76
%89 = load i32*, i32** %11
%90 = call i32 @fclose(i32* %89)
br label %51
91: ; preds = %83, %73, %51
%92 = load i32*, i32** %6
%93 = call i32 @pclose(i32* %92)
%94 = load i32, i32* %9
%95 = call i32 @_exit(i32 %94)
unreachable
96: ; preds = %47, %29, %15
%97 = load i32, i32* %2
ret i32 %97
}

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 %11
9: ; preds = %1
%10 = load i32, i32* @errno
br label %67
11: ; preds = %1
%12 = icmp eq i64 %7, 0
br i1 %12, label %20, label %13
13: ; preds = %11
%14 = bitcast i32* %4 to i8*
%15 = load i32, i32* @WNOHANG
%16 = call i32 @waitpid(i64 %7, i32* %4, i32 %15)
%17 = sext i32 %16 to i64
%18 = icmp eq i64 %7, %17
%19 = select i1 %18, i32 0, i32 %16
br label %67
20: ; preds = %11
%21 = icmp eq i8* %0, null
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = 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 %25
24: ; preds = %20
br label %25
25: ; preds = %24, %22
%26 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = call i64 @fgets(i8* %6, i32 1024, i32* %26)
%30 = icmp eq i64 %29, 0
br i1 %30, label %63, label %34
31: ; preds = %25
%32 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @errno
br label %67
34: ; preds = %28, %59
%35 = phi i32 [ %60, %59 ], [ 0, %28 ]
%36 = call i32 @strlen(i8* %6)
%37 = icmp eq i32 %36, 0
br i1 %37, label %59, label %38
38: ; preds = %34
%39 = call i32 @strlen(i8* %6)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 -1
store i8 0, i8* %42
%43 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* @errno
br label %63
48: ; preds = %38
%49 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%50 = add nsw i32 %49, 1
%51 = call i32 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %50, i32 1, i32* %43)
%52 = icmp slt i32 %51, 1
br i1 %52, label %53, label %57
53: ; preds = %48
%54 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%55 = load i32, i32* @errno
%56 = call i32 @fclose(i32* %43)
br label %63
57: ; preds = %48
%58 = call i32 @fclose(i32* %43)
br label %59
59: ; preds = %34, %57
%60 = phi i32 [ %51, %57 ], [ %35, %34 ]
%61 = call i64 @fgets(i8* %6, i32 1024, i32* %26)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %34
63: ; preds = %59, %28, %53, %45
%64 = phi i32 [ %55, %53 ], [ %47, %45 ], [ 0, %28 ], [ %60, %59 ]
%65 = call i32 @pclose(i32* %26)
%66 = call i32 @_exit(i32 %64)
unreachable
67: ; preds = %31, %13, %9
%68 = phi i32 [ %10, %9 ], [ %19, %13 ], [ %33, %31 ]
ret i32 %68
}