#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 */
struct kmod_list *kmod_list_append_list(struct kmod_list *, struct kmod_list *);
int /*<<< orphan*/ kmod_log_null(struct kmod_ctx *, char *, char const *);
int kmod_module_new_from_lookup(struct kmod_ctx *, char const *,
                                struct kmod_list **);
struct kmod_list *lookup_softdep(struct kmod_ctx *ctx, const char *const *array,
                                 unsigned int count) {
  struct kmod_list *ret = NULL;
  unsigned i;
  for (i = 0; i < count; i++) {
    const char *depname = array[i];
    struct kmod_list *lst = NULL;
    int err;
    err = kmod_module_new_from_lookup(ctx, depname, &lst);
    if (err < 0) {
      kmod_log_null(
          ctx, "failed to lookup soft dependency '%s', continuing anyway.\n",
          depname);
      continue;
    } else if (lst != NULL)
      ret = kmod_list_append_list(ret, lst);
  }
  return ret;
}


x86 assembly (clang, -O0):
<lookup_softdep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11e0 <lookup_softdep+0xb0>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <kmod_module_new_from_lookup@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    11ac <lookup_softdep+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1030 <kmod_log_null@plt>
jmp    11d2 <lookup_softdep+0xa2>
cmpq   $0x0,-0x38(%rbp)
je     11c8 <lookup_softdep+0x98>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <kmod_list_append_list@plt>
mov    %rax,-0x20(%rbp)
jmp    11cd <lookup_softdep+0x9d>
jmp    11d2 <lookup_softdep+0xa2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1152 <lookup_softdep+0x22>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup_softdep>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     119f <lookup_softdep+0x6f>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%r13d
xor    %r15d,%r15d
xor    %r12d,%r12d
jmp    116b <lookup_softdep+0x3b>
mov    %rbx,%rdi
lea    0xea6(%rip),%rsi
mov    %rbp,%rdx
call   1030 <kmod_log_null@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     11a2 <lookup_softdep+0x72>
mov    (%r14,%r15,8),%rbp
movq   $0x0,(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %rsp,%rdx
call   1040 <kmod_module_new_from_lookup@plt>
test   %eax,%eax
js     1150 <lookup_softdep+0x20>
mov    (%rsp),%rsi
test   %rsi,%rsi
je     1162 <lookup_softdep+0x32>
mov    %r12,%rdi
call   1050 <kmod_list_append_list@plt>
mov    %rax,%r12
jmp    1162 <lookup_softdep+0x32>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.kmod_list = type { i32 }
%struct.kmod_ctx = type { i32 }
@.str = [59 x i8] c"failed to lookup soft dependency '%s', continuing anyway.\0A\00"
define %struct.kmod_list* @lookup_softdep(%struct.kmod_ctx* %0, i8** %1, i32 %2) {
%4 = alloca %struct.kmod_ctx*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.kmod_list*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.kmod_list*
%11 = alloca i32
store %struct.kmod_ctx* %0, %struct.kmod_ctx** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store %struct.kmod_list* null, %struct.kmod_list** %7
store i32 0, i32* %8
br label %12
12: ; preds = %40, %3
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %43
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %8
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
store i8* %21, i8** %9
store %struct.kmod_list* null, %struct.kmod_list** %10
%22 = load %struct.kmod_ctx*, %struct.kmod_ctx** %4
%23 = load i8*, i8** %9
%24 = call i32 @kmod_module_new_from_lookup(%struct.kmod_ctx* %22, i8* %23, %struct.kmod_list** %10)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %16
%28 = load %struct.kmod_ctx*, %struct.kmod_ctx** %4
%29 = load i8*, i8** %9
%30 = call i32 @kmod_log_null(%struct.kmod_ctx* %28, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %40
31: ; preds = %16
%32 = load %struct.kmod_list*, %struct.kmod_list** %10
%33 = icmp ne %struct.kmod_list* %32, null
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load %struct.kmod_list*, %struct.kmod_list** %7
%36 = load %struct.kmod_list*, %struct.kmod_list** %10
%37 = call %struct.kmod_list* @kmod_list_append_list(%struct.kmod_list* %35, %struct.kmod_list* %36)
store %struct.kmod_list* %37, %struct.kmod_list** %7
br label %38
38: ; preds = %34, %31
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39, %27
%41 = load i32, i32* %8
%42 = add i32 %41, 1
store i32 %42, i32* %8
br label %12
43: ; preds = %12
%44 = load %struct.kmod_list*, %struct.kmod_list** %7
ret %struct.kmod_list* %44
}

LLVM IR (-O2):
%struct.kmod_list = type { i32 }
%struct.kmod_ctx = type { i32 }
@.str = [59 x i8] c"failed to lookup soft dependency '%s', continuing anyway.\0A\00"
define %struct.kmod_list* @lookup_softdep(%struct.kmod_ctx* %0, i8** nocapture %1, i32 %2) {
%4 = alloca %struct.kmod_list*
%5 = icmp eq i32 %2, 0
br i1 %5, label %27, label %6
6: ; preds = %3
%7 = bitcast %struct.kmod_list** %4 to i8*
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %6, %23
%10 = phi i64 [ 0, %6 ], [ %25, %23 ]
%11 = phi %struct.kmod_list* [ null, %6 ], [ %24, %23 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %10
%13 = load i8*, i8** %12
store %struct.kmod_list* null, %struct.kmod_list** %4
%14 = call i32 @kmod_module_new_from_lookup(%struct.kmod_ctx* %0, i8* %13, %struct.kmod_list** %4)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = call i32 @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %23
18: ; preds = %9
%19 = load %struct.kmod_list*, %struct.kmod_list** %4
%20 = icmp eq %struct.kmod_list* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call %struct.kmod_list* @kmod_list_append_list(%struct.kmod_list* %11, %struct.kmod_list* %19)
br label %23
23: ; preds = %21, %18, %16
%24 = phi %struct.kmod_list* [ %11, %16 ], [ %22, %21 ], [ %11, %18 ]
%25 = add nuw nsw i64 %10, 1
%26 = icmp eq i64 %25, %8
br i1 %26, label %27, label %9
27: ; preds = %23, %3
%28 = phi %struct.kmod_list* [ null, %3 ], [ %24, %23 ]
ret %struct.kmod_list* %28
}