#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 strlen(char *);
void normalize_path(char *path) {
  int len = strlen(path);
  char *c;
  for (c = path; *c; c++)
    if ('\\' == *c)
      *c = '/';
  while (len > 1 && path[len - 1] == '/') {
    path[len - 1] = '\0';
    len--;
  }
}


x86 assembly (clang, -O0):
<normalize_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     116e <normalize_path+0x5e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x5c,%eax
cmp    %ecx,%eax
jne    1158 <normalize_path+0x48>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
jmp    115d <normalize_path+0x4d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1130 <normalize_path+0x20>
jmp    1173 <normalize_path+0x63>
xor    %eax,%eax
cmpl   $0x1,-0xc(%rbp)
mov    %al,-0x19(%rbp)
jle    119c <normalize_path+0x8c>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ac <normalize_path+0x9c>
jmp    11cb <normalize_path+0xbb>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1173 <normalize_path+0x63>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_path>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rbx,%rcx
jmp    1127 <normalize_path+0x17>
xchg   %ax,%ax
movb   $0x2f,(%rcx)
add    $0x1,%rcx
movzbl (%rcx),%edx
cmp    $0x5c,%dl
je     1120 <normalize_path+0x10>
test   %dl,%dl
jne    1123 <normalize_path+0x13>
cmp    $0x2,%eax
jl     1157 <normalize_path+0x47>
mov    %eax,%eax
add    $0x1,%rax
xchg   %ax,%ax
lea    -0x2(%rax),%ecx
cmpb   $0x2f,(%rbx,%rcx,1)
jne    1157 <normalize_path+0x47>
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
ja     1140 <normalize_path+0x30>
pop    %rbx
ret

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

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