#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 */
scalar_t__ ft_strlen(char const *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strmapito(char *, char const *, int /*<<< orphan*/,
                             char (*)(unsigned int, char));
char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) {
  char *st;
  if (!s)
    return (NULL);
  st = (char *)(malloc(ft_strlen(s) + 1));
  if (!st)
    return (NULL);
  strmapito(st, s, 0, f);
  return (st);
}


x86 assembly (clang, -O0):
<ft_strmapi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <ft_strmapi+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <ft_strmapi+0x74>
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1189 <ft_strmapi+0x59>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <ft_strmapi+0x74>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
xor    %edx,%edx
call   1040 <strmapito@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strmapi>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1168 <ft_strmapi+0x38>
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <ft_strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     1168 <ft_strmapi+0x38>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
xor    %edx,%edx
mov    %r14,%rcx
call   1040 <strmapito@plt>
jmp    116a <ft_strmapi+0x3a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
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 i8*
store i8* %0, i8** %4
store i8 (i32, i8)* %1, i8 (i32, i8)** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i8* null, i8** %3
br label %25
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i64 @ft_strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %10
store i8* null, i8** %3
br label %25
19: ; preds = %10
%20 = load i8*, i8** %6
%21 = load i8*, i8** %4
%22 = load i8 (i32, i8)*, i8 (i32, i8)** %5
%23 = call i32 @strmapito(i8* %20, i8* %21, i32 0, i8 (i32, i8)* %22)
%24 = load i8*, i8** %6
store i8* %24, i8** %3
br label %25
25: ; preds = %19, %18, %9
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
define i8* @ft_strmapi(i8* %0, i8 (i32, i8)* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = tail call i64 @ft_strlen(i8* %0)
%6 = add nsw i64 %5, 1
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = tail call i32 @strmapito(i8* %8, i8* %0, i32 0, i8 (i32, i8)* %1)
br label %12
12: ; preds = %4, %2, %10
%13 = phi i8* [ %8, %10 ], [ null, %2 ], [ null, %4 ]
ret i8* %13
}