#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*/ my_assert_notNull(char *, char const *);
int /*<<< orphan*/ my_newString_replaceOne(char *, char *, char *);
char *my_newString_string(char const *);
int /*<<< orphan*/ my_string_replaceChar(char *, char, char);
int strlen(char *);
char *my_io_normalizeFilenameToRead(const char *filename) {
  my_assert_notNull("filename", filename);
  char *fname = my_newString_string(filename);
  my_string_replaceChar(fname, '\\', '/');
  my_newString_replaceOne(fname, "//", "/");
  int len = strlen(fname);
  if (len > 1 && (fname[len - 1] == '/' || fname[len - 1] == '\\'))
    fname[len - 1] = '\0';
  return fname;
}


x86 assembly (clang, -O0):
<my_io_normalizeFilenameToRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1060 <my_assert_notNull@plt>
mov    -0x8(%rbp),%rdi
call   1030 <my_newString_string@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
mov    $0x2f,%edx
call   1070 <my_string_replaceChar@plt>
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
lea    0xe6c(%rip),%rdx
call   1050 <my_newString_replaceOne@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11fe <my_io_normalizeFilenameToRead+0xae>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11ed <my_io_normalizeFilenameToRead+0x9d>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    11fe <my_io_normalizeFilenameToRead+0xae>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_io_normalizeFilenameToRead>:
push   %rbx
mov    %rdi,%rbx
lea    0xea5(%rip),%rdi
mov    %rbx,%rsi
call   1060 <my_assert_notNull@plt>
mov    %rbx,%rdi
call   1030 <my_newString_string@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x5c,%esi
mov    $0x2f,%edx
call   1070 <my_string_replaceChar@plt>
lea    0xe82(%rip),%rsi
lea    0xe7c(%rip),%rdx
mov    %rbx,%rdi
call   1050 <my_newString_replaceOne@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11b7 <my_io_normalizeFilenameToRead+0x67>
add    $0xffffffff,%eax
mov    (%rbx,%rax,1),%cl
cmp    $0x5c,%cl
je     11b3 <my_io_normalizeFilenameToRead+0x63>
cmp    $0x2f,%cl
jne    11b7 <my_io_normalizeFilenameToRead+0x67>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"filename\00"
@.str.1 = [3 x i8] c"//\00"
@.str.2 = [2 x i8] c"/\00"
define i8* @my_io_normalizeFilenameToRead(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @my_assert_notNull(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %2
%8 = call i8* @my_newString_string(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @my_string_replaceChar(i8* %9, i8 signext 92, i8 signext 47)
%11 = load i8*, i8** %3
%12 = call i32 @my_newString_replaceOne(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %41
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 47
br i1 %25, label %35, label %26
26: ; preds = %17
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 92
br i1 %34, label %35, label %41
35: ; preds = %26, %17
%36 = load i8*, i8** %3
%37 = load i32, i32* %4
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %35, %26, %1
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
@.str = [9 x i8] c"filename\00"
@.str.1 = [3 x i8] c"//\00"
@.str.2 = [2 x i8] c"/\00"
define i8* @my_io_normalizeFilenameToRead(i8* %0) {
%2 = tail call i32 @my_assert_notNull(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i8* @my_newString_string(i8* %0)
%4 = tail call i32 @my_string_replaceChar(i8* %3, i8 signext 92, i8 signext 47)
%5 = tail call i32 @my_newString_replaceOne(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* %3)
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = add nsw i32 %6, -1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %3, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %14 [
i8 47, label %13
i8 92, label %13
]
13: ; preds = %8, %8
store i8 0, i8* %11
br label %14
14: ; preds = %8, %13, %1
ret i8* %3
}