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

/* Variables and functions */
int O_EXCL;
int O_NONBLOCK;
int delete_module(char *, int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strrchr(char *, char);
int rmmod_main(int argc, char **argv) {
  int ret;
  char *modname, *dot;
  if (argc < 2) {
    fprintf(stderr, "usage: rmmod <module>\n");
    return -1;
  }
  modname = strrchr(argv[1], '/');
  if (!modname)
    modname = argv[1];
  dot = strchr(argv[1], '.');
  if (dot)
    *dot = '\0';
  ret = delete_module(modname, O_NONBLOCK | O_EXCL);
  if (ret != 0) {
    fprintf(stderr, "rmmod: delete_module '%s' failed (errno %d)\n", modname,
            errno);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rmmod_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117c <rmmod_main+0x3c>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <rmmod_main+0xf0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <rmmod_main+0x69>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d1 <rmmod_main+0x91>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
call   1050 <delete_module@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1229 <rmmod_main+0xe9>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    0x2dbb(%rip),%rax
mov    (%rax),%ecx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <rmmod_main+0xf0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmmod_main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1162 <rmmod_main+0x22>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11d3 <rmmod_main+0x93>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%r14
test   %rax,%rax
cmove  %rbx,%r14
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1192 <rmmod_main+0x52>
movb   $0x0,(%rax)
mov    0x2e4f(%rip),%rax
mov    0x2e30(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
call   1050 <delete_module@plt>
test   %eax,%eax
je     11da <rmmod_main+0x9a>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%ecx
lea    0xe4e(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11dc <rmmod_main+0x9c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"usage: rmmod <module>\0A\00"
@O_NONBLOCK = global i32 0
@O_EXCL = global i32 0
@.str.1 = [45 x i8] c"rmmod: delete_module '%s' failed (errno %d)\0A\00"
@errno = global i32 0
define i32 @rmmod_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %48
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i8* @strrchr(i8* %17, i8 signext 47)
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %14
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %7
br label %25
25: ; preds = %21, %14
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i8* @strchr(i8* %28, i8 signext 46)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = load i8*, i8** %8
store i8 0, i8* %33
br label %34
34: ; preds = %32, %25
%35 = load i8*, i8** %7
%36 = load i32, i32* @O_NONBLOCK
%37 = load i32, i32* @O_EXCL
%38 = or i32 %36, %37
%39 = call i32 @delete_module(i8* %35, i32 %38)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %34
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %7
%45 = load i32, i32* @errno
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %44, i32 %45)
store i32 -1, i32* %3
br label %48
47: ; preds = %34
store i32 0, i32* %3
br label %48
48: ; preds = %47, %42, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"usage: rmmod <module>\0A\00"
@O_NONBLOCK = global i32 0
@O_EXCL = global i32 0
@.str.1 = [45 x i8] c"rmmod: delete_module '%s' failed (errno %d)\0A\00"
@errno = global i32 0
define i32 @rmmod_main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %26
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %9, i8 signext 47)
%11 = icmp eq i8* %10, null
%12 = select i1 %11, i8* %9, i8* %10
%13 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 46)
%14 = icmp eq i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %7
store i8 0, i8* %13
br label %16
16: ; preds = %15, %7
%17 = load i32, i32* @O_NONBLOCK
%18 = load i32, i32* @O_EXCL
%19 = or i32 %18, %17
%20 = tail call i32 @delete_module(i8* %12, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %24)
br label %26
26: ; preds = %16, %22, %4
%27 = phi i32 [ -1, %4 ], [ -1, %22 ], [ 0, %16 ]
ret i32 %27
}