#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*/ filename2modname(char *, char const *);
int /*<<< orphan*/ printf(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;
  }
  ret = delete_module(name, flags);
  if (ret != 0)
    printf("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   1060 <filename2modname@plt>
mov    -0x14(%rbp),%eax
mov    0x2e2f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11fc <rmmod+0x9c>
mov    -0x14(%rbp),%eax
mov    0x2e32(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    11fc <rmmod+0x9c>
mov    -0x40(%rbp),%rdi
call   1070 <check_usage@plt>
cmp    $0x0,%rax
je     11f7 <rmmod+0x97>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1246 <rmmod+0xe6>
jmp    11fc <rmmod+0x9c>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <delete_module@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1238 <rmmod+0xd8>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    0xdcd(%rip),%rdi
call   1040 <printf@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   %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   1060 <filename2modname@plt>
mov    0x2e45(%rip),%rax
test   %r14d,(%rax)
je     11bf <rmmod+0x5f>
mov    0x2e51(%rip),%rax
test   %r14d,(%rax)
jne    11bf <rmmod+0x5f>
mov    %rbx,%rdi
call   1070 <check_usage@plt>
mov    $0x1,%r15d
test   %rax,%rax
jne    11f2 <rmmod+0x92>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <delete_module@plt>
mov    %rax,%r15
test   %rax,%rax
je     11f2 <rmmod+0x92>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe19(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <printf@plt>
mov    %r15d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_NONBLOCK = global i32 0
@O_TRUNC = global i32 0
@.str = [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 %44
31: ; preds = %27
br label %32
32: ; preds = %31, %22, %2
%33 = load i32, i32* %5
%34 = call i64 @delete_module(i8* %15, i32 %33)
store i64 %34, i64* %6
%35 = load i64, i64* %6
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %39)
br label %41
41: ; preds = %37, %32
%42 = load i64, i64* %6
%43 = trunc i64 %42 to i32
store i32 %43, i32* %3
store i32 1, i32* %9
br label %44
44: ; preds = %41, %30
%45 = load i8*, i8** %7
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@O_NONBLOCK = global i32 0
@O_TRUNC = global i32 0
@.str = [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 %18, 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 %18
15: ; preds = %11
%16 = call i64 @check_usage(i8* %6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15, %11, %2
%19 = call i64 @delete_module(i8* %6, i32 %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %23)
br label %25
25: ; preds = %21, %18
%26 = trunc i64 %19 to i32
br label %27
27: ; preds = %15, %25
%28 = phi i32 [ %26, %25 ], [ 1, %15 ]
ret i32 %28
}