#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 */
char *strchr(char const *, char);
const char *cut_path(const char *in) {
  const char *p, *ret = in;
  char delims[] = "/\\";
  char *i;
  for (i = delims; *i; i++) {
    p = in;
    while ((p = strchr(p, *i)) != 0) {
      ret = ++p;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<cut_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0xed5(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xecd(%rip),%al
mov    %al,-0x19(%rbp)
lea    -0x1b(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     119e <cut_path+0x8e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1188 <cut_path+0x78>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
jmp    1155 <cut_path+0x45>
jmp    118d <cut_path+0x7d>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1140 <cut_path+0x30>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cut_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x4(%rsp),%r15
movb   $0x0,0x6(%rsp)
movw   $0x5c2f,0x4(%rsp)
mov    $0x2f,%bpl
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rcx
cs nopw 0x0(%rax,%rax,1)
mov    %rcx,%rbx
movsbl %bpl,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rdi
mov    %rdi,%rcx
test   %rax,%rax
jne    1150 <cut_path+0x40>
mov    0x1(%r15),%bpl
add    $0x1,%r15
test   %bpl,%bpl
jne    1140 <cut_path+0x30>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.cut_path.delims = [3 x i8] c"/\\\00"
define i8* @cut_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %4
%8 = bitcast [3 x i8]* %5 to i8*
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8* %9, i8** %6
br label %10
10: ; preds = %26, %1
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i8*, i8** %2
store i8* %15, i8** %3
br label %16
16: ; preds = %22, %14
%17 = load i8*, i8** %3
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = call i8* @strchr(i8* %17, i8 signext %19)
store i8* %20, i8** %3
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
store i8* %24, i8** %4
br label %16
25: ; preds = %16
br label %26
26: ; preds = %25
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
br label %10
29: ; preds = %10
%30 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
@__const.cut_path.delims = [3 x i8] c"/\\\00"
define i8* @cut_path(i8* %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %1, %14
%5 = phi i8 [ %16, %14 ], [ 47, %1 ]
%6 = phi i8* [ %15, %14 ], [ %3, %1 ]
%7 = phi i8* [ %10, %14 ], [ %0, %1 ]
br label %8
8: ; preds = %8, %4
%9 = phi i8* [ %13, %8 ], [ %0, %4 ]
%10 = phi i8* [ %13, %8 ], [ %7, %4 ]
%11 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext %5)
%12 = icmp eq i8* %11, null
%13 = getelementptr inbounds i8, i8* %11, i64 1
br i1 %12, label %14, label %8
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %6, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %4
18: ; preds = %14
ret i8* %10
}