#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*/ pid_t;

/* Variables and functions */
int O_EXCL;
int O_NONBLOCK;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int delete_module(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
char *modNameMunge(char *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int rmmod(char *modName) {
  pid_t child;
  int status;
  int rc = 0;
  modName = modNameMunge(modName);
  if ((child = fork()) == 0) {
    rc = delete_module(modName, O_NONBLOCK | O_EXCL);
    exit(rc);
  }
  waitpid(child, &status, 0);
  if (WIFEXITED(status))
    rc = WEXITSTATUS(status);
  else
    rc = -1;
  return rc;
}


x86 assembly (clang, -O0):
<rmmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <modNameMunge@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    11c9 <rmmod+0x59>
mov    -0x8(%rbp),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
call   1030 <delete_module@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x10(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11f9 <rmmod+0x89>
mov    -0x10(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,-0x14(%rbp)
jmp    1200 <rmmod+0x90>
movl   $0xffffffff,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmmod>:
push   %rbx
sub    $0x10,%rsp
call   1040 <modNameMunge@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11ba <rmmod+0x4a>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11af <rmmod+0x3f>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
jmp    11b4 <rmmod+0x44>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e27(%rip),%rax
mov    0x2e10(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1030 <delete_module@plt>
mov    %eax,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_NONBLOCK = global i32 0
@O_EXCL = global i32 0
define i32 @rmmod(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i8* @modNameMunge(i8* %6)
store i8* %7, i8** %2
%8 = call i32 (...) @fork()
store i32 %8, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i32, i32* @O_NONBLOCK
%13 = load i32, i32* @O_EXCL
%14 = or i32 %12, %13
%15 = call i32 @delete_module(i8* %11, i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
%19 = load i32, i32* %3
%20 = call i32 @waitpid(i32 %19, i32* %4, i32 0)
%21 = load i32, i32* %4
%22 = call i64 @WIFEXITED(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %4
%26 = call i32 @WEXITSTATUS(i32 %25)
store i32 %26, i32* %5
br label %28
27: ; preds = %18
store i32 -1, i32* %5
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
@O_NONBLOCK = global i32 0
@O_EXCL = global i32 0
define i32 @rmmod(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i8* @modNameMunge(i8* %0)
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* @O_NONBLOCK
%9 = load i32, i32* @O_EXCL
%10 = or i32 %9, %8
%11 = tail call i32 @delete_module(i8* %4, i32 %10)
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = call i32 @waitpid(i32 %5, i32* %2, i32 0)
%15 = load i32, i32* %2
%16 = call i64 @WIFEXITED(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = load i32, i32* %2
%20 = call i32 @WEXITSTATUS(i32 %19)
br label %21
21: ; preds = %13, %18
%22 = phi i32 [ %20, %18 ], [ -1, %13 ]
ret i32 %22
}