#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*/ ft_strcpy(char *, char const *);
int /*<<< orphan*/ ft_strlen(char const *);
char *ft_strnew(int /*<<< orphan*/);
void stub1(unsigned int, char);
char *ft_strmapi(const char *s, void (*f)(unsigned int, char)) {
  char *str;
  unsigned int i;
  i = 0;
  str = ft_strnew(ft_strlen(s));
  ft_strcpy(str, s);
  while (*(str + i)) {
    (*f)(i, *(str + i));
    i++;
  }
  return (str);
}


x86 assembly (clang, -O0):
<ft_strmapi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    %eax,%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <ft_strcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmpb   $0x0,(%rax,%rcx,1)
je     119b <ft_strmapi+0x6b>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%edx
movsbl (%rcx,%rdx,1),%esi
call   *%rax
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1168 <ft_strmapi+0x38>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strmapi>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <ft_strlen@plt>
mov    %eax,%edi
call   1050 <ft_strnew@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <ft_strcpy@plt>
mov    (%r15),%al
test   %al,%al
je     1174 <ft_strmapi+0x44>
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl %al,%esi
mov    %ebx,%edi
call   *%r14
add    $0x1,%ebx
movzbl (%r15,%rbx,1),%eax
test   %al,%al
jne    1160 <ft_strmapi+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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