#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 *, char);
void escapepath(char *value, int mode) {
  char *s;
  s = strchr(value, '/');
  while (s) {
    if (mode == 2)
      *s = '_';
    else if (mode == 3)
      *s = '.';
    s = strchr(s + 1, '/');
  }
}


x86 assembly (clang, -O0):
<escapepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1183 <escapepath+0x73>
cmpl   $0x2,-0xc(%rbp)
jne    1152 <escapepath+0x42>
mov    -0x18(%rbp),%rax
movb   $0x5f,(%rax)
jmp    1168 <escapepath+0x58>
cmpl   $0x3,-0xc(%rbp)
jne    1163 <escapepath+0x53>
mov    -0x18(%rbp),%rax
movb   $0x2e,(%rax)
jmp    1168 <escapepath+0x58>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
jmp    1131 <escapepath+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escapepath>:
push   %rbx
mov    %esi,%ebx
jmp    112b <escapepath+0x1b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x5f,%cl
mov    %cl,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1148 <escapepath+0x38>
cmp    $0x2,%ebx
je     1120 <escapepath+0x10>
cmp    $0x3,%ebx
jne    1124 <escapepath+0x14>
mov    $0x2e,%cl
jmp    1122 <escapepath+0x12>
pop    %rbx
ret

LLVM IR (-O0):
define void @escapepath(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i8* @strchr(i8* %6, i8 signext 47)
store i8* %7, i8** %5
br label %8
8: ; preds = %22, %2
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = load i8*, i8** %5
store i8 95, i8* %15
br label %22
16: ; preds = %11
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i8*, i8** %5
store i8 46, i8* %20
br label %21
21: ; preds = %19, %16
br label %22
22: ; preds = %21, %14
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i8* @strchr(i8* %24, i8 signext 47)
store i8* %25, i8** %5
br label %8
26: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @escapepath(i8* %0, i32 %1) {
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2, %10
%6 = phi i8* [ %12, %10 ], [ %3, %2 ]
switch i32 %1, label %10 [
i32 2, label %8
i32 3, label %7
]
7: ; preds = %5
br label %8
8: ; preds = %5, %7
%9 = phi i8 [ 46, %7 ], [ 95, %5 ]
store i8 %9, i8* %6
br label %10
10: ; preds = %8, %5
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = tail call i8* @strchr(i8* %11, i8 signext 47)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %5
14: ; preds = %10, %2
ret void
}