#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 *str_new(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *const);
char *str_map(char *const s, char (*f)(char)) {
  char *new = str_new(strlen(s));
  for (size_t i = 0; s[i] != '\0'; i++) {
    new[i] = f(s[i]);
    i++;
  }
  return (new);
}


x86 assembly (clang, -O0):
<str_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
call   1040 <str_new@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119d <str_map+0x7d>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%edi
call   *%rax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114c <str_map+0x2c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_map>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%edi
call   1040 <str_new@plt>
mov    %rax,%r12
mov    (%r15),%al
test   %al,%al
je     1168 <str_map+0x48>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   *%r14
mov    %al,(%r12,%rbx,1)
movzbl 0x2(%r15,%rbx,1),%eax
add    $0x2,%rbx
test   %al,%al
jne    1150 <str_map+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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