#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 strlen(char *);
void str_copy(char *seq, char *from, int start, int len) {
  int i, j, l = 0;
  for (i = start, j = 0, l = 0; i < strlen(from) && l < len; i++, j++, l++) {
    seq[j] = from[i];
  }
  seq[j] = '\0';
}


x86 assembly (clang, -O0):
<str_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x25(%rbp)
jge    116e <str_copy+0x5e>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    117e <str_copy+0x6e>
jmp    11b4 <str_copy+0xa4>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <str_copy+0x31>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_copy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
xor    %ebp,%ebp
cmp    %r15d,%eax
jle    1176 <str_copy+0x66>
test   %r12d,%r12d
jle    1176 <str_copy+0x66>
movslq %r15d,%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%r13,%rbx,1),%eax
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1176 <str_copy+0x66>
add    $0x1,%rbx
cmp    %r12d,%ebp
jl     1150 <str_copy+0x40>
movb   $0x0,(%r14,%rbp,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @str_copy(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %11
%12 = load i32, i32* %7
store i32 %12, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %13
13: ; preds = %34, %4
%14 = load i32, i32* %9
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* %11
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br label %22
22: ; preds = %18, %13
%23 = phi i1 [ false, %13 ], [ %21, %18 ]
br i1 %23, label %24, label %41
24: ; preds = %22
%25 = load i8*, i8** %6
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = load i8*, i8** %5
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %24
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 1
store i32 %40, i32* %11
br label %13
41: ; preds = %22
%42 = load i8*, i8** %5
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
ret void
}

LLVM IR (-O2):
define void @str_copy(i8* nocapture writeonly %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, %2
%7 = icmp sgt i32 %3, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %27
9: ; preds = %4
%10 = sext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ %10, %9 ], [ %17, %11 ]
%13 = phi i64 [ 0, %9 ], [ %18, %11 ]
%14 = getelementptr inbounds i8, i8* %1, i64 %12
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 %15, i8* %16
%17 = add nsw i64 %12, 1
%18 = add nuw nsw i64 %13, 1
%19 = trunc i64 %18 to i32
%20 = tail call i32 @strlen(i8* %1)
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %17, %21
%23 = icmp slt i32 %19, %3
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %11, label %25
25: ; preds = %11
%26 = and i64 %18, 4294967295
br label %27
27: ; preds = %25, %4
%28 = phi i64 [ 0, %4 ], [ %26, %25 ]
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 0, i8* %29
ret void
}