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

/* Variables and functions */
int EINVAL;
int ENOENT;
int ENOSYS;
int PATH_MAX;
scalar_t__ alias_normalize(char const *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ kmod_log_null(struct kmod_ctx *, char *, ...);
int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *, char *,
                                        struct kmod_list **);
int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *, char *,
                                        struct kmod_list **);
int kmod_lookup_alias_from_commands(struct kmod_ctx *, char *,
                                    struct kmod_list **);
int kmod_lookup_alias_from_config(struct kmod_ctx *, char *,
                                  struct kmod_list **);
int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *, char *,
                                       struct kmod_list **);
int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *, char *,
                                        struct kmod_list **);
int /*<<< orphan*/ kmod_module_unref_list(struct kmod_list *);
__attribute__((visibility("default"))) int
kmod_module_new_from_lookup(struct kmod_ctx *ctx, const char *given_alias,
                            struct kmod_list **list) {
  int err;
  char alias[PATH_MAX];
  if (ctx == NULL || given_alias == NULL)
    return -ENOENT;
  if (list == NULL || *list != NULL) {
    kmod_log_null(ctx, "An empty list is needed to create lookup\n");
    return -ENOSYS;
  }
  if (alias_normalize(given_alias, alias, NULL) < 0) {
    kmod_log_null(ctx, "invalid alias: %s\n", given_alias);
    return -EINVAL;
  }
  kmod_log_null(ctx, "input alias=%s, normalized=%s\n", given_alias, alias);
  err = kmod_lookup_alias_from_config(ctx, alias, list);
  do {
    if ((err) < 0)
      goto fail;
    if (*(list) != NULL)
      goto finish;
  } while (0);
  kmod_log_null(ctx, "lookup modules.dep %s\n", alias);
  err = kmod_lookup_alias_from_moddep_file(ctx, alias, list);
  do {
    if ((err) < 0)
      goto fail;
    if (*(list) != NULL)
      goto finish;
  } while (0);
  kmod_log_null(ctx, "lookup modules.symbols %s\n", alias);
  err = kmod_lookup_alias_from_symbols_file(ctx, alias, list);
  do {
    if ((err) < 0)
      goto fail;
    if (*(list) != NULL)
      goto finish;
  } while (0);
  kmod_log_null(ctx, "lookup install and remove commands %s\n", alias);
  err = kmod_lookup_alias_from_commands(ctx, alias, list);
  do {
    if ((err) < 0)
      goto fail;
    if (*(list) != NULL)
      goto finish;
  } while (0);
  kmod_log_null(ctx, "lookup modules.aliases %s\n", alias);
  err = kmod_lookup_alias_from_aliases_file(ctx, alias, list);
  do {
    if ((err) < 0)
      goto fail;
    if (*(list) != NULL)
      goto finish;
  } while (0);
  kmod_log_null(ctx, "lookup modules.builtin %s\n", alias);
  err = kmod_lookup_alias_from_builtin_file(ctx, alias, list);
  do {
    if ((err) < 0)
      goto fail;
    if (*(list) != NULL)
      goto finish;
  } while (0);
finish:
  kmod_log_null(ctx, "lookup %s=%d, list=%p\n", alias, err, *list);
  return err;
fail:
  kmod_log_null(ctx, "Failed to lookup %s\n", alias);
  kmod_module_unref_list(*list);
  *list = NULL;
  return err;
}


