#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(int, char *);
long delete_module(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ filename2modname(char *, char const *);
int /*<<< orphan*/ message(int, char *, char *, char *, char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int rmmod(int log, int verbose, 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(log, name) != 0)
      return 1;
  }
  do {
    if (verbose)
      message(log, "", "rmmod %s, wait=%s%s\n", name,
              (flags & O_NONBLOCK) ? "no" : "yes",
              (flags & O_TRUNC) ? " force" : "");
  } while (0);
  ret = delete_module(name, flags);
  if (ret != 0)
    message(log, "ERROR: ", "Removing '%s': %s\n", name, strerror(errno));
  return ret;
}


x86 assembly (clang, -O0):
<rmmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rsi
call   1060 <filename2modname@plt>
mov    -0x1c(%rbp),%eax
mov    0x2e29(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1205 <rmmod+0xa5>
mov    -0x1c(%rbp),%eax
mov    0x2e2c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1205 <rmmod+0xa5>
mov    -0x48(%rbp),%rsi
mov    -0x8(%rbp),%edi
call   1070 <check_usage@plt>
cmp    $0x0,%rax
je     1200 <rmmod+0xa0>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    12d8 <rmmod+0x178>
jmp    1205 <rmmod+0xa5>
jmp    120a <rmmod+0xaa>
cmpl   $0x0,-0xc(%rbp)
je     1272 <rmmod+0x112>
mov    -0x48(%rbp),%rcx
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    0x2dbb(%rip),%rax
and    (%rax),%edx
lea    0xdea(%rip),%r8
lea    0xde0(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r8
mov    -0x1c(%rbp),%edx
mov    0x2db2(%rip),%rax
and    (%rax),%edx
lea    0xdee(%rip),%r9
lea    0xdc6(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%r9
lea    0xdd9(%rip),%rsi
lea    0xd95(%rip),%rdx
mov    $0x0,%al
call   1030 <message@plt>
jmp    1277 <rmmod+0x117>
jmp    127c <rmmod+0x11c>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <delete_module@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12ca <rmmod+0x16a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rcx
movslq %eax,%r8
lea    0xd67(%rip),%rsi
lea    0xd68(%rip),%rdx
mov    $0x0,%al
call   1030 <message@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x30(%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    %ecx,%r15d
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %edi,-0x2c(%rbp)
mov    %rdx,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <filename2modname@plt>
mov    0x2e38(%rip),%rbx
test   %r15d,(%rbx)
je     11d3 <rmmod+0x73>
mov    0x2e44(%rip),%rax
test   %r15d,(%rax)
jne    11d3 <rmmod+0x73>
mov    -0x2c(%rbp),%edi
mov    %r14,%rsi
call   1070 <check_usage@plt>
mov    $0x1,%r13d
test   %rax,%rax
jne    1260 <rmmod+0x100>
test   %r12d,%r12d
je     1221 <rmmod+0xc1>
mov    (%rbx),%eax
and    %r15d,%eax
lea    0xe34(%rip),%rax
lea    0xe2a(%rip),%r8
cmove  %rax,%r8
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
and    %r15d,%eax
lea    0xe3b(%rip),%rsi
lea    0xe13(%rip),%r9
cmove  %rsi,%r9
lea    0xdec(%rip),%rdx
mov    -0x2c(%rbp),%edi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <message@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   1050 <delete_module@plt>
mov    %rax,%r13
test   %rax,%rax
je     1260 <rmmod+0x100>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
movslq %eax,%r8
lea    0xdd7(%rip),%rsi
lea    0xdd8(%rip),%rdx
mov    -0x2c(%rbp),%edi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <message@plt>
mov    %r13d,%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 = [1 x i8] zeroinitializer
@.str.1 = [21 x i8] c"rmmod %s, wait=%s%s\0A\00"
@.str.2 = [3 x i8] c"no\00"
@.str.3 = [4 x i8] c"yes\00"
@.str.4 = [7 x i8] c" force\00"
@.str.5 = [8 x i8] c"ERROR: \00"
@.str.6 = [19 x i8] c"Removing '%s': %s\0A\00"
@errno = global i32 0
define i32 @rmmod(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%14 = load i8*, i8** %8
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %11
%19 = alloca i8, i64 %17
store i64 %17, i64* %12
%20 = load i8*, i8** %8
%21 = call i32 @filename2modname(i8* %19, i8* %20)
%22 = load i32, i32* %9
%23 = load i32, i32* @O_NONBLOCK
%24 = and i32 %22, %23
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %4
%27 = load i32, i32* %9
%28 = load i32, i32* @O_TRUNC
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %26
%32 = load i32, i32* %6
%33 = call i64 @check_usage(i32 %32, i8* %19)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 1, i32* %5
store i32 1, i32* %13
br label %73
36: ; preds = %31
br label %37
37: ; preds = %36, %26, %4
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %56
41: ; preds = %38
%42 = load i32, i32* %6
%43 = load i32, i32* %9
%44 = load i32, i32* @O_NONBLOCK
%45 = and i32 %43, %44
%46 = icmp ne i32 %45, 0
%47 = zext i1 %46 to i64
%48 = select i1 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%49 = load i32, i32* %9
%50 = load i32, i32* @O_TRUNC
%51 = and i32 %49, %50
%52 = icmp ne i32 %51, 0
%53 = zext i1 %52 to i64
%54 = select i1 %52, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%55 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @message(i32 %42, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %48, i8* %54)
br label %56
56: ; preds = %41, %38
br label %57
57: ; preds = %56
br label %58
58: ; preds = %57
%59 = load i32, i32* %9
%60 = call i64 @delete_module(i8* %19, i32 %59)
store i64 %60, i64* %10
%61 = load i64, i64* %10
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %58
%64 = load i32, i32* %6
%65 = load i32, i32* @errno
%66 = call i32 @strerror(i32 %65)
%67 = sext i32 %66 to i64
%68 = inttoptr i64 %67 to i8*
%69 = call i32 (i32, i8*, i8*, i8*, i8*, ...) @message(i32 %64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %19, i8* %68)
br label %70
70: ; preds = %63, %58
%71 = load i64, i64* %10
%72 = trunc i64 %71 to i32
store i32 %72, i32* %5
store i32 1, i32* %13
br label %73
73: ; preds = %70, %35
%74 = load i8*, i8** %11
%75 = load i32, i32* %5
ret i32 %75
}

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