#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 dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ abort;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SIGKILL;
int WNOHANG;
int __WALL;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usleep(int);
int waitpid(int, int *, int);
scalar_t__ write(int, char *, int);
void kill_and_wait(int pid, int *status) {
  kill(-pid, SIGKILL);
  kill(pid, SIGKILL);
  int i;
  for (i = 0; i < 100; i++) {
    if (waitpid(-1, status, WNOHANG | __WALL) == pid)
      return;
    usleep(1000);
  }
  DIR *dir = opendir("/sys/fs/fuse/connections");
  if (dir) {
    for (;;) {
      struct dirent *ent = readdir(dir);
      if (!ent)
        break;
      if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
        continue;
      char abort[300];
      snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
               ent->d_name);
      int fd = open(abort, O_WRONLY);
      if (fd == -1) {
        continue;
      }
      if (write(fd, abort, 1) < 0) {
      }
      close(fd);
    }
    closedir(dir);
  } else {
  }
  while (waitpid(-1, status, __WALL) != pid) {
  }
}


x86 assembly (clang, -O0):
<kill_and_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
sub    -0x4(%rbp),%edi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1090 <kill@plt>
mov    -0x4(%rbp),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
call   1090 <kill@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    123d <kill_and_wait+0x8d>
mov    -0x10(%rbp),%rsi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
mov    0x2dcd(%rip),%rax
or     (%rax),%edx
mov    $0xffffffff,%edi
call   10b0 <waitpid@plt>
cmp    -0x4(%rbp),%eax
jne    1225 <kill_and_wait+0x75>
jmp    1378 <kill_and_wait+0x1c8>
mov    $0x3e8,%edi
call   10d0 <usleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ed <kill_and_wait+0x3d>
lea    0xdbc(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1349 <kill_and_wait+0x199>
jmp    125d <kill_and_wait+0xad>
mov    -0x20(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    127a <kill_and_wait+0xca>
jmp    133b <kill_and_wait+0x18b>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd92(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12b4 <kill_and_wait+0x104>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd74(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12b9 <kill_and_wait+0x109>
jmp    125d <kill_and_wait+0xad>
lea    -0x160(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
mov    $0x12c,%esi
lea    0xd49(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x160(%rbp),%rdi
mov    0x2cda(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x164(%rbp)
cmpl   $0xffffffff,-0x164(%rbp)
jne    1305 <kill_and_wait+0x155>
jmp    125d <kill_and_wait+0xad>
mov    -0x164(%rbp),%edi
lea    -0x160(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    132b <kill_and_wait+0x17b>
jmp    132b <kill_and_wait+0x17b>
mov    -0x164(%rbp),%edi
call   1060 <close@plt>
jmp    125d <kill_and_wait+0xad>
mov    -0x20(%rbp),%rdi
call   1070 <closedir@plt>
jmp    134e <kill_and_wait+0x19e>
jmp    134e <kill_and_wait+0x19e>
jmp    1353 <kill_and_wait+0x1a3>
mov    -0x10(%rbp),%rsi
mov    0x2c7a(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
call   10b0 <waitpid@plt>
cmp    -0x4(%rbp),%eax
je     1378 <kill_and_wait+0x1c8>
jmp    1353 <kill_and_wait+0x1a3>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_and_wait>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
neg    %edi
mov    0x2e01(%rip),%rbx
mov    (%rbx),%esi
call   1090 <kill@plt>
mov    (%rbx),%esi
mov    %ebp,%edi
call   1090 <kill@plt>
mov    $0x64,%ebx
mov    0x2dfd(%rip),%r14
mov    0x2de6(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%edx
or     (%r14),%edx
mov    $0xffffffff,%edi
mov    %r15,%rsi
call   10b0 <waitpid@plt>
cmp    %ebp,%eax
je     1325 <kill_and_wait+0x175>
mov    $0x3e8,%edi
call   10d0 <usleep@plt>
add    $0xffffffff,%ebx
jne    1200 <kill_and_wait+0x50>
lea    0xdce(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1310 <kill_and_wait+0x160>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     1301 <kill_and_wait+0x151>
mov    %rax,%r12
lea    0xdbc(%rip),%rbx
mov    %r14,0x8(%rsp)
jmp    1288 <kill_and_wait+0xd8>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rbx
mov    0x8(%rsp),%r14
mov    %r14,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     1301 <kill_and_wait+0x151>
mov    (%r12),%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1278 <kill_and_wait+0xc8>
mov    (%r12),%rdi
lea    0xd75(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1278 <kill_and_wait+0xc8>
mov    %rbx,%r14
mov    (%r12),%rcx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x12c,%esi
lea    0xd53(%rip),%rdx
call   1050 <snprintf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     1270 <kill_and_wait+0xc0>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    1270 <kill_and_wait+0xc0>
mov    %r14,%rdi
call   1070 <closedir@plt>
nopl   0x0(%rax)
mov    0x0(%r13),%edx
mov    $0xffffffff,%edi
mov    %r15,%rsi
call   10b0 <waitpid@plt>
cmp    %ebp,%eax
jne    1310 <kill_and_wait+0x160>
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@SIGKILL = global i32 0
@WNOHANG = global i32 0
@__WALL = global i32 0
@.str = [25 x i8] c"/sys/fs/fuse/connections\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [34 x i8] c"/sys/fs/fuse/connections/%s/abort\00"
@O_WRONLY = global i32 0
define void @kill_and_wait(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca [300 x i8]
%9 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%10 = load i32, i32* %3
%11 = sub nsw i32 0, %10
%12 = load i32, i32* @SIGKILL
%13 = call i32 @kill(i32 %11, i32 %12)
%14 = load i32, i32* %3
%15 = load i32, i32* @SIGKILL
%16 = call i32 @kill(i32 %14, i32 %15)
store i32 0, i32* %5
br label %17
17: ; preds = %31, %2
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = load i32*, i32** %4
%22 = load i32, i32* @WNOHANG
%23 = load i32, i32* @__WALL
%24 = or i32 %22, %23
%25 = call i32 @waitpid(i32 -1, i32* %21, i32 %24)
%26 = load i32, i32* %3
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %20
br label %91
29: ; preds = %20
%30 = call i32 @usleep(i32 1000)
br label %31
31: ; preds = %29
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %17
34: ; preds = %17
%35 = call i32* @opendir(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32* %35, i32** %6
%36 = load i32*, i32** %6
%37 = icmp ne i32* %36, null
br i1 %37, label %38, label %82
38: ; preds = %34
br label %39
39: ; preds = %76, %69, %57, %38
%40 = load i32*, i32** %6
%41 = call %struct.dirent* @readdir(i32* %40)
store %struct.dirent* %41, %struct.dirent** %7
%42 = load %struct.dirent*, %struct.dirent** %7
%43 = icmp ne %struct.dirent* %42, null
br i1 %43, label %45, label %44
44: ; preds = %39
br label %79
45: ; preds = %39
%46 = load %struct.dirent*, %struct.dirent** %7
%47 = getelementptr inbounds %struct.dirent, %struct.dirent* %46, i32 0, i32 0
%48 = load i8*, i8** %47
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %57, label %51
51: ; preds = %45
%52 = load %struct.dirent*, %struct.dirent** %7
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i8*, i8** %53
%55 = call i64 @strcmp(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %51, %45
br label %39
58: ; preds = %51
%59 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%60 = load %struct.dirent*, %struct.dirent** %7
%61 = getelementptr inbounds %struct.dirent, %struct.dirent* %60, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = call i32 @snprintf(i8* %59, i32 300, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %62)
%64 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%65 = load i32, i32* @O_WRONLY
%66 = call i32 @open(i8* %64, i32 %65)
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %70
69: ; preds = %58
br label %39
70: ; preds = %58
%71 = load i32, i32* %9
%72 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%73 = call i64 @write(i32 %71, i8* %72, i32 1)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %70
br label %76
76: ; preds = %75, %70
%77 = load i32, i32* %9
%78 = call i32 @close(i32 %77)
br label %39
79: ; preds = %44
%80 = load i32*, i32** %6
%81 = call i32 @closedir(i32* %80)
br label %83
82: ; preds = %34
br label %83
83: ; preds = %82, %79
br label %84
84: ; preds = %90, %83
%85 = load i32*, i32** %4
%86 = load i32, i32* @__WALL
%87 = call i32 @waitpid(i32 -1, i32* %85, i32 %86)
%88 = load i32, i32* %3
%89 = icmp ne i32 %87, %88
br i1 %89, label %90, label %91
90: ; preds = %84
br label %84
91: ; preds = %28, %84
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@SIGKILL = global i32 0
@WNOHANG = global i32 0
@__WALL = global i32 0
@.str = [25 x i8] c"/sys/fs/fuse/connections\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [34 x i8] c"/sys/fs/fuse/connections/%s/abort\00"
@O_WRONLY = global i32 0
define void @kill_and_wait(i32 %0, i32* %1) {
%3 = alloca [300 x i8]
%4 = sub nsw i32 0, %0
%5 = load i32, i32* @SIGKILL
%6 = tail call i32 @kill(i32 %4, i32 %5)
%7 = load i32, i32* @SIGKILL
%8 = tail call i32 @kill(i32 %0, i32 %7)
br label %9
9: ; preds = %2, %16
%10 = phi i32 [ 0, %2 ], [ %18, %16 ]
%11 = load i32, i32* @WNOHANG
%12 = load i32, i32* @__WALL
%13 = or i32 %12, %11
%14 = tail call i32 @waitpid(i32 -1, i32* %1, i32 %13)
%15 = icmp eq i32 %14, %0
br i1 %15, label %58, label %16
16: ; preds = %9
%17 = tail call i32 @usleep(i32 1000)
%18 = add nuw nsw i32 %10, 1
%19 = icmp eq i32 %18, 100
br i1 %19, label %20, label %9
20: ; preds = %16
%21 = tail call i32* @opendir(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %53, label %23
23: ; preds = %20
%24 = call %struct.dirent* @readdir(i32* %21)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %51, label %26
26: ; preds = %23
%27 = getelementptr inbounds [300 x i8], [300 x i8]* %3, i64 0, i64 0
br label %28
28: ; preds = %26, %48
%29 = phi %struct.dirent* [ %24, %26 ], [ %49, %48 ]
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 0
%31 = load i8*, i8** %30
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %48, label %34
34: ; preds = %28
%35 = load i8*, i8** %30
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %48, label %38
38: ; preds = %34
%39 = load i8*, i8** %30
%40 = call i32 @snprintf(i8* %27, i32 300, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @O_WRONLY
%42 = call i32 @open(i8* %27, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %47, label %44
44: ; preds = %38
%45 = call i64 @write(i32 %42, i8* %27, i32 1)
%46 = call i32 @close(i32 %42)
br label %47
47: ; preds = %38, %44
br label %48
48: ; preds = %28, %34, %47
%49 = call %struct.dirent* @readdir(i32* %21)
%50 = icmp eq %struct.dirent* %49, null
br i1 %50, label %51, label %28
51: ; preds = %48, %23
%52 = call i32 @closedir(i32* %21)
br label %53
53: ; preds = %20, %51
br label %54
54: ; preds = %53, %54
%55 = load i32, i32* @__WALL
%56 = call i32 @waitpid(i32 -1, i32* %1, i32 %55)
%57 = icmp eq i32 %56, %0
br i1 %57, label %58, label %54
58: ; preds = %9, %54
ret void
}