#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, i;
  char *modname, *dot;
  if (argc < 2) {
    fprintf(stderr, "usage: rmmod <module>\n");
    return -1;
  }
  modname = strrchr(argv[1], '/');
  if (!modname)
    modname = argv[1];
  else
    modname++;
  dot = strchr(argv[1], '.');
  if (dot)
    *dot = '\0';
  for (i = 0; modname[i] != '\0'; i++) {
    if (modname[i] == '-')
      modname[i] = '_';
  }
  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    1291 <rmmod_main+0x151>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ae <rmmod_main+0x6e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11ba <rmmod_main+0x7a>
mov    -0x20(%rbp),%rax
add    $0x1,%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     11e2 <rmmod_main+0xa2>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1232 <rmmod_main+0xf2>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    121f <rmmod_main+0xdf>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    1224 <rmmod_main+0xe4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e9 <rmmod_main+0xa9>
mov    -0x20(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
mov    0x2d8a(%rip),%rax
or     (%rax),%esi
call   1050 <delete_module@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     128a <rmmod_main+0x14a>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    0x2d5a(%rip),%rax
mov    (%rax),%ecx
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1291 <rmmod_main+0x151>
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     1165 <rmmod_main+0x25>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11f4 <rmmod_main+0xb4>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%r14
test   %rax,%rax
cmove  %rbx,%r14
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1196 <rmmod_main+0x56>
movb   $0x0,(%rax)
mov    %r14,%rax
jmp    11a7 <rmmod_main+0x67>
nopl   0x0(%rax,%rax,1)
movb   $0x5f,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x2d,%cl
je     11a0 <rmmod_main+0x60>
test   %cl,%cl
jne    11a3 <rmmod_main+0x63>
mov    0x2e2e(%rip),%rax
mov    0x2e0f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
call   1050 <delete_module@plt>
test   %eax,%eax
je     11fb <rmmod_main+0xbb>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%ecx
lea    0xe2d(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11fd <rmmod_main+0xbd>
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 i32
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %78
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i8* @strrchr(i8* %18, i8 signext 47)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %8
br label %29
26: ; preds = %15
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %8
br label %29
29: ; preds = %26, %22
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i8* @strchr(i8* %32, i8 signext 46)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = load i8*, i8** %9
store i8 0, i8* %37
br label %38
38: ; preds = %36, %29
store i32 0, i32* %7
br label %39
39: ; preds = %61, %38
%40 = load i8*, i8** %8
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %64
47: ; preds = %39
%48 = load i8*, i8** %8
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 45
br i1 %54, label %55, label %60
55: ; preds = %47
%56 = load i8*, i8** %8
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 95, i8* %59
br label %60
60: ; preds = %55, %47
br label %61
61: ; preds = %60
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %39
64: ; preds = %39
%65 = load i8*, i8** %8
%66 = load i32, i32* @O_NONBLOCK
%67 = load i32, i32* @O_EXCL
%68 = or i32 %66, %67
%69 = call i32 @delete_module(i8* %65, i32 %68)
store i32 %69, i32* %6
%70 = load i32, i32* %6
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %64
%73 = load i32, i32* @stderr
%74 = load i8*, i8** %8
%75 = load i32, i32* @errno
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %74, i32 %75)
store i32 -1, i32* %3
br label %78
77: ; preds = %64
store i32 0, i32* %3
br label %78
78: ; preds = %77, %72, %12
%79 = load i32, i32* %3
ret i32 %79
}

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 %35
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 = getelementptr inbounds i8, i8* %10, i64 1
%13 = select i1 %11, i8* %9, i8* %12
%14 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 46)
%15 = icmp eq i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %7
store i8 0, i8* %14
br label %17
17: ; preds = %16, %7
br label %18
18: ; preds = %17, %23
%19 = phi i64 [ %24, %23 ], [ 0, %17 ]
%20 = getelementptr inbounds i8, i8* %13, i64 %19
%21 = load i8, i8* %20
switch i8 %21, label %23 [
i8 0, label %25
i8 45, label %22
]
22: ; preds = %18
store i8 95, i8* %20
br label %23
23: ; preds = %18, %22
%24 = add nuw i64 %19, 1
br label %18
25: ; preds = %18
%26 = load i32, i32* @O_NONBLOCK
%27 = load i32, i32* @O_EXCL
%28 = or i32 %27, %26
%29 = tail call i32 @delete_module(i8* %13, i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %33)
br label %35
35: ; preds = %25, %31, %4
%36 = phi i32 [ -1, %4 ], [ -1, %31 ], [ 0, %25 ]
ret i32 %36
}