#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;
};
struct kmod_ctx {
  int dummy;
};

/* Variables and functions */
int ENOENT;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
struct kmod_list *kmod_list_next(struct kmod_list *, struct kmod_list *);
struct kmod_module *kmod_module_get_module(struct kmod_list *);
int kmod_module_new_from_lookup(struct kmod_ctx *, char const *,
                                struct kmod_list **);
int /*<<< orphan*/ kmod_module_unref(struct kmod_module *);
int /*<<< orphan*/ kmod_module_unref_list(struct kmod_list *);
int modinfo_do(struct kmod_module *);
int /*<<< orphan*/ stderr;
int modinfo_alias_do(struct kmod_ctx *ctx, const char *alias) {
  struct kmod_list *l, *list = NULL;
  int err = kmod_module_new_from_lookup(ctx, alias, &list);
  if (err < 0) {
    fprintf(stderr,
            "ERROR: "
            "Module alias %s not found.\n",
            alias);
    return err;
  }
  if (list == NULL) {
    fprintf(stderr,
            "ERROR: "
            "Module %s not found.\n",
            alias);
    return -ENOENT;
  }
  for (l = list; l != NULL; l = kmod_list_next(list, l)) {
    struct kmod_module *mod = kmod_module_get_module(l);
    int r = modinfo_do(mod);
    kmod_module_unref(mod);
    if (r < 0)
      err = r;
  }
  kmod_module_unref_list(list);
  return err;
}


