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


x86 assembly (clang, -O0):
<ft_strmap>:
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
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     119a <ft_strmap+0x6a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%edi
call   *%rax
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1168 <ft_strmap+0x38>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strmap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
call   1040 <ft_strlen@plt>
mov    %eax,%edi
call   1050 <ft_strnew@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <ft_strcpy@plt>
mov    (%r14),%al
test   %al,%al
je     1181 <ft_strmap+0x51>
mov    %r14,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   *%r12
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <ft_strmap+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ft_strmap(i8* %0, void (i8)* %1) {
%3 = alloca i8*
%4 = alloca void (i8)*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store void (i8)* %1, void (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 = sext 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 %29
20: ; preds = %13
%21 = load void (i8)*, void (i8)** %4
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %13
29: ; preds = %13
%30 = load i8*, i8** %5
ret i8* %30
}

LLVM IR (-O2):
define i8* @ft_strmap(i8* %0, void (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 %15, label %8
8: ; preds = %2, %8
%9 = phi i64 [ %11, %8 ], [ 0, %2 ]
%10 = phi i8 [ %13, %8 ], [ %6, %2 ]
tail call void %1(i8 signext %10)
%11 = add nuw i64 %9, 1
%12 = getelementptr inbounds i8, i8* %4, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8, %2
ret i8* %4
}