x86 assembly (clang, -O0):
<kmod_module_new_from_lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e6 <kmod_module_new_from_lookup+0x56>
cmpq   $0x0,-0x18(%rbp)
jne    1200 <kmod_module_new_from_lookup+0x70>
xor    %eax,%eax
mov    0x2dd1(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1509 <kmod_module_new_from_lookup+0x379>
cmpq   $0x0,-0x20(%rbp)
je     1219 <kmod_module_new_from_lookup+0x89>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1245 <kmod_module_new_from_lookup+0xb5>
mov    -0x10(%rbp),%rdi
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
xor    %eax,%eax
mov    0x2dac(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1509 <kmod_module_new_from_lookup+0x379>
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <alias_normalize@plt>
cmp    $0x0,%rax
jge    1290 <kmod_module_new_from_lookup+0x100>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
xor    %eax,%eax
mov    0x2d51(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1509 <kmod_module_new_from_lookup+0x379>
mov    -0x48(%rbp),%rcx
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
call   1040 <kmod_lookup_alias_from_config@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12cd <kmod_module_new_from_lookup+0x13d>
jmp    14cf <kmod_module_new_from_lookup+0x33f>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     12e0 <kmod_module_new_from_lookup+0x150>
jmp    149d <kmod_module_new_from_lookup+0x30d>
jmp    12e5 <kmod_module_new_from_lookup+0x155>
jmp    12ea <kmod_module_new_from_lookup+0x15a>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
lea    0xd63(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
call   1090 <kmod_lookup_alias_from_moddep_file@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1323 <kmod_module_new_from_lookup+0x193>
jmp    14cf <kmod_module_new_from_lookup+0x33f>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1336 <kmod_module_new_from_lookup+0x1a6>
jmp    149d <kmod_module_new_from_lookup+0x30d>
jmp    133b <kmod_module_new_from_lookup+0x1ab>
jmp    1340 <kmod_module_new_from_lookup+0x1b0>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
call   1030 <kmod_lookup_alias_from_symbols_file@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1379 <kmod_module_new_from_lookup+0x1e9>
jmp    14cf <kmod_module_new_from_lookup+0x33f>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     138c <kmod_module_new_from_lookup+0x1fc>
jmp    149d <kmod_module_new_from_lookup+0x30d>
jmp    1391 <kmod_module_new_from_lookup+0x201>
jmp    1396 <kmod_module_new_from_lookup+0x206>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
lea    0xce9(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
call   1070 <kmod_lookup_alias_from_commands@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    13cf <kmod_module_new_from_lookup+0x23f>
jmp    14cf <kmod_module_new_from_lookup+0x33f>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     13e2 <kmod_module_new_from_lookup+0x252>
jmp    149d <kmod_module_new_from_lookup+0x30d>
jmp    13e7 <kmod_module_new_from_lookup+0x257>
jmp    13ec <kmod_module_new_from_lookup+0x25c>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
call   10b0 <kmod_lookup_alias_from_aliases_file@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1425 <kmod_module_new_from_lookup+0x295>
jmp    14cf <kmod_module_new_from_lookup+0x33f>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1438 <kmod_module_new_from_lookup+0x2a8>
jmp    149d <kmod_module_new_from_lookup+0x30d>
jmp    143d <kmod_module_new_from_lookup+0x2ad>
jmp    1442 <kmod_module_new_from_lookup+0x2b2>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
lea    0xc7f(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
call   10a0 <kmod_lookup_alias_from_builtin_file@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    147b <kmod_module_new_from_lookup+0x2eb>
jmp    14cf <kmod_module_new_from_lookup+0x33f>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     148e <kmod_module_new_from_lookup+0x2fe>
jmp    149d <kmod_module_new_from_lookup+0x30d>
jmp    1493 <kmod_module_new_from_lookup+0x303>
jmp    1498 <kmod_module_new_from_lookup+0x308>
jmp    149d <kmod_module_new_from_lookup+0x30d>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8
lea    0xc35(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1509 <kmod_module_new_from_lookup+0x379>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
lea    0xc24(%rip),%rsi
mov    $0x0,%al
call   1060 <kmod_log_null@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <kmod_module_unref_list@plt>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x24(%rbp),%eax
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):
<kmod_module_new_from_lookup>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %rdi,%rdi
je     11f3 <kmod_module_new_from_lookup+0x63>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11f3 <kmod_module_new_from_lookup+0x63>
mov    %rdx,%r14
mov    %rdi,%r15
test   %rdx,%rdx
je     11d6 <kmod_module_new_from_lookup+0x46>
cmpq   $0x0,(%r14)
je     1212 <kmod_module_new_from_lookup+0x82>
lea    0xe23(%rip),%rsi
xor    %r13d,%r13d
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    0x2def(%rip),%rax
jmp    11fd <kmod_module_new_from_lookup+0x6d>
mov    0x2dc6(%rip),%rax
xor    %r13d,%r13d
sub    (%rax),%r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1080 <alias_normalize@plt>
test   %rax,%rax
js     1278 <kmod_module_new_from_lookup+0xe8>
lea    0xe0f(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <kmod_lookup_alias_from_config@plt>
mov    %eax,%r13d
test   %eax,%eax
js     13a1 <kmod_module_new_from_lookup+0x211>
mov    (%r14),%r8
test   %r8,%r8
je     1298 <kmod_module_new_from_lookup+0x108>
lea    0xe85(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
jmp    1200 <kmod_module_new_from_lookup+0x70>
lea    0xdab(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    0x2d3d(%rip),%rax
jmp    11fd <kmod_module_new_from_lookup+0x6d>
lea    0xdbd(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1090 <kmod_lookup_alias_from_moddep_file@plt>
mov    %eax,%r13d
test   %eax,%eax
js     13a1 <kmod_module_new_from_lookup+0x211>
mov    (%r14),%r8
test   %r8,%r8
jne    125f <kmod_module_new_from_lookup+0xcf>
lea    0xd9f(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1030 <kmod_lookup_alias_from_symbols_file@plt>
mov    %eax,%r13d
test   %eax,%eax
js     13a1 <kmod_module_new_from_lookup+0x211>
mov    (%r14),%r8
test   %r8,%r8
jne    125f <kmod_module_new_from_lookup+0xcf>
lea    0xd81(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <kmod_lookup_alias_from_commands@plt>
mov    %eax,%r13d
test   %eax,%eax
js     13a1 <kmod_module_new_from_lookup+0x211>
mov    (%r14),%r8
test   %r8,%r8
jne    125f <kmod_module_new_from_lookup+0xcf>
lea    0xd73(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10b0 <kmod_lookup_alias_from_aliases_file@plt>
mov    %eax,%r13d
test   %eax,%eax
js     13a1 <kmod_module_new_from_lookup+0x211>
mov    (%r14),%r8
test   %r8,%r8
jne    125f <kmod_module_new_from_lookup+0xcf>
lea    0xd59(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10a0 <kmod_lookup_alias_from_builtin_file@plt>
mov    %eax,%r13d
test   %eax,%eax
js     13a1 <kmod_module_new_from_lookup+0x211>
mov    (%r14),%r8
jmp    125f <kmod_module_new_from_lookup+0xcf>
lea    0xd5a(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <kmod_log_null@plt>
mov    (%r14),%rdi
call   1050 <kmod_module_unref_list@plt>
movq   $0x0,(%r14)
jmp    1200 <kmod_module_new_from_lookup+0x70>

LLVM IR (-O0):
%struct.kmod_ctx = type { i32 }
%struct.kmod_list = type { i32 }
@PATH_MAX = global i32 0
@ENOENT = global i32 0
@.str = [42 x i8] c"An empty list is needed to create lookup\0A\00"
@ENOSYS = global i32 0
@.str.1 = [19 x i8] c"invalid alias: %s\0A\00"
@EINVAL = global i32 0
@.str.2 = [31 x i8] c"input alias=%s, normalized=%s\0A\00"
@.str.3 = [23 x i8] c"lookup modules.dep %s\0A\00"
@.str.4 = [27 x i8] c"lookup modules.symbols %s\0A\00"
@.str.5 = [39 x i8] c"lookup install and remove commands %s\0A\00"
@.str.6 = [27 x i8] c"lookup modules.aliases %s\0A\00"
@.str.7 = [27 x i8] c"lookup modules.builtin %s\0A\00"
@.str.8 = [23 x i8] c"lookup %s=%d, list=%p\0A\00"
@.str.9 = [21 x i8] c"Failed to lookup %s\0A\00"
define i32 @kmod_module_new_from_lookup(%struct.kmod_ctx* %0, i8* %1, %struct.kmod_list** %2) {
%4 = alloca i32
%5 = alloca %struct.kmod_ctx*
%6 = alloca i8*
%7 = alloca %struct.kmod_list**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store %struct.kmod_ctx* %0, %struct.kmod_ctx** %5
store i8* %1, i8** %6
store %struct.kmod_list** %2, %struct.kmod_list*** %7
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 %13
store i64 %13, i64* %10
%16 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%17 = icmp eq %struct.kmod_ctx* %16, null
br i1 %17, label %21, label %18
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18, %3
%22 = load i32, i32* @ENOENT
%23 = sub nsw i32 0, %22
store i32 %23, i32* %4
store i32 1, i32* %11
br label %165
24: ; preds = %18
%25 = load %struct.kmod_list**, %struct.kmod_list*** %7
%26 = icmp eq %struct.kmod_list** %25, null
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = load %struct.kmod_list**, %struct.kmod_list*** %7
%29 = load %struct.kmod_list*, %struct.kmod_list** %28
%30 = icmp ne %struct.kmod_list* %29, null
br i1 %30, label %31, label %36
31: ; preds = %27, %24
%32 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%33 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %32, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* @ENOSYS
%35 = sub nsw i32 0, %34
store i32 %35, i32* %4
store i32 1, i32* %11
br label %165
36: ; preds = %27
%37 = load i8*, i8** %6
%38 = call i64 @alias_normalize(i8* %37, i8* %15, i32* null)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%42 = load i8*, i8** %6
%43 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EINVAL
%45 = sub nsw i32 0, %44
store i32 %45, i32* %4
store i32 1, i32* %11
br label %165
46: ; preds = %36
%47 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%48 = load i8*, i8** %6
%49 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %47, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %48, i8* %15)
%50 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%51 = load %struct.kmod_list**, %struct.kmod_list*** %7
%52 = call i32 @kmod_lookup_alias_from_config(%struct.kmod_ctx* %50, i8* %15, %struct.kmod_list** %51)
store i32 %52, i32* %8
br label %53
53: ; preds = %46
%54 = load i32, i32* %8
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %53
br label %157
57: ; preds = %53
%58 = load %struct.kmod_list**, %struct.kmod_list*** %7
%59 = load %struct.kmod_list*, %struct.kmod_list** %58
%60 = icmp ne %struct.kmod_list* %59, null
br i1 %60, label %61, label %62
61: ; preds = %57
br label %150
62: ; preds = %57
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63
%65 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%66 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %65, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%67 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%68 = load %struct.kmod_list**, %struct.kmod_list*** %7
%69 = call i32 @kmod_lookup_alias_from_moddep_file(%struct.kmod_ctx* %67, i8* %15, %struct.kmod_list** %68)
store i32 %69, i32* %8
br label %70
70: ; preds = %64
%71 = load i32, i32* %8
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %70
br label %157
74: ; preds = %70
%75 = load %struct.kmod_list**, %struct.kmod_list*** %7
%76 = load %struct.kmod_list*, %struct.kmod_list** %75
%77 = icmp ne %struct.kmod_list* %76, null
br i1 %77, label %78, label %79
78: ; preds = %74
br label %150
79: ; preds = %74
br label %80
80: ; preds = %79
br label %81
81: ; preds = %80
%82 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%83 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %82, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%84 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%85 = load %struct.kmod_list**, %struct.kmod_list*** %7
%86 = call i32 @kmod_lookup_alias_from_symbols_file(%struct.kmod_ctx* %84, i8* %15, %struct.kmod_list** %85)
store i32 %86, i32* %8
br label %87
87: ; preds = %81
%88 = load i32, i32* %8
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %87
br label %157
91: ; preds = %87
%92 = load %struct.kmod_list**, %struct.kmod_list*** %7
%93 = load %struct.kmod_list*, %struct.kmod_list** %92
%94 = icmp ne %struct.kmod_list* %93, null
br i1 %94, label %95, label %96
95: ; preds = %91
br label %150
96: ; preds = %91
br label %97
97: ; preds = %96
br label %98
98: ; preds = %97
%99 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%100 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %99, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%101 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%102 = load %struct.kmod_list**, %struct.kmod_list*** %7
%103 = call i32 @kmod_lookup_alias_from_commands(%struct.kmod_ctx* %101, i8* %15, %struct.kmod_list** %102)
store i32 %103, i32* %8
br label %104
104: ; preds = %98
%105 = load i32, i32* %8
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %108
107: ; preds = %104
br label %157
108: ; preds = %104
%109 = load %struct.kmod_list**, %struct.kmod_list*** %7
%110 = load %struct.kmod_list*, %struct.kmod_list** %109
%111 = icmp ne %struct.kmod_list* %110, null
br i1 %111, label %112, label %113
112: ; preds = %108
br label %150
113: ; preds = %108
br label %114
114: ; preds = %113
br label %115
115: ; preds = %114
%116 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%117 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %116, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %15)
%118 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%119 = load %struct.kmod_list**, %struct.kmod_list*** %7
%120 = call i32 @kmod_lookup_alias_from_aliases_file(%struct.kmod_ctx* %118, i8* %15, %struct.kmod_list** %119)
store i32 %120, i32* %8
br label %121
121: ; preds = %115
%122 = load i32, i32* %8
%123 = icmp slt i32 %122, 0
br i1 %123, label %124, label %125
124: ; preds = %121
br label %157
125: ; preds = %121
%126 = load %struct.kmod_list**, %struct.kmod_list*** %7
%127 = load %struct.kmod_list*, %struct.kmod_list** %126
%128 = icmp ne %struct.kmod_list* %127, null
br i1 %128, label %129, label %130
129: ; preds = %125
br label %150
130: ; preds = %125
br label %131
131: ; preds = %130
br label %132
132: ; preds = %131
%133 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%134 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %133, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %15)
%135 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%136 = load %struct.kmod_list**, %struct.kmod_list*** %7
%137 = call i32 @kmod_lookup_alias_from_builtin_file(%struct.kmod_ctx* %135, i8* %15, %struct.kmod_list** %136)
store i32 %137, i32* %8
br label %138
138: ; preds = %132
%139 = load i32, i32* %8
%140 = icmp slt i32 %139, 0
br i1 %140, label %141, label %142
141: ; preds = %138
br label %157
142: ; preds = %138
%143 = load %struct.kmod_list**, %struct.kmod_list*** %7
%144 = load %struct.kmod_list*, %struct.kmod_list** %143
%145 = icmp ne %struct.kmod_list* %144, null
br i1 %145, label %146, label %147
146: ; preds = %142
br label %150
147: ; preds = %142
br label %148
148: ; preds = %147
br label %149
149: ; preds = %148
br label %150
150: ; preds = %149, %146, %129, %112, %95, %78, %61
%151 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%152 = load i32, i32* %8
%153 = load %struct.kmod_list**, %struct.kmod_list*** %7
%154 = load %struct.kmod_list*, %struct.kmod_list** %153
%155 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %151, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %15, i32 %152, %struct.kmod_list* %154)
%156 = load i32, i32* %8
store i32 %156, i32* %4
store i32 1, i32* %11
br label %165
157: ; preds = %141, %124, %107, %90, %73, %56
%158 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%159 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %158, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %15)
%160 = load %struct.kmod_list**, %struct.kmod_list*** %7
%161 = load %struct.kmod_list*, %struct.kmod_list** %160
%162 = call i32 @kmod_module_unref_list(%struct.kmod_list* %161)
%163 = load %struct.kmod_list**, %struct.kmod_list*** %7
store %struct.kmod_list* null, %struct.kmod_list** %163
%164 = load i32, i32* %8
store i32 %164, i32* %4
store i32 1, i32* %11
br label %165
165: ; preds = %157, %150, %40, %31, %21
%166 = load i8*, i8** %9
%167 = load i32, i32* %4
ret i32 %167
}

LLVM IR (-O2):
%struct.kmod_ctx = type { i32 }
%struct.kmod_list = type { i32 }
@PATH_MAX = global i32 0
@ENOENT = global i32 0
@.str = [42 x i8] c"An empty list is needed to create lookup\0A\00"
@ENOSYS = global i32 0
@.str.1 = [19 x i8] c"invalid alias: %s\0A\00"
@EINVAL = global i32 0
@.str.2 = [31 x i8] c"input alias=%s, normalized=%s\0A\00"
@.str.3 = [23 x i8] c"lookup modules.dep %s\0A\00"
@.str.4 = [27 x i8] c"lookup modules.symbols %s\0A\00"
@.str.5 = [39 x i8] c"lookup install and remove commands %s\0A\00"
@.str.6 = [27 x i8] c"lookup modules.aliases %s\0A\00"
@.str.7 = [27 x i8] c"lookup modules.builtin %s\0A\00"
@.str.8 = [23 x i8] c"lookup %s=%d, list=%p\0A\00"
@.str.9 = [21 x i8] c"Failed to lookup %s\0A\00"
define i32 @kmod_module_new_from_lookup(%struct.kmod_ctx* %0, i8* %1, %struct.kmod_list** %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp eq %struct.kmod_ctx* %0, null
%8 = icmp eq i8* %1, null
%9 = or i1 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* @ENOENT
%12 = sub nsw i32 0, %11
br label %79
13: ; preds = %3
%14 = icmp eq %struct.kmod_list** %2, null
br i1 %14, label %18, label %15
15: ; preds = %13
%16 = load %struct.kmod_list*, %struct.kmod_list** %2
%17 = icmp eq %struct.kmod_list* %16, null
br i1 %17, label %22, label %18
18: ; preds = %15, %13
%19 = tail call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @ENOSYS
%21 = sub nsw i32 0, %20
br label %79
22: ; preds = %15
%23 = call i64 @alias_normalize(i8* %1, i8* %6, i32* null)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%27 = load i32, i32* @EINVAL
%28 = sub nsw i32 0, %27
br label %79
29: ; preds = %22
%30 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %6)
%31 = call i32 @kmod_lookup_alias_from_config(%struct.kmod_ctx* %0, i8* %6, %struct.kmod_list** %2)
%32 = icmp slt i32 %31, 0
br i1 %32, label %74, label %33
33: ; preds = %29
%34 = load %struct.kmod_list*, %struct.kmod_list** %2
%35 = icmp eq %struct.kmod_list* %34, null
br i1 %35, label %36, label %70
36: ; preds = %33
%37 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%38 = call i32 @kmod_lookup_alias_from_moddep_file(%struct.kmod_ctx* %0, i8* %6, %struct.kmod_list** %2)
%39 = icmp slt i32 %38, 0
br i1 %39, label %74, label %40
40: ; preds = %36
%41 = load %struct.kmod_list*, %struct.kmod_list** %2
%42 = icmp eq %struct.kmod_list* %41, null
br i1 %42, label %43, label %70
43: ; preds = %40
%44 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%45 = call i32 @kmod_lookup_alias_from_symbols_file(%struct.kmod_ctx* %0, i8* %6, %struct.kmod_list** %2)
%46 = icmp slt i32 %45, 0
br i1 %46, label %74, label %47
47: ; preds = %43
%48 = load %struct.kmod_list*, %struct.kmod_list** %2
%49 = icmp eq %struct.kmod_list* %48, null
br i1 %49, label %50, label %70
50: ; preds = %47
%51 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%52 = call i32 @kmod_lookup_alias_from_commands(%struct.kmod_ctx* %0, i8* %6, %struct.kmod_list** %2)
%53 = icmp slt i32 %52, 0
br i1 %53, label %74, label %54
54: ; preds = %50
%55 = load %struct.kmod_list*, %struct.kmod_list** %2
%56 = icmp eq %struct.kmod_list* %55, null
br i1 %56, label %57, label %70
57: ; preds = %54
%58 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%59 = call i32 @kmod_lookup_alias_from_aliases_file(%struct.kmod_ctx* %0, i8* %6, %struct.kmod_list** %2)
%60 = icmp slt i32 %59, 0
br i1 %60, label %74, label %61
61: ; preds = %57
%62 = load %struct.kmod_list*, %struct.kmod_list** %2
%63 = icmp eq %struct.kmod_list* %62, null
br i1 %63, label %64, label %70
64: ; preds = %61
%65 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %6)
%66 = call i32 @kmod_lookup_alias_from_builtin_file(%struct.kmod_ctx* %0, i8* %6, %struct.kmod_list** %2)
%67 = icmp slt i32 %66, 0
br i1 %67, label %74, label %68
68: ; preds = %64
%69 = load %struct.kmod_list*, %struct.kmod_list** %2
br label %70
70: ; preds = %68, %61, %54, %47, %40, %33
%71 = phi %struct.kmod_list* [ %34, %33 ], [ %41, %40 ], [ %48, %47 ], [ %55, %54 ], [ %62, %61 ], [ %69, %68 ]
%72 = phi i32 [ %31, %33 ], [ %38, %40 ], [ %45, %47 ], [ %52, %54 ], [ %59, %61 ], [ %66, %68 ]
%73 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %6, i32 %72, %struct.kmod_list* %71)
br label %79
74: ; preds = %64, %57, %50, %43, %36, %29
%75 = phi i32 [ %31, %29 ], [ %38, %36 ], [ %45, %43 ], [ %52, %50 ], [ %59, %57 ], [ %66, %64 ]
%76 = call i32 (%struct.kmod_ctx*, i8*, ...) @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %6)
%77 = load %struct.kmod_list*, %struct.kmod_list** %2
%78 = call i32 @kmod_module_unref_list(%struct.kmod_list* %77)
store %struct.kmod_list* null, %struct.kmod_list** %2
br label %79
79: ; preds = %74, %70, %25, %18, %10
%80 = phi i32 [ %12, %10 ], [ %21, %18 ], [ %28, %25 ], [ %75, %74 ], [ %72, %70 ]
ret i32 %80
}