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

/* Variables and functions */
int ENOENT;
int PATH_MAX;
int kmod_module_new(struct kmod_ctx *, char *, char *, size_t,
                    int /*<<< orphan*/ *, int /*<<< orphan*/,
                    struct kmod_module **);
int /*<<< orphan*/ modname_normalize(char const *, char *, size_t *);
__attribute__((visibility("default"))) int
kmod_module_new_from_name(struct kmod_ctx *ctx, const char *name,
                          struct kmod_module **mod) {
  size_t namelen;
  char name_norm[PATH_MAX];
  if (ctx == NULL || name == NULL || mod == NULL)
    return -ENOENT;
  modname_normalize(name, name_norm, &namelen);
  return kmod_module_new(ctx, name_norm, name_norm, namelen, NULL, 0, mod);
}


x86 assembly (clang, -O0):
<kmod_module_new_from_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2eb5(%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     1181 <kmod_module_new_from_name+0x61>
cmpq   $0x0,-0x18(%rbp)
je     1181 <kmod_module_new_from_name+0x61>
cmpq   $0x0,-0x20(%rbp)
jne    119b <kmod_module_new_from_name+0x7b>
xor    %eax,%eax
mov    0x2e46(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    11e2 <kmod_module_new_from_name+0xc2>
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rdx
call   1030 <modname_normalize@plt>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
xor    %esi,%esi
mov    %esi,%r8d
xor    %r9d,%r9d
sub    $0x10,%rsp
mov    %rdx,%rsi
mov    %rax,(%rsp)
call   1040 <kmod_module_new@plt>
add    $0x10,%rsp
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_name>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%r12
mov    0x2eb7(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %rdi,%rdi
je     1194 <kmod_module_new_from_name+0x74>
test   %rsi,%rsi
je     1194 <kmod_module_new_from_name+0x74>
mov    %rdx,%r14
test   %rdx,%rdx
je     1194 <kmod_module_new_from_name+0x74>
mov    %rdi,%r15
lea    -0x28(%rbp),%rdx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1030 <modname_normalize@plt>
mov    -0x28(%rbp),%rcx
sub    $0x8,%rsp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %r14
call   1040 <kmod_module_new@plt>
add    $0x10,%rsp
jmp    119f <kmod_module_new_from_name+0x7f>
mov    0x2e35(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
mov    %r12,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.kmod_ctx = type { i32 }
%struct.kmod_module = type { i32 }
@PATH_MAX = global i32 0
@ENOENT = global i32 0
define i32 @kmod_module_new_from_name(%struct.kmod_ctx* %0, i8* %1, %struct.kmod_module** %2) {
%4 = alloca i32
%5 = alloca %struct.kmod_ctx*
%6 = alloca i8*
%7 = alloca %struct.kmod_module**
%8 = alloca i64
%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_module** %2, %struct.kmod_module*** %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 %24, label %18
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load %struct.kmod_module**, %struct.kmod_module*** %7
%23 = icmp eq %struct.kmod_module** %22, null
br i1 %23, label %24, label %27
24: ; preds = %21, %18, %3
%25 = load i32, i32* @ENOENT
%26 = sub nsw i32 0, %25
store i32 %26, i32* %4
store i32 1, i32* %11
br label %34
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = call i32 @modname_normalize(i8* %28, i8* %15, i64* %8)
%30 = load %struct.kmod_ctx*, %struct.kmod_ctx** %5
%31 = load i64, i64* %8
%32 = load %struct.kmod_module**, %struct.kmod_module*** %7
%33 = call i32 @kmod_module_new(%struct.kmod_ctx* %30, i8* %15, i8* %15, i64 %31, i32* null, i32 0, %struct.kmod_module** %32)
store i32 %33, i32* %4
store i32 1, i32* %11
br label %34
34: ; preds = %27, %24
%35 = load i8*, i8** %9
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
%struct.kmod_ctx = type { i32 }
%struct.kmod_module = type { i32 }
@PATH_MAX = global i32 0
@ENOENT = global i32 0
define i32 @kmod_module_new_from_name(%struct.kmod_ctx* %0, i8* %1, %struct.kmod_module** %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = icmp eq %struct.kmod_ctx* %0, null
%11 = icmp eq i8* %1, null
%12 = or i1 %10, %11
%13 = icmp eq %struct.kmod_module** %2, null
%14 = or i1 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @ENOENT
%17 = sub nsw i32 0, %16
br label %22
18: ; preds = %3
%19 = call i32 @modname_normalize(i8* %1, i8* %9, i64* %4)
%20 = load i64, i64* %4
%21 = call i32 @kmod_module_new(%struct.kmod_ctx* %0, i8* %9, i8* %9, i64 %20, i32* null, i32 0, %struct.kmod_module** %2)
br label %22
22: ; preds = %18, %15
%23 = phi i32 [ %17, %15 ], [ %21, %18 ]
ret i32 %23
}