#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_NONBLOCK;
int O_TRUNC;
scalar_t__ check_usage(char *);
long delete_module(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(char *, char *, char *);
int /*<<< orphan*/ filename2modname(char *, char const *);
int /*<<< orphan*/ info(char *, char *, char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int rmmod(const char *path, int flags) {
  long ret;
  char name[strlen(path) + 1];
  filename2modname(name, path);
  if ((flags & O_NONBLOCK) && !(flags & O_TRUNC)) {
    if (check_usage(name) != 0)
      return 1;
  }
  info("rmmod %s, wait=%s%s\n", name, (flags & O_NONBLOCK) ? "no" : "yes",
       (flags & O_TRUNC) ? " force" : "");
  ret = delete_module(name, flags);
  if (ret != 0)
    error("Removing '%s': %s\n", name, strerror(errno));
  return ret;
}


x86 assembly (clang, -O0):
<rmmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
call   1050 <filename2modname@plt>
mov    -0x14(%rbp),%eax
mov    0x2e1f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     120c <rmmod+0x9c>
mov    -0x14(%rbp),%eax
mov    0x2e22(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    120c <rmmod+0x9c>
mov    -0x40(%rbp),%rdi
call   1070 <check_usage@plt>
cmp    $0x0,%rax
je     1207 <rmmod+0x97>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12a8 <rmmod+0x138>
jmp    120c <rmmod+0x9c>
mov    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%ecx
mov    0x2dc6(%rip),%rax
and    (%rax),%ecx
lea    0xdf5(%rip),%rdx
lea    0xdeb(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x14(%rbp),%edi
mov    0x2dbd(%rip),%rax
and    (%rax),%edi
lea    0xdf1(%rip),%rcx
lea    0xdd1(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
lea    0xda7(%rip),%rdi
call   1090 <info@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <delete_module@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     129a <rmmod+0x12a>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    0xd8e(%rip),%rdi
call   1060 <error@plt>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmmod>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <filename2modname@plt>
mov    0x2e31(%rip),%r13
test   %r14d,0x0(%r13)
je     11e1 <rmmod+0x71>
mov    0x2e3c(%rip),%rax
lea    0xe52(%rip),%r15
test   %r14d,(%rax)
jne    11e8 <rmmod+0x78>
mov    %rbx,%rdi
call   1070 <check_usage@plt>
mov    $0x1,%r12d
test   %rax,%rax
jne    124b <rmmod+0xdb>
test   %r14d,0x0(%r13)
jne    11e8 <rmmod+0x78>
lea    0xe30(%rip),%r15
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
and    %r14d,%eax
lea    0xe3a(%rip),%rax
lea    0xe1a(%rip),%rcx
cmove  %rax,%rcx
lea    0xdf3(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <info@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <delete_module@plt>
mov    %rax,%r12
test   %rax,%rax
je     124b <rmmod+0xdb>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde3(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1060 <error@plt>
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_NONBLOCK = global i32 0
@O_TRUNC = global i32 0
@.str = [21 x i8] c"rmmod %s, wait=%s%s\0A\00"
@.str.1 = [3 x i8] c"no\00"
@.str.2 = [4 x i8] c"yes\00"
@.str.3 = [7 x i8] c" force\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [19 x i8] c"Removing '%s': %s\0A\00"
@errno = global i32 0
define i32 @rmmod(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
%16 = load i8*, i8** %4
%17 = call i32 @filename2modname(i8* %15, i8* %16)
%18 = load i32, i32* %5
%19 = load i32, i32* @O_NONBLOCK
%20 = and i32 %18, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %2
%23 = load i32, i32* %5
%24 = load i32, i32* @O_TRUNC
%25 = and i32 %23, %24
%26 = icmp ne i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %22
%28 = call i64 @check_usage(i8* %15)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 1, i32* %3
store i32 1, i32* %9
br label %57
31: ; preds = %27
br label %32
32: ; preds = %31, %22, %2
%33 = load i32, i32* %5
%34 = load i32, i32* @O_NONBLOCK
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%39 = load i32, i32* %5
%40 = load i32, i32* @O_TRUNC
%41 = and i32 %39, %40
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%45 = call i32 @info(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %38, i8* %44)
%46 = load i32, i32* %5
%47 = call i64 @delete_module(i8* %15, i32 %46)
store i64 %47, i64* %6
%48 = load i64, i64* %6
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %32
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %15, i8* %52)
br label %54
54: ; preds = %50, %32
%55 = load i64, i64* %6
%56 = trunc i64 %55 to i32
store i32 %56, i32* %3
store i32 1, i32* %9
br label %57
57: ; preds = %54, %30
%58 = load i8*, i8** %7
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@O_NONBLOCK = global i32 0
@O_TRUNC = global i32 0
@.str = [21 x i8] c"rmmod %s, wait=%s%s\0A\00"
@.str.1 = [3 x i8] c"no\00"
@.str.2 = [4 x i8] c"yes\00"
@.str.3 = [7 x i8] c" force\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [19 x i8] c"Removing '%s': %s\0A\00"
@errno = global i32 0
define i32 @rmmod(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @filename2modname(i8* %6, i8* %0)
%8 = load i32, i32* @O_NONBLOCK
%9 = and i32 %8, %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %2
%12 = load i32, i32* @O_TRUNC
%13 = and i32 %12, %1
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = call i64 @check_usage(i8* %6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %15
%19 = load i32, i32* @O_NONBLOCK
%20 = and i32 %19, %1
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %2, %18
br label %23
23: ; preds = %11, %18, %22
%24 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %22 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %18 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %11 ]
%25 = load i32, i32* @O_TRUNC
%26 = and i32 %25, %1
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%29 = call i32 @info(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %24, i8* %28)
%30 = call i64 @delete_module(i8* %6, i32 %1)
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %23
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %6, i8* %34)
br label %36
36: ; preds = %32, %23
%37 = trunc i64 %30 to i32
br label %38
38: ; preds = %15, %36
%39 = phi i32 [ %37, %36 ], [ 1, %15 ]
ret i32 %39
}