#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 */
char *alloc_replace_initial_substrings(char *const, char const *, char const *);
int /*<<< orphan*/ free_substring_array(char **);
scalar_t__ malloc(int);
char **replace_initial_substring_array(char *const src_str_array[],
                                       const char *old_sub_str,
                                       const char *new_sub_str) {
  char **new_str_array;
  size_t n_arr_strs;
  for (n_arr_strs = 0; src_str_array[n_arr_strs] != NULL; n_arr_strs++)
    ;
  new_str_array = (char **)malloc(sizeof(char *) * (n_arr_strs + 1));
  if (new_str_array != NULL) {
    size_t arr_str_ind;
    for (arr_str_ind = 0; arr_str_ind < n_arr_strs; arr_str_ind++) {
      char *new_arr_str = alloc_replace_initial_substrings(
          src_str_array[arr_str_ind], old_sub_str, new_sub_str);
      new_str_array[arr_str_ind] = new_arr_str;
      if (new_arr_str == NULL)
        break;
    }
    if (arr_str_ind == n_arr_strs)
      new_str_array[n_arr_strs] = NULL;
    else {
      free_substring_array(new_str_array);
      new_str_array = NULL;
    }
  }
  return (new_str_array);
}


x86 assembly (clang, -O0):
<replace_initial_substring_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1175 <replace_initial_substring_array+0x45>
jmp    1164 <replace_initial_substring_array+0x34>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    114c <replace_initial_substring_array+0x1c>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1239 <replace_initial_substring_array+0x109>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1200 <replace_initial_substring_array+0xd0>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <alloc_replace_initial_substrings@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
cmpq   $0x0,-0x38(%rbp)
jne    11ea <replace_initial_substring_array+0xba>
jmp    1200 <replace_initial_substring_array+0xd0>
jmp    11ef <replace_initial_substring_array+0xbf>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    119f <replace_initial_substring_array+0x6f>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1223 <replace_initial_substring_array+0xf3>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    1234 <replace_initial_substring_array+0x104>
mov    -0x20(%rbp),%rdi
call   1040 <free_substring_array@plt>
movq   $0x0,-0x20(%rbp)
jmp    1239 <replace_initial_substring_array+0x109>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_initial_substring_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdi,%r13
mov    $0x1,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffffffffffff,%rbp
cmpq   $0x0,0x0(%r13,%rbx,1)
lea    0x8(%rbx),%rbx
jne    1160 <replace_initial_substring_array+0x30>
mov    %ebx,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11d3 <replace_initial_substring_array+0xa3>
mov    %rax,%r14
test   %rbp,%rbp
je     11b8 <replace_initial_substring_array+0x88>
mov    %rbp,%r12
neg    %r12
xor    %r15d,%r15d
nopl   (%rax)
mov    0x0(%r13,%r15,8),%rdi
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
call   1030 <alloc_replace_initial_substrings@plt>
mov    %rax,(%r14,%r15,8)
test   %rax,%rax
je     11bb <replace_initial_substring_array+0x8b>
add    $0x1,%r15
cmp    %r15,%r12
jne    1190 <replace_initial_substring_array+0x60>
jmp    11c0 <replace_initial_substring_array+0x90>
xor    %r15d,%r15d
add    %rbp,%r15
jne    11cb <replace_initial_substring_array+0x9b>
movq   $0x0,-0x8(%r14,%rbx,1)
jmp    11d6 <replace_initial_substring_array+0xa6>
mov    %r14,%rdi
call   1040 <free_substring_array@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @replace_initial_substring_array(i8** %0, i8* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i64 0, i64* %8
br label %11
11: ; preds = %18, %3
%12 = load i8**, i8*** %4
%13 = load i64, i64* %8
%14 = getelementptr inbounds i8*, i8** %12, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %11
br label %18
18: ; preds = %17
%19 = load i64, i64* %8
%20 = add i64 %19, 1
store i64 %20, i64* %8
br label %11
21: ; preds = %11
%22 = load i64, i64* %8
%23 = add i64 %22, 1
%24 = mul i64 8, %23
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8**
store i8** %27, i8*** %7
%28 = load i8**, i8*** %7
%29 = icmp ne i8** %28, null
br i1 %29, label %30, label %66
30: ; preds = %21
store i64 0, i64* %9
br label %31
31: ; preds = %51, %30
%32 = load i64, i64* %9
%33 = load i64, i64* %8
%34 = icmp ult i64 %32, %33
br i1 %34, label %35, label %54
35: ; preds = %31
%36 = load i8**, i8*** %4
%37 = load i64, i64* %9
%38 = getelementptr inbounds i8*, i8** %36, i64 %37
%39 = load i8*, i8** %38
%40 = load i8*, i8** %5
%41 = load i8*, i8** %6
%42 = call i8* @alloc_replace_initial_substrings(i8* %39, i8* %40, i8* %41)
store i8* %42, i8** %10
%43 = load i8*, i8** %10
%44 = load i8**, i8*** %7
%45 = load i64, i64* %9
%46 = getelementptr inbounds i8*, i8** %44, i64 %45
store i8* %43, i8** %46
%47 = load i8*, i8** %10
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %50
49: ; preds = %35
br label %54
50: ; preds = %35
br label %51
51: ; preds = %50
%52 = load i64, i64* %9
%53 = add i64 %52, 1
store i64 %53, i64* %9
br label %31
54: ; preds = %49, %31
%55 = load i64, i64* %9
%56 = load i64, i64* %8
%57 = icmp eq i64 %55, %56
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = load i8**, i8*** %7
%60 = load i64, i64* %8
%61 = getelementptr inbounds i8*, i8** %59, i64 %60
store i8* null, i8** %61
br label %65
62: ; preds = %54
%63 = load i8**, i8*** %7
%64 = call i32 @free_substring_array(i8** %63)
store i8** null, i8*** %7
br label %65
65: ; preds = %62, %58
br label %66
66: ; preds = %65, %21
%67 = load i8**, i8*** %7
ret i8** %67
}

