#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 */
typedef int /*<<< orphan*/ alias;

/* Variables and functions */
int dmCreateAlias(char const *, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ logmsg(int, char *, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ randomHexStrCat(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char const *);
char *dmCreateDynamicAlias(const char *aSrcDevice, const char *aAliasPrefix) {
  char alias[64];
  if (aAliasPrefix && (strlen(aAliasPrefix) < 32)) {
    snprintf(alias, sizeof(alias), "alias_%s_", aAliasPrefix);
  } else {
    strcpy(alias, "alias_");
  }
  if (!randomHexStrCat(alias, 4)) {
    return NULL;
  }
  char *aliasPathname = malloc(strlen("/dev/mapper/") + strlen(alias) + 1);
  if (!aliasPathname) {
    logmsg(1, "malloc error for full filename of dynamic alias: %s\n",
           strerror(errno));
    return NULL;
  }
  sprintf(aliasPathname, "/dev/mapper/%s", alias);
  bool aliasSuccessful = dmCreateAlias(aSrcDevice, alias);
  if (!aliasSuccessful) {
    free(aliasPathname);
    return NULL;
  }
  return aliasPathname;
}


x86 assembly (clang, -O0):
<dmCreateDynamicAlias>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11eb <dmCreateDynamicAlias+0x4b>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x20,%eax
jge    11eb <dmCreateDynamicAlias+0x4b>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
lea    0xe1f(%rip),%rdx
call   1060 <snprintf@plt>
jmp    11fb <dmCreateDynamicAlias+0x5b>
lea    -0x60(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x60(%rbp),%rdi
mov    $0x4,%esi
call   10a0 <randomHexStrCat@plt>
cmp    $0x0,%eax
jne    121f <dmCreateDynamicAlias+0x7f>
movq   $0x0,-0x8(%rbp)
jmp    12cd <dmCreateDynamicAlias+0x12d>
lea    0xdeb(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x70(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    1281 <dmCreateDynamicAlias+0xe1>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xdaf(%rip),%rsi
call   1090 <logmsg@plt>
movq   $0x0,-0x8(%rbp)
jmp    12cd <dmCreateDynamicAlias+0x12d>
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xdc3(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1070 <dmCreateAlias@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jne    12c5 <dmCreateDynamicAlias+0x125>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12cd <dmCreateDynamicAlias+0x12d>
mov    -0x68(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmCreateDynamicAlias>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r14
test   %rsi,%rsi
je     11da <dmCreateDynamicAlias+0x3a>
mov    %rsi,%rbx
mov    %rsi,%rdi
call   1050 <strlen@plt>
cmp    $0x1f,%eax
jg     11da <dmCreateDynamicAlias+0x3a>
lea    0xe38(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
jmp    11e9 <dmCreateDynamicAlias+0x49>
lea    0xe29(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
mov    %rsp,%rdi
mov    $0x4,%esi
call   10a0 <randomHexStrCat@plt>
test   %eax,%eax
je     1272 <dmCreateDynamicAlias+0xd2>
lea    0xe10(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %rsp,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1251 <dmCreateDynamicAlias+0xb1>
mov    %rax,%rbx
lea    0xe29(%rip),%rsi
mov    %rsp,%r15
mov    %rax,%rdi
mov    %r15,%rdx
call   10b0 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <dmCreateAlias@plt>
test   %eax,%eax
jne    1274 <dmCreateDynamicAlias+0xd4>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1272 <dmCreateDynamicAlias+0xd2>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xdb8(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1090 <logmsg@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"alias_%s_\00"
@.str.1 = [7 x i8] c"alias_\00"
@.str.2 = [13 x i8] c"/dev/mapper/\00"
@.str.3 = [53 x i8] c"malloc error for full filename of dynamic alias: %s\0A\00"
@errno = global i32 0
@.str.4 = [15 x i8] c"/dev/mapper/%s\00"
define i8* @dmCreateDynamicAlias(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [64 x i8]
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %13, 32
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 @snprintf(i8* %16, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %22
19: ; preds = %11, %2
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %15
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%24 = call i32 @randomHexStrCat(i8* %23, i32 4)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22
store i8* null, i8** %3
br label %54
27: ; preds = %22
%28 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %28, %30
%32 = add nsw i32 %31, 1
%33 = call i8* @malloc(i32 %32)
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %40, label %36
36: ; preds = %27
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 @logmsg(i32 1, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %38)
store i8* null, i8** %3
br label %54
40: ; preds = %27
%41 = load i8*, i8** %7
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%43 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %4
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%46 = call i32 @dmCreateAlias(i8* %44, i8* %45)
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %40
%50 = load i8*, i8** %7
%51 = call i32 @free(i8* %50)
store i8* null, i8** %3
br label %54
52: ; preds = %40
%53 = load i8*, i8** %7
store i8* %53, i8** %3
br label %54
54: ; preds = %52, %49, %36, %26
%55 = load i8*, i8** %3
ret i8* %55
}

LLVM IR (-O2):
@.str = [10 x i8] c"alias_%s_\00"
@.str.1 = [7 x i8] c"alias_\00"
@.str.2 = [13 x i8] c"/dev/mapper/\00"
@.str.3 = [53 x i8] c"malloc error for full filename of dynamic alias: %s\0A\00"
@errno = global i32 0
@.str.4 = [15 x i8] c"/dev/mapper/%s\00"
define noalias i8* @dmCreateDynamicAlias(i8* %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp slt i32 %7, 32
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %13
11: ; preds = %6, %2
%12 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = call i32 @randomHexStrCat(i8* %4, i32 4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %13
%17 = call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @strlen(i8* %4)
%19 = add i32 %17, 1
%20 = add i32 %19, %18
%21 = call i8* @malloc(i32 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i32, i32* @errno
%25 = call i32 @strerror(i32 %24)
%26 = call i32 @logmsg(i32 1, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %33
27: ; preds = %16
%28 = call i32 @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%29 = call i32 @dmCreateAlias(i8* %0, i8* %4)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @free(i8* %21)
br label %33
33: ; preds = %23, %27, %31, %13
%34 = phi i8* [ null, %13 ], [ null, %23 ], [ null, %31 ], [ %21, %27 ]
ret i8* %34
}