#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 stub1(char);
char stub2(char);
__attribute__((always_)) void reverse_with_mapping(char *p, size_t len,
                                                   char (*map_char)(char)) {
  char tmp;
  char *pp = p + len;
  while (pp > p) {
    --pp;
    tmp = *p;
    *p = (*map_char)(*pp);
    *pp = (*map_char)(tmp);
    ++p;
  }
}


x86 assembly (clang, -O0):
<reverse_with_mapping>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    117b <reverse_with_mapping+0x7b>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rcx),%edi
call   *%rax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movsbl -0x19(%rbp),%edi
call   *%rax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1120 <reverse_with_mapping+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_with_mapping>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rsi,%rsi
jle    114d <reverse_with_mapping+0x4d>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
add    %rdi,%r15
add    $0x1,%rbx
nopl   (%rax)
lea    -0x1(%r15),%rbp
movsbl -0x1(%rbx),%r12d
movsbl -0x1(%r15),%edi
call   *%r14
mov    %al,-0x1(%rbx)
mov    %r12d,%edi
call   *%r14
mov    %al,-0x1(%r15)
lea    0x1(%rbx),%rax
mov    %rbp,%r15
cmp    %rbx,%rbp
mov    %rax,%rbx
ja     1120 <reverse_with_mapping+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @reverse_with_mapping(i8* %0, i64 %1, i8 (i8)* nocapture %2) {
%4 = icmp sgt i64 %1, 0
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 %1
br label %7
7: ; preds = %5, %7
%8 = phi i8* [ %10, %7 ], [ %6, %5 ]
%9 = phi i8* [ %15, %7 ], [ %0, %5 ]
%10 = getelementptr inbounds i8, i8* %8, i64 -1
%11 = load i8, i8* %9
%12 = load i8, i8* %10
%13 = tail call signext i8 %2(i8 signext %12)
store i8 %13, i8* %9
%14 = tail call signext i8 %2(i8 signext %11)
store i8 %14, i8* %10
%15 = getelementptr inbounds i8, i8* %9, i64 1
%16 = icmp ugt i8* %10, %15
br i1 %16, label %7, label %17
17: ; preds = %7, %3
ret void
}