LLVM IR (-O2):
define i8** @replace_initial_substring_array(i8** nocapture %0, i8* %1, i8* %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ 0, %3 ], [ %9, %4 ]
%6 = getelementptr inbounds i8*, i8** %0, i64 %5
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
%9 = add i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = trunc i64 %5 to i32
%12 = shl i32 %11, 3
%13 = add i32 %12, 8
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8**
%16 = icmp eq i64 %14, 0
br i1 %16, label %36, label %17
17: ; preds = %10
%18 = icmp eq i64 %5, 0
br i1 %18, label %29, label %19
19: ; preds = %17, %26
%20 = phi i64 [ %27, %26 ], [ 0, %17 ]
%21 = getelementptr inbounds i8*, i8** %0, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i8* @alloc_replace_initial_substrings(i8* %22, i8* %1, i8* %2)
%24 = getelementptr inbounds i8*, i8** %15, i64 %20
store i8* %23, i8** %24
%25 = icmp eq i8* %23, null
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = add nuw i64 %20, 1
%28 = icmp eq i64 %27, %5
br i1 %28, label %32, label %19
29: ; preds = %19, %17
%30 = phi i64 [ 0, %17 ], [ %20, %19 ]
%31 = icmp eq i64 %30, %5
br i1 %31, label %32, label %34
32: ; preds = %26, %29
%33 = getelementptr inbounds i8*, i8** %15, i64 %5
store i8* null, i8** %33
br label %36
34: ; preds = %29
%35 = tail call i32 @free_substring_array(i8** %15)
br label %36
36: ; preds = %32, %34, %10
%37 = phi i8** [ null, %10 ], [ %15, %32 ], [ null, %34 ]
ret i8** %37
}