#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 /*<<< orphan*/ free(char *);
struct kmod_list *kmod_list_append(struct kmod_list *, struct kmod_module *);
int /*<<< orphan*/ kmod_log_null(struct kmod_ctx *, char *, char const *,
                                 int /*<<< orphan*/);
int kmod_module_new_from_name(struct kmod_ctx *, char const *,
                              struct kmod_module **);
int /*<<< orphan*/ kmod_module_parse_depline(struct kmod_module *, char *);
char *kmod_search_moddep(struct kmod_ctx *, char const *);
scalar_t__ strchr(char const *, char);
int /*<<< orphan*/ strerror(int);
int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name,
                                       struct kmod_list **list) {
  char *line;
  int n = 0;
  if (strchr(name, ':'))
    return 0;
  line = kmod_search_moddep(ctx, name);
  if (line != NULL) {
    struct kmod_module *mod;
    n = kmod_module_new_from_name(ctx, name, &mod);
    if (n < 0) {
      kmod_log_null(ctx, "Could not create module from name %s: %s\n", name,
                    strerror(-n));
      goto finish;
    }
    *list = kmod_list_append(*list, mod);
    kmod_module_parse_depline(mod, line);
  }
finish:
  free(line);
  return n;
}


x86 assembly (clang, -O0):
<kmod_lookup_alias_from_moddep_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
je     11bf <kmod_lookup_alias_from_moddep_file+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    1269 <kmod_lookup_alias_from_moddep_file+0xe9>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <kmod_search_moddep@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1255 <kmod_lookup_alias_from_moddep_file+0xd5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1080 <kmod_module_new_from_name@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    122e <kmod_lookup_alias_from_moddep_file+0xae>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
xor    %edi,%edi
sub    -0x2c(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
lea    0xddc(%rip),%rsi
call   1060 <kmod_log_null@plt>
jmp    125a <kmod_lookup_alias_from_moddep_file+0xda>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <kmod_list_append@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <kmod_module_parse_depline@plt>
jmp    125a <kmod_lookup_alias_from_moddep_file+0xda>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kmod_lookup_alias_from_moddep_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
mov    $0x3a,%esi
call   1070 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    121a <kmod_lookup_alias_from_moddep_file+0x9a>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <kmod_search_moddep@plt>
mov    %rax,%r14
test   %rax,%rax
je     11f1 <kmod_lookup_alias_from_moddep_file+0x71>
lea    0x8(%rsp),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1080 <kmod_module_new_from_name@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11f5 <kmod_lookup_alias_from_moddep_file+0x75>
mov    (%r15),%rdi
mov    0x8(%rsp),%rsi
call   1050 <kmod_list_append@plt>
mov    %rax,(%r15)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1090 <kmod_module_parse_depline@plt>
jmp    1212 <kmod_lookup_alias_from_moddep_file+0x92>
xor    %ebp,%ebp
jmp    1212 <kmod_lookup_alias_from_moddep_file+0x92>
mov    %ebp,%edi
neg    %edi
call   10a0 <strerror@plt>
lea    0xdfb(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1060 <kmod_log_null@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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 }
@.str = [42 x i8] c"Could not create module from name %s: %s\0A\00"
define i32 @kmod_lookup_alias_from_moddep_file(%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 i8*
%9 = alloca i32
%10 = alloca %struct.kmod_module*
store %struct.kmod_ctx* %0, %struct.kmod_ctx** %5
store i8* %1, i8** %6
store %struct.kmod_list** %2, %struct.kmod_list*** %7
store i32 0, i32* %9
%11 = load i8*, i8** %6
%12 = call i64 @strchr(i8* %11, i8 signext 58)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %48
15: ; preds = %3
%16 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%17 = load i8*, i8** %6
%18 = call i8* @kmod_search_moddep(%struct.kmod_ctx* %16, i8* %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %43
21: ; preds = %15
%22 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%23 = load i8*, i8** %6
%24 = call i32 @kmod_module_new_from_name(%struct.kmod_ctx* %22, i8* %23, %struct.kmod_module** %10)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %21
%28 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%29 = load i8*, i8** %6
%30 = load i32, i32* %9
%31 = sub nsw i32 0, %30
%32 = call i32 @strerror(i32 %31)
%33 = call i32 @kmod_log_null(%struct.kmod_ctx* %28, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %32)
br label %44
34: ; preds = %21
%35 = load %struct.kmod_list**, %struct.kmod_list*** %7
%36 = load %struct.kmod_list*, %struct.kmod_list** %35
%37 = load %struct.kmod_module*, %struct.kmod_module** %10
%38 = call %struct.kmod_list* @kmod_list_append(%struct.kmod_list* %36, %struct.kmod_module* %37)
%39 = load %struct.kmod_list**, %struct.kmod_list*** %7
store %struct.kmod_list* %38, %struct.kmod_list** %39
%40 = load %struct.kmod_module*, %struct.kmod_module** %10
%41 = load i8*, i8** %8
%42 = call i32 @kmod_module_parse_depline(%struct.kmod_module* %40, i8* %41)
br label %43
43: ; preds = %34, %15
br label %44
44: ; preds = %43, %27
%45 = load i8*, i8** %8
%46 = call i32 @free(i8* %45)
%47 = load i32, i32* %9
store i32 %47, i32* %4
br label %48
48: ; preds = %44, %14
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
%struct.kmod_ctx = type { i32 }
%struct.kmod_list = type { i32 }
%struct.kmod_module = type { i32 }
@.str = [42 x i8] c"Could not create module from name %s: %s\0A\00"
define i32 @kmod_lookup_alias_from_moddep_file(%struct.kmod_ctx* %0, i8* %1, %struct.kmod_list** nocapture %2) {
%4 = alloca %struct.kmod_module*
%5 = tail call i64 @strchr(i8* %1, i8 signext 58)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %28
7: ; preds = %3
%8 = tail call i8* @kmod_search_moddep(%struct.kmod_ctx* %0, i8* %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %25, label %10
10: ; preds = %7
%11 = bitcast %struct.kmod_module** %4 to i8*
%12 = call i32 @kmod_module_new_from_name(%struct.kmod_ctx* %0, i8* %1, %struct.kmod_module** %4)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = sub nsw i32 0, %12
%16 = call i32 @strerror(i32 %15)
%17 = call i32 @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %16)
br label %24
18: ; preds = %10
%19 = load %struct.kmod_list*, %struct.kmod_list** %2
%20 = load %struct.kmod_module*, %struct.kmod_module** %4
%21 = call %struct.kmod_list* @kmod_list_append(%struct.kmod_list* %19, %struct.kmod_module* %20)
store %struct.kmod_list* %21, %struct.kmod_list** %2
%22 = load %struct.kmod_module*, %struct.kmod_module** %4
%23 = call i32 @kmod_module_parse_depline(%struct.kmod_module* %22, i8* %8)
br label %24
24: ; preds = %14, %18
br label %25
25: ; preds = %24, %7
%26 = phi i32 [ %12, %24 ], [ 0, %7 ]
%27 = call i32 @free(i8* %8)
br label %28
28: ; preds = %3, %25
%29 = phi i32 [ %26, %25 ], [ 0, %3 ]
ret i32 %29
}