#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 /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ string_translate_char(char *, char, char);
int strlen(char const *);
extern void buffer_translate_char(char *buff, unsigned buffLen, const char *src,
                                  char fromChar, char toChar) {
  int len = strlen(src);
  if (len >= buffLen)
    len = buffLen - 1;
  memcpy(buff, src, len);
  buff[len] = 0;
  string_translate_char(buff, fromChar, toChar);
}


x86 assembly (clang, -O0):
<buffer_translate_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jb     116d <buffer_translate_char+0x3d>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x19(%rbp),%al
movsbl %al,%esi
movsbl -0x1a(%rbp),%edx
call   1040 <string_translate_char@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_translate_char>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %esi,%r13d
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    -0x1(%r13),%ebp
cmp    %r13d,%eax
cmovb  %eax,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <string_translate_char@plt>

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

LLVM IR (-O2):
define void @buffer_translate_char(i8* %0, i32 %1, i8* %2, i8 signext %3, i8 signext %4) {
%6 = tail call i32 @strlen(i8* %2)
%7 = icmp ult i32 %6, %1
%8 = add i32 %1, -1
%9 = select i1 %7, i32 %6, i32 %8
%10 = tail call i32 @memcpy(i8* %0, i8* %2, i32 %9)
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 0, i8* %12
%13 = tail call i32 @string_translate_char(i8* %0, i8 signext %3, i8 signext %4)
ret void
}