char *strmapito(char *dst, char const *s, unsigned int i,
                char (*f)(unsigned int, char)) {
  if (!(*s))
    return ("\0");
  *dst = f(i, *s);
  *(dst + 1) = *strmapito(dst + 1, s + 1, i + 1, f);
  return (dst);
}


x86 assembly (clang, -O0):
<strmapito>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1144 <strmapito+0x34>
lea    0xec5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118c <strmapito+0x7c>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%esi
call   *%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x28(%rbp),%rcx
call   1030 <strmapito@plt>
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strmapito>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%al
test   %al,%al
je     1152 <strmapito+0x42>
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
movsbl %al,%esi
mov    %edx,%edi
call   *%rcx
mov    %al,(%r15)
lea    0x1(%r15),%rdi
add    $0x1,%rbx
add    $0x1,%ebp
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r14,%rcx
call   1030 <strmapito@plt>
mov    (%rax),%al
mov    %al,0x1(%r15)
jmp    1159 <strmapito+0x49>
lea    0xea7(%rip),%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
define i8* @strmapito(i8* %0, i8* nocapture %1, i32 %2, i8 (i32, i8)* nocapture %3) {
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4, %9
%8 = phi i8* [ %0, %9 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %4 ]
ret i8* %8
9: ; preds = %4
%10 = tail call signext i8 %3(i32 %2, i8 signext %5)
store i8 %10, i8* %0
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = getelementptr inbounds i8, i8* %1, i64 1
%13 = add i32 %2, 1
%14 = tail call i8* @strmapito(i8* %11, i8* %12, i32 %13, i8 (i32, i8)* %3)
%15 = load i8, i8* %14
store i8 %15, i8* %11
br label %7
}