#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__);
char *strmapto(char *, char const *, char (*)(char));
char *ft_strmap(char const *s, char (*f)(char)) {
  char *st;
  if (!s)
    return (NULL);
  st = (char *)(malloc(ft_strlen(s) + 1));
  if (st == NULL)
    return (NULL);
  st = strmapto(st, s, f);
  return (st);
}


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

x86 assembly (clang, -O2):
<ft_strmap>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1167 <ft_strmap+0x37>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <ft_strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     1167 <ft_strmap+0x37>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strmapto@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @ft_strmap(i8* %0, i8 (i8)* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8 (i8)*
%6 = alloca i8*
store i8* %0, i8** %4
store i8 (i8)* %1, i8 (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 eq i8* %16, null
br i1 %17, label %18, label %19
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 (i8)*, i8 (i8)** %5
%23 = call i8* @strmapto(i8* %20, i8* %21, i8 (i8)* %22)
store i8* %23, i8** %6
%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_strmap(i8* %0, i8 (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 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = inttoptr i64 %7 to i8*
%11 = tail call i8* @strmapto(i8* %10, i8* %0, i8 (i8)* %1)
br label %12
12: ; preds = %4, %2, %9
%13 = phi i8* [ %11, %9 ], [ null, %2 ], [ null, %4 ]
ret i8* %13
}