#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 */
struct kmod_module {
  int dummy;
};
struct kmod_list {
  int dummy;
};

/* Variables and functions */
struct kmod_list *kmod_list_last(struct kmod_list *);
struct kmod_list *kmod_list_prev(struct kmod_list *, struct kmod_list *);
struct kmod_module *kmod_module_get_module(struct kmod_list *);
int /*<<< orphan*/ kmod_module_unref(struct kmod_module *);
int rmmod_do_module(struct kmod_module *, int);
int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors) {
  struct kmod_list *l;
  for (l = kmod_list_last(list); l != NULL; l = kmod_list_prev(list, l)) {
    struct kmod_module *m = kmod_module_get_module(l);
    int r = rmmod_do_module(m, false);
    kmod_module_unref(m);
    if (r < 0 && stop_on_errors)
      return r;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rmmod_do_deps_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <kmod_list_last@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d5 <rmmod_do_deps_list+0x85>
mov    -0x20(%rbp),%rdi
call   1030 <kmod_module_get_module@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1060 <rmmod_do_module@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <kmod_module_unref@plt>
cmpl   $0x0,-0x2c(%rbp)
jge    11ba <rmmod_do_deps_list+0x6a>
cmpl   $0x0,-0x14(%rbp)
je     11ba <rmmod_do_deps_list+0x6a>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11dc <rmmod_do_deps_list+0x8c>
jmp    11bf <rmmod_do_deps_list+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <kmod_list_prev@plt>
mov    %rax,-0x20(%rbp)
jmp    116c <rmmod_do_deps_list+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmmod_do_deps_list>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
call   1070 <kmod_list_last@plt>
test   %rax,%rax
je     11af <rmmod_do_deps_list+0x5f>
mov    %rax,%rbp
jmp    1183 <rmmod_do_deps_list+0x33>
nopl   (%rax)
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <kmod_list_prev@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11af <rmmod_do_deps_list+0x5f>
mov    %rbp,%rdi
call   1030 <kmod_module_get_module@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <rmmod_do_module@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1050 <kmod_module_unref@plt>
test   %r14d,%r14d
je     1170 <rmmod_do_deps_list+0x20>
test   %r12d,%r12d
jns    1170 <rmmod_do_deps_list+0x20>
jmp    11b2 <rmmod_do_deps_list+0x62>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.kmod_list = type { i32 }
%struct.kmod_module = type { i32 }
define i32 @rmmod_do_deps_list(%struct.kmod_list* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.kmod_list*
%5 = alloca i32
%6 = alloca %struct.kmod_list*
%7 = alloca %struct.kmod_module*
%8 = alloca i32
store %struct.kmod_list* %0, %struct.kmod_list** %4
store i32 %1, i32* %5
%9 = load %struct.kmod_list*, %struct.kmod_list** %4
%10 = call %struct.kmod_list* @kmod_list_last(%struct.kmod_list* %9)
store %struct.kmod_list* %10, %struct.kmod_list** %6
br label %11
11: ; preds = %29, %2
%12 = load %struct.kmod_list*, %struct.kmod_list** %6
%13 = icmp ne %struct.kmod_list* %12, null
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load %struct.kmod_list*, %struct.kmod_list** %6
%16 = call %struct.kmod_module* @kmod_module_get_module(%struct.kmod_list* %15)
store %struct.kmod_module* %16, %struct.kmod_module** %7
%17 = load %struct.kmod_module*, %struct.kmod_module** %7
%18 = call i32 @rmmod_do_module(%struct.kmod_module* %17, i32 0)
store i32 %18, i32* %8
%19 = load %struct.kmod_module*, %struct.kmod_module** %7
%20 = call i32 @kmod_module_unref(%struct.kmod_module* %19)
%21 = load i32, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %14
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = load i32, i32* %8
store i32 %27, i32* %3
br label %34
28: ; preds = %23, %14
br label %29
29: ; preds = %28
%30 = load %struct.kmod_list*, %struct.kmod_list** %4
%31 = load %struct.kmod_list*, %struct.kmod_list** %6
%32 = call %struct.kmod_list* @kmod_list_prev(%struct.kmod_list* %30, %struct.kmod_list* %31)
store %struct.kmod_list* %32, %struct.kmod_list** %6
br label %11
33: ; preds = %11
store i32 0, i32* %3
br label %34
34: ; preds = %33, %26
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.kmod_list = type { i32 }
%struct.kmod_module = type { i32 }
define i32 @rmmod_do_deps_list(%struct.kmod_list* %0, i32 %1) {
%3 = tail call %struct.kmod_list* @kmod_list_last(%struct.kmod_list* %0)
%4 = icmp eq %struct.kmod_list* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = icmp ne i32 %1, 0
br label %7
7: ; preds = %5, %14
%8 = phi %struct.kmod_list* [ %3, %5 ], [ %15, %14 ]
%9 = tail call %struct.kmod_module* @kmod_module_get_module(%struct.kmod_list* %8)
%10 = tail call i32 @rmmod_do_module(%struct.kmod_module* %9, i32 0)
%11 = tail call i32 @kmod_module_unref(%struct.kmod_module* %9)
%12 = icmp slt i32 %10, 0
%13 = and i1 %6, %12
br i1 %13, label %17, label %14
14: ; preds = %7
%15 = tail call %struct.kmod_list* @kmod_list_prev(%struct.kmod_list* %0, %struct.kmod_list* %8)
%16 = icmp eq %struct.kmod_list* %15, null
br i1 %16, label %17, label %7
17: ; preds = %7, %14, %2
%18 = phi i32 [ 0, %2 ], [ 0, %14 ], [ %10, %7 ]
ret i32 %18
}