#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_strlen(char const *);
char *ft_strnew(int /*<<< orphan*/);
char stub1(unsigned int, char const);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) {
  int i;
  char *dest;
  if (!(dest = ft_strnew(ft_strlen(s))))
    return (NULL);
  i = 0;
  while (s[i]) {
    dest[i] = (*f)(i, s[i]);
    i++;
  }
  return (dest);
}


x86 assembly (clang, -O0):
<ft_strmapi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%edi
call   1040 <ft_strnew@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    115b <ft_strmapi+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11ac <ft_strmapi+0x8c>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11a4 <ft_strmapi+0x84>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%esi
call   *%rax
mov    %al,%dl
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1162 <ft_strmapi+0x42>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strmapi>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <ft_strlen@plt>
mov    %eax,%edi
call   1040 <ft_strnew@plt>
mov    %rax,%r12
test   %rax,%rax
je     116a <ft_strmapi+0x4a>
mov    (%r15),%al
test   %al,%al
je     116a <ft_strmapi+0x4a>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %ebx,%edi
call   *%r14
mov    %al,(%r12,%rbx,1)
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <ft_strmapi+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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