x86 assembly (clang, -O0):
<modinfo_alias_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <kmod_module_new_from_lookup@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ca <modinfo_alias_do+0x5a>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1270 <modinfo_alias_do+0x100>
cmpq   $0x0,-0x28(%rbp)
jne    1201 <modinfo_alias_do+0x91>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1080 <fprintf@plt>
xor    %eax,%eax
mov    0x2dd9(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1270 <modinfo_alias_do+0x100>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1261 <modinfo_alias_do+0xf1>
mov    -0x20(%rbp),%rdi
call   1030 <kmod_module_get_module@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1090 <modinfo_do@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <kmod_module_unref@plt>
cmpl   $0x0,-0x3c(%rbp)
jge    1246 <modinfo_alias_do+0xd6>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    124b <modinfo_alias_do+0xdb>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <kmod_list_next@plt>
mov    %rax,-0x20(%rbp)
jmp    1209 <modinfo_alias_do+0x99>
mov    -0x28(%rbp),%rdi
call   1040 <kmod_module_unref_list@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modinfo_alias_do>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movq   $0x0,(%rsp)
mov    %rsp,%rdx
call   1050 <kmod_module_new_from_lookup@plt>
mov    %eax,%r15d
test   %eax,%eax
js     11e4 <modinfo_alias_do+0x74>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     11fe <modinfo_alias_do+0x8e>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <kmod_module_get_module@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1090 <modinfo_do@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1060 <kmod_module_unref@plt>
test   %r14d,%r14d
cmovs  %r14d,%r15d
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1070 <kmod_list_next@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a0 <modinfo_alias_do+0x30>
mov    (%rsp),%rdi
call   1040 <kmod_module_unref_list@plt>
jmp    1223 <modinfo_alias_do+0xb3>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    %r14,%rdx
call   1080 <fprintf@plt>
jmp    1223 <modinfo_alias_do+0xb3>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
mov    %r14,%rdx
call   1080 <fprintf@plt>
mov    0x2db3(%rip),%rax
xor    %r15d,%r15d
sub    (%rax),%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.kmod_ctx = type { i32 }
%struct.kmod_list = type { i32 }
%struct.kmod_module = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: Module alias %s not found.\0A\00"
@.str.1 = [29 x i8] c"ERROR: Module %s not found.\0A\00"
@ENOENT = global i32 0
define i32 @modinfo_alias_do(%struct.kmod_ctx* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.kmod_ctx*
%5 = alloca i8*
%6 = alloca %struct.kmod_list*
%7 = alloca %struct.kmod_list*
%8 = alloca i32
%9 = alloca %struct.kmod_module*
%10 = alloca i32
store %struct.kmod_ctx* %0, %struct.kmod_ctx** %4
store i8* %1, i8** %5
store %struct.kmod_list* null, %struct.kmod_list** %7
%11 = load %struct.kmod_ctx*, %struct.kmod_ctx** %4
%12 = load i8*, i8** %5
%13 = call i32 @kmod_module_new_from_lookup(%struct.kmod_ctx* %11, i8* %12, %struct.kmod_list** %7)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %5
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %8
store i32 %20, i32* %3
br label %55
21: ; preds = %2
%22 = load %struct.kmod_list*, %struct.kmod_list** %7
%23 = icmp eq %struct.kmod_list* %22, null
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %5
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @ENOENT
%29 = sub nsw i32 0, %28
store i32 %29, i32* %3
br label %55
30: ; preds = %21
%31 = load %struct.kmod_list*, %struct.kmod_list** %7
store %struct.kmod_list* %31, %struct.kmod_list** %6
br label %32
32: ; preds = %47, %30
%33 = load %struct.kmod_list*, %struct.kmod_list** %6
%34 = icmp ne %struct.kmod_list* %33, null
br i1 %34, label %35, label %51
35: ; preds = %32
%36 = load %struct.kmod_list*, %struct.kmod_list** %6
%37 = call %struct.kmod_module* @kmod_module_get_module(%struct.kmod_list* %36)
store %struct.kmod_module* %37, %struct.kmod_module** %9
%38 = load %struct.kmod_module*, %struct.kmod_module** %9
%39 = call i32 @modinfo_do(%struct.kmod_module* %38)
store i32 %39, i32* %10
%40 = load %struct.kmod_module*, %struct.kmod_module** %9
%41 = call i32 @kmod_module_unref(%struct.kmod_module* %40)
%42 = load i32, i32* %10
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %35
%45 = load i32, i32* %10
store i32 %45, i32* %8
br label %46
46: ; preds = %44, %35
br label %47
47: ; preds = %46
%48 = load %struct.kmod_list*, %struct.kmod_list** %7
%49 = load %struct.kmod_list*, %struct.kmod_list** %6
%50 = call %struct.kmod_list* @kmod_list_next(%struct.kmod_list* %48, %struct.kmod_list* %49)
store %struct.kmod_list* %50, %struct.kmod_list** %6
br label %32
51: ; preds = %32
%52 = load %struct.kmod_list*, %struct.kmod_list** %7
%53 = call i32 @kmod_module_unref_list(%struct.kmod_list* %52)
%54 = load i32, i32* %8
store i32 %54, i32* %3
br label %55
55: ; preds = %51, %24, %16
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.kmod_ctx = type { i32 }
%struct.kmod_list = type { i32 }
%struct.kmod_module = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: Module alias %s not found.\0A\00"
@.str.1 = [29 x i8] c"ERROR: Module %s not found.\0A\00"
@ENOENT = global i32 0
define i32 @modinfo_alias_do(%struct.kmod_ctx* %0, i8* %1) {
%3 = alloca %struct.kmod_list*
%4 = bitcast %struct.kmod_list** %3 to i8*
store %struct.kmod_list* null, %struct.kmod_list** %3
%5 = call i32 @kmod_module_new_from_lookup(%struct.kmod_ctx* %0, i8* %1, %struct.kmod_list** %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %32
10: ; preds = %2
%11 = load %struct.kmod_list*, %struct.kmod_list** %3
%12 = icmp eq %struct.kmod_list* %11, null
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%16 = load i32, i32* @ENOENT
%17 = sub nsw i32 0, %16
br label %32
18: ; preds = %10, %18
%19 = phi %struct.kmod_list* [ %27, %18 ], [ %11, %10 ]
%20 = phi i32 [ %25, %18 ], [ %5, %10 ]
%21 = call %struct.kmod_module* @kmod_module_get_module(%struct.kmod_list* %19)
%22 = call i32 @modinfo_do(%struct.kmod_module* %21)
%23 = call i32 @kmod_module_unref(%struct.kmod_module* %21)
%24 = icmp slt i32 %22, 0
%25 = select i1 %24, i32 %22, i32 %20
%26 = load %struct.kmod_list*, %struct.kmod_list** %3
%27 = call %struct.kmod_list* @kmod_list_next(%struct.kmod_list* %26, %struct.kmod_list* %19)
%28 = icmp eq %struct.kmod_list* %27, null
br i1 %28, label %29, label %18
29: ; preds = %18
%30 = load %struct.kmod_list*, %struct.kmod_list** %3
%31 = call i32 @kmod_module_unref_list(%struct.kmod_list* %30)
br label %32
32: ; preds = %29, %13, %7
%33 = phi i32 [ %5, %7 ], [ %17, %13 ], [ %25, %29 ]
ret i32 %33
}