#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(scalar_t__);
char *mpgedit_pathname_parse(char const *, char **, char **);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *_normalize_path_name(const char *file) {
  char *path_dir = NULL;
  char *path_base = "";
  char *path_ext = "";
  char *filename;
  char *filenamep = NULL;
  path_dir = mpgedit_pathname_parse(file, &path_base, &path_ext);
  if (path_ext && path_dir && path_base &&
      (!strcmp(path_ext, "lvl") || !strcmp(path_ext, "idx"))) {
    filename = filenamep =
        (char *)malloc(strlen(path_dir) + strlen(path_base) + 6);
    if (filename) {
      strcpy(filename, path_dir);
      if (*path_base) {
        strcat(filename, "/");
        strcat(filename, path_base);
        strcat(filename, ".mp3");
      }
    }
    if (path_dir) {
      free(path_dir);
    }
    if (path_base) {
      free(path_base);
    }
    if (path_ext) {
      free(path_ext);
    }
  } else {
    filename = (char *)file;
  }
  if (filenamep) {
    free(filenamep);
  }
  return filename;
}


x86 assembly (clang, -O0):
<_normalize_path_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <mpgedit_pathname_parse@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12d0 <_normalize_path_name+0x160>
cmpq   $0x0,-0x10(%rbp)
je     12d0 <_normalize_path_name+0x160>
cmpq   $0x0,-0x18(%rbp)
je     12d0 <_normalize_path_name+0x160>
mov    -0x20(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     120a <_normalize_path_name+0x9a>
mov    -0x20(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12d0 <_normalize_path_name+0x160>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x6,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     128f <_normalize_path_name+0x11f>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     128a <_normalize_path_name+0x11a>
mov    -0x28(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xd85(%rip),%rsi
call   1090 <strcat@plt>
jmp    128f <_normalize_path_name+0x11f>
cmpq   $0x0,-0x10(%rbp)
je     12a3 <_normalize_path_name+0x133>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     12b7 <_normalize_path_name+0x147>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     12cb <_normalize_path_name+0x15b>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    12d8 <_normalize_path_name+0x168>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12ec <_normalize_path_name+0x17c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_normalize_path_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
lea    0xe84(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1050 <mpgedit_pathname_parse@plt>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     1290 <_normalize_path_name+0x120>
mov    %rax,%r14
test   %rax,%rax
je     1290 <_normalize_path_name+0x120>
mov    0x8(%rsp),%r15
test   %r15,%r15
je     1290 <_normalize_path_name+0x120>
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11f0 <_normalize_path_name+0x80>
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    1290 <_normalize_path_name+0x120>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x6,%rdi
call   1080 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     1258 <_normalize_path_name+0xe8>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1258 <_normalize_path_name+0xe8>
lea    0xdd4(%rip),%rsi
mov    %r12,%rdi
call   1090 <strcat@plt>
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1090 <strcat@plt>
lea    0xdba(%rip),%rsi
mov    %r12,%rdi
call   1090 <strcat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     126f <_normalize_path_name+0xff>
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     127e <_normalize_path_name+0x10e>
call   1030 <free@plt>
test   %r12,%r12
je     128d <_normalize_path_name+0x11d>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1290 <_normalize_path_name+0x120>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"lvl\00"
@.str.2 = [4 x i8] c"idx\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [5 x i8] c".mp3\00"
define i8* @_normalize_path_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* null, i8** %7
%8 = load i8*, i8** %2
%9 = call i8* @mpgedit_pathname_parse(i8* %8, i8** %4, i8** %5)
store i8* %9, i8** %3
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %72
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %72
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %72
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %72, label %26
26: ; preds = %22, %18
%27 = load i8*, i8** %3
%28 = call i64 @strlen(i8* %27)
%29 = load i8*, i8** %4
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %28, %30
%32 = add nsw i64 %31, 6
%33 = call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %7
store i8* %34, i8** %6
%35 = load i8*, i8** %6
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %53
37: ; preds = %26
%38 = load i8*, i8** %6
%39 = load i8*, i8** %3
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %4
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %37
%45 = load i8*, i8** %6
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%47 = load i8*, i8** %6
%48 = load i8*, i8** %4
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i8*, i8** %6
%51 = call i32 @strcat(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %44, %37
br label %53
53: ; preds = %52, %26
%54 = load i8*, i8** %3
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i8*, i8** %3
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %56, %53
%60 = load i8*, i8** %4
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i8*, i8** %4
%64 = call i32 @free(i8* %63)
br label %65
65: ; preds = %62, %59
%66 = load i8*, i8** %5
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i8*, i8** %5
%70 = call i32 @free(i8* %69)
br label %71
71: ; preds = %68, %65
br label %74
72: ; preds = %22, %15, %12, %1
%73 = load i8*, i8** %2
store i8* %73, i8** %6
br label %74
74: ; preds = %72, %71
%75 = load i8*, i8** %7
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i8*, i8** %7
%79 = call i32 @free(i8* %78)
br label %80
80: ; preds = %77, %74
%81 = load i8*, i8** %6
ret i8* %81
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"lvl\00"
@.str.2 = [4 x i8] c"idx\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [5 x i8] c".mp3\00"
define i8* @_normalize_path_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast i8** %2 to i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = call i8* @mpgedit_pathname_parse(i8* %0, i8** %2, i8** %3)
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
%9 = icmp ne i8* %6, null
%10 = select i1 %8, i1 %9, i1 false
%11 = load i8*, i8** %2
%12 = icmp ne i8* %11, null
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %52
14: ; preds = %1
%15 = call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32 @strcmp(i8* %7, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %52
20: ; preds = %17, %14
%21 = call i64 @strlen(i8* %6)
%22 = call i64 @strlen(i8* dereferenceable(1) %11)
%23 = add i64 %21, 6
%24 = add i64 %23, %22
%25 = call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to i8*
%27 = icmp eq i64 %25, 0
br i1 %27, label %38, label %28
28: ; preds = %20
%29 = call i32 @strcpy(i8* %26, i8* %6)
%30 = load i8*, i8** %2
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%35 = load i8*, i8** %2
%36 = call i32 @strcat(i8* %26, i8* %35)
%37 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %20, %33, %28
%39 = call i32 @free(i8* %6)
%40 = load i8*, i8** %2
%41 = icmp eq i8* %40, null
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 @free(i8* %40)
br label %44
44: ; preds = %42, %38
%45 = load i8*, i8** %3
%46 = icmp eq i8* %45, null
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = call i32 @free(i8* %45)
br label %49
49: ; preds = %44, %47
br i1 %27, label %52, label %50
50: ; preds = %49
%51 = call i32 @free(i8* %26)
br label %52
52: ; preds = %1, %17, %50, %49
%53 = phi i8* [ %26, %50 ], [ null, %49 ], [ %0, %17 ], [ %0, %1 ]
ret i8* %53
}