#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 *memchr(char *, char, int);
void strtr_in_place(char *s, size_t l, char from, char to) {
  char *e = s + l;
  while (s < e) {
    char *p = memchr(s, from, e - s);
    if (p == NULL)
      break;
    *p = to;
    s = p + 1;
  }
}


x86 assembly (clang, -O0):
<strtr_in_place>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    118e <strtr_in_place+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
mov    %ecx,%edx
movsbl %al,%esi
call   1030 <memchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1174 <strtr_in_place+0x64>
jmp    118e <strtr_in_place+0x7e>
mov    -0x12(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1136 <strtr_in_place+0x26>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtr_in_place>:
push   %rbp
push   %r14
push   %rbx
test   %rsi,%rsi
jle    114f <strtr_in_place+0x3f>
mov    %ecx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rax
add    %rdi,%rbx
movsbl %dl,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edx
sub    %eax,%edx
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <memchr@plt>
test   %rax,%rax
je     114f <strtr_in_place+0x3f>
mov    %r14b,(%rax)
add    $0x1,%rax
cmp    %rbx,%rax
jb     1130 <strtr_in_place+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @strtr_in_place(i8* %0, i64 %1, i8 signext %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8 %2, i8* %7
store i8 %3, i8* %8
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8* %13, i8** %9
br label %14
14: ; preds = %31, %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %9
%17 = icmp ult i8* %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = load i8, i8* %7
%21 = load i8*, i8** %9
%22 = load i8*, i8** %5
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = call i8* @memchr(i8* %19, i8 signext %20, i32 %26)
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %18
br label %36
31: ; preds = %18
%32 = load i8, i8* %8
%33 = load i8*, i8** %10
store i8 %32, i8* %33
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8* %35, i8** %5
br label %14
36: ; preds = %30, %14
ret void
}

LLVM IR (-O2):
define void @strtr_in_place(i8* %0, i64 %1, i8 signext %2, i8 signext %3) {
%5 = getelementptr inbounds i8, i8* %0, i64 %1
%6 = ptrtoint i8* %5 to i64
%7 = icmp sgt i64 %1, 0
br i1 %7, label %8, label %18
8: ; preds = %4, %15
%9 = phi i8* [ %16, %15 ], [ %0, %4 ]
%10 = ptrtoint i8* %9 to i64
%11 = sub i64 %6, %10
%12 = trunc i64 %11 to i32
%13 = tail call i8* @memchr(i8* %9, i8 signext %2, i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %8
store i8 %3, i8* %13
%16 = getelementptr inbounds i8, i8* %13, i64 1
%17 = icmp ult i8* %16, %5
br i1 %17, label %8, label %18
18: ; preds = %15, %8, %4
ret void
}