#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*/ assert(char *);
char *strings_alloc(unsigned int);
unsigned int strings_length(char *);
char *strings_to_something(char *string, char (*mapping_function)(char)) {
  assert(string);
  unsigned int string_length = strings_length(string);
  char *ret = strings_alloc(string_length + 1);
  for (unsigned int k = 0; k < string_length; k++) {
    ret[k] = mapping_function(string[k]);
  }
  ret[string_length] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<strings_to_something>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strings_length@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1040 <strings_alloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11a2 <strings_to_something+0x72>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x24(%rbp),%edx
movsbl (%rcx,%rdx,1),%edi
call   *%rax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <strings_to_something+0x3b>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings_to_something>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <assert@plt>
mov    %r15,%rdi
call   1030 <strings_length@plt>
mov    %eax,%r12d
lea    0x1(%r12),%edi
call   1040 <strings_alloc@plt>
mov    %rax,%r13
test   %r12d,%r12d
je     1188 <strings_to_something+0x58>
mov    %r12d,%r12d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   *%r14
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1170 <strings_to_something+0x40>
jmp    118b <strings_to_something+0x5b>
xor    %r12d,%r12d
movb   $0x0,0x0(%r13,%r12,1)
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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