#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 */
scalar_t__ calloc(int, int);
unsigned int strlen(char *);
char *changepath(char *filename) {
  char *tmp;
  unsigned int i = 0;
  int j = 0;
  tmp = (char *)calloc(strlen(filename) + 1, sizeof(char));
  for (i = 0; i < strlen(filename); ++i) {
    if (filename[i] != '/')
      tmp[j] = filename[i];
    else
      tmp[j] = '\\';
    ++j;
  }
  tmp[j] = ('\0');
  return tmp;
}


x86 assembly (clang, -O0):
<changepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jae    11ca <changepath+0xaa>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11a7 <changepath+0x87>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11b3 <changepath+0x93>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x5c,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <changepath+0x3d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changepath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1181 <changepath+0x61>
mov    $0x5c,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%eax
cmp    $0x2f,%al
cmove  %ebp,%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1160 <changepath+0x40>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @changepath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = add i32 %7, 1
%9 = call i64 @calloc(i32 %8, i32 1)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %3
store i32 0, i32* %4
br label %11
11: ; preds = %42, %1
%12 = load i32, i32* %4
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = icmp ult i32 %12, %14
br i1 %15, label %16, label %45
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = load i32, i32* %4
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 47
br i1 %23, label %24, label %34
24: ; preds = %16
%25 = load i8*, i8** %2
%26 = load i32, i32* %4
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = load i8*, i8** %3
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %39
34: ; preds = %16
%35 = load i8*, i8** %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 92, i8* %38
br label %39
39: ; preds = %34, %24
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %42
42: ; preds = %39
%43 = load i32, i32* %4
%44 = add i32 %43, 1
store i32 %44, i32* %4
br label %11
45: ; preds = %11
%46 = load i8*, i8** %3
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %3
ret i8* %50
}

LLVM IR (-O2):
define i8* @changepath(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add i32 %2, 1
%4 = tail call i64 @calloc(i32 %3, i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %15, %8 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
%13 = select i1 %12, i8 92, i8 %11
%14 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 %13, i8* %14
%15 = add nuw nsw i64 %9, 1
%16 = tail call i32 @strlen(i8* %0)
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %15, %17
br i1 %18, label %8, label %19
19: ; preds = %8
%20 = and i64 %15, 4294967295
br label %21
21: ; preds = %19, %1
%22 = phi i64 [ 0, %1 ], [ %20, %19 ]
%23 = getelementptr inbounds i8, i8* %5, i64 %22
store i8 0, i8* %23
ret i8* %5
}