#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 sc_strlen(char *);
void sc_substrcpy(char *A, char *B, int start) {
  int walker = start;
  int counter = 0;
  for (; counter < sc_strlen(B); walker++, counter++)
    A[walker] = B[counter];
}


x86 assembly (clang, -O0):
<sc_substrcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sc_strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1179 <sc_substrcpy+0x69>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1130 <sc_substrcpy+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sc_substrcpy>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <sc_strlen@plt>
test   %eax,%eax
jle    114b <sc_substrcpy+0x3b>
movslq %ebp,%rax
add    %rax,%r14
xor    %ebp,%ebp
movzbl (%rbx,%rbp,1),%eax
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <sc_strlen@plt>
cltq
cmp    %rax,%rbp
jl     1130 <sc_substrcpy+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @sc_substrcpy(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
store i32 %9, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %25, %3
%11 = load i32, i32* %8
%12 = load i8*, i8** %5
%13 = call i32 @sc_strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %30
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 %20, i8* %24
br label %25
25: ; preds = %15
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %10
30: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @sc_substrcpy(i8* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = tail call i32 @sc_strlen(i8* %1)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %3
%7 = sext i32 %2 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %14, %8 ]
%10 = phi i64 [ 0, %6 ], [ %15, %8 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %12, i8* %13
%14 = add nsw i64 %9, 1
%15 = add nuw nsw i64 %10, 1
%16 = tail call i32 @sc_strlen(i8* %1)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %8, label %19
19: ; preds = %8, %3
ret void
}