#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 ENAMETOOLONG;
int PATH_MAX;
int kmod_module_new(struct kmod_ctx *, char *, char const *, size_t,
                    char const *, size_t, struct kmod_module **);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
int kmod_module_new_from_alias(struct kmod_ctx *ctx, const char *alias,
                               const char *name, struct kmod_module **mod) {
  int err;
  char key[PATH_MAX];
  size_t namelen = strlen(name);
  size_t aliaslen = strlen(alias);
  if (namelen + aliaslen + 2 > PATH_MAX)
    return -ENAMETOOLONG;
  memcpy(key, name, namelen);
  memcpy(key + namelen + 1, alias, aliaslen + 1);
  key[namelen] = '\\';
  err = kmod_module_new(ctx, key, name, namelen, alias, aliaslen, mod);
  if (err < 0)
    return err;
  return 0;
}


x86 assembly (clang, -O0):
<kmod_module_new_from_alias>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
add    -0x50(%rbp),%rax
add    $0x2,%rax
mov    0x2e4f(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jbe    11c7 <kmod_module_new_from_alias+0x97>
xor    %eax,%eax
mov    0x2e22(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1257 <kmod_module_new_from_alias+0x127>
mov    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x60(%rbp),%rdi
add    -0x48(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x50(%rbp),%rdx
add    $0x1,%rdx
call   1040 <memcpy@plt>
mov    -0x60(%rbp),%rsi
mov    -0x48(%rbp),%rax
movb   $0x5c,(%rsi,%rax,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x50(%rbp),%r9
mov    -0x28(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1050 <kmod_module_new@plt>
add    $0x10,%rsp
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1249 <kmod_module_new_from_alias+0x119>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1257 <kmod_module_new_from_alias+0x127>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kmod_module_new_from_alias>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,-0x40(%rbp)
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,-0x30(%rbp)
mov    0x2e9a(%rip),%rax
movslq (%rax),%r15
mov    %r15d,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rdx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
mov    %r12,-0x38(%rbp)
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
add    %r14,%rax
add    $0x2,%rax
cmp    %r15,%rax
jbe    11a0 <kmod_module_new_from_alias+0x70>
mov    0x2e3e(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    11f8 <kmod_module_new_from_alias+0xc8>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
lea    (%rbx,%r14,1),%rdi
add    $0x1,%rdi
mov    %r12,%rdx
add    $0x1,%rdx
mov    -0x38(%rbp),%r15
mov    %r15,%rsi
call   1040 <memcpy@plt>
movb   $0x5c,(%rbx,%r14,1)
sub    $0x8,%rsp
mov    -0x30(%rbp),%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r15,%r8
mov    %r12,%r9
push   -0x40(%rbp)
call   1050 <kmod_module_new@plt>
add    $0x10,%rsp
mov    %eax,%ecx
sar    $0x1f,%eax
and    %ecx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
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
@ENAMETOOLONG = global i32 0
define i32 @kmod_module_new_from_alias(%struct.kmod_ctx* %0, i8* %1, i8* %2, %struct.kmod_module** %3) {
%5 = alloca i32
%6 = alloca %struct.kmod_ctx*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.kmod_module**
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
store %struct.kmod_ctx* %0, %struct.kmod_ctx** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store %struct.kmod_module** %3, %struct.kmod_module*** %9
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %11
%19 = alloca i8, i64 %17
store i64 %17, i64* %12
%20 = load i8*, i8** %8
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %13
%22 = load i8*, i8** %7
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %14
%24 = load i64, i64* %13
%25 = load i64, i64* %14
%26 = add i64 %24, %25
%27 = add i64 %26, 2
%28 = load i32, i32* @PATH_MAX
%29 = sext i32 %28 to i64
%30 = icmp ugt i64 %27, %29
br i1 %30, label %31, label %34
31: ; preds = %4
%32 = load i32, i32* @ENAMETOOLONG
%33 = sub nsw i32 0, %32
store i32 %33, i32* %5
store i32 1, i32* %15
br label %59
34: ; preds = %4
%35 = load i8*, i8** %8
%36 = load i64, i64* %13
%37 = call i32 @memcpy(i8* %19, i8* %35, i64 %36)
%38 = load i64, i64* %13
%39 = getelementptr inbounds i8, i8* %19, i64 %38
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8*, i8** %7
%42 = load i64, i64* %14
%43 = add i64 %42, 1
%44 = call i32 @memcpy(i8* %40, i8* %41, i64 %43)
%45 = load i64, i64* %13
%46 = getelementptr inbounds i8, i8* %19, i64 %45
store i8 92, i8* %46
%47 = load %struct.kmod_ctx*, %struct.kmod_ctx** %6
%48 = load i8*, i8** %8
%49 = load i64, i64* %13
%50 = load i8*, i8** %7
%51 = load i64, i64* %14
%52 = load %struct.kmod_module**, %struct.kmod_module*** %9
%53 = call i32 @kmod_module_new(%struct.kmod_ctx* %47, i8* %19, i8* %48, i64 %49, i8* %50, i64 %51, %struct.kmod_module** %52)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %34
%57 = load i32, i32* %10
store i32 %57, i32* %5
store i32 1, i32* %15
br label %59
58: ; preds = %34
store i32 0, i32* %5
store i32 1, i32* %15
br label %59
59: ; preds = %58, %56, %31
%60 = load i8*, i8** %11
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
%struct.kmod_ctx = type { i32 }
%struct.kmod_module = type { i32 }
@PATH_MAX = global i32 0
@ENAMETOOLONG = global i32 0
define i32 @kmod_module_new_from_alias(%struct.kmod_ctx* %0, i8* %1, i8* %2, %struct.kmod_module** %3) {
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = add i64 %8, 2
%11 = add i64 %10, %9
%12 = sext i32 %5 to i64
%13 = icmp ugt i64 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* @ENAMETOOLONG
%16 = sub nsw i32 0, %15
br label %26
17: ; preds = %4
%18 = call i32 @memcpy(i8* %7, i8* %2, i64 %8)
%19 = getelementptr inbounds i8, i8* %7, i64 %8
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = add i64 %9, 1
%22 = call i32 @memcpy(i8* %20, i8* %1, i64 %21)
store i8 92, i8* %19
%23 = call i32 @kmod_module_new(%struct.kmod_ctx* %0, i8* %7, i8* %2, i64 %8, i8* %1, i64 %9, %struct.kmod_module** %3)
%24 = icmp slt i32 %23, 0
%25 = select i1 %24, i32 %23, i32 0
br label %26
26: ; preds = %17, %14
%27 = phi i32 [ %16, %14 ], [ %25, %17 ]
ret i32 %27
}