#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int StrLen(char *);
int StrCpy(char *dst, char *src, int len) {
  if (StrLen(dst) < len - 1) {
    return EXIT_FAILURE;
  }
  while (len-- && (*dst++ = *src++))
    ;
  *--dst = 0;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<StrCpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <StrLen@plt>
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    114b <StrCpy+0x3b>
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <StrCpy+0xbb>
jmp    1150 <StrCpy+0x40>
mov    -0x1c(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1197 <StrCpy+0x87>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a7 <StrCpy+0x97>
jmp    11ac <StrCpy+0x9c>
jmp    1150 <StrCpy+0x40>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,-0x1(%rax)
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrCpy>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <StrLen@plt>
lea    -0x1(%r15),%ecx
cmp    %ecx,%eax
jge    1134 <StrCpy+0x24>
mov    0x2eae(%rip),%rax
jmp    1162 <StrCpy+0x52>
mov    %r15d,%ecx
xor    %eax,%eax
nopl   0x0(%rax)
cmp    %eax,%ecx
je     1154 <StrCpy+0x44>
movzbl (%r14,%rax,1),%edx
mov    %dl,(%rbx,%rax,1)
add    $0x1,%rax
test   %dl,%dl
jne    1140 <StrCpy+0x30>
add    %rax,%rbx
movb   $0x0,-0x1(%rbx)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @StrCpy(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = call i32 @StrLen(i8* %8)
%10 = load i32, i32* %7
%11 = sub nsw i32 %10, 1
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %4
br label %35
15: ; preds = %3
br label %16
16: ; preds = %30, %15
%17 = load i32, i32* %7
%18 = add nsw i32 %17, -1
store i32 %18, i32* %7
%19 = icmp ne i32 %17, 0
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %6
%23 = load i8, i8* %21
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
store i8 %23, i8* %24
%26 = sext i8 %23 to i32
%27 = icmp ne i32 %26, 0
br label %28
28: ; preds = %20, %16
%29 = phi i1 [ false, %16 ], [ %27, %20 ]
br i1 %29, label %30, label %31
30: ; preds = %28
br label %16
31: ; preds = %28
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 -1
store i8* %33, i8** %5
store i8 0, i8* %33
%34 = load i32, i32* @EXIT_SUCCESS
store i32 %34, i32* %4
br label %35
35: ; preds = %31, %13
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @StrCpy(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @StrLen(i8* %0)
%5 = add nsw i32 %2, -1
%6 = icmp slt i32 %4, %5
br i1 %6, label %21, label %7
7: ; preds = %3, %12
%8 = phi i8* [ %16, %12 ], [ %0, %3 ]
%9 = phi i8* [ %14, %12 ], [ %1, %3 ]
%10 = phi i32 [ %13, %12 ], [ %2, %3 ]
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %7
%13 = add nsw i32 %10, -1
%14 = getelementptr inbounds i8, i8* %9, i64 1
%15 = load i8, i8* %9
%16 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %15, i8* %8
%17 = icmp eq i8 %15, 0
br i1 %17, label %18, label %7
18: ; preds = %7, %12
%19 = phi i8* [ %16, %12 ], [ %8, %7 ]
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8 0, i8* %20
br label %21
21: ; preds = %3, %18
%22 = phi i32* [ @EXIT_SUCCESS, %18 ], [ @EXIT_FAILURE, %3 ]
%23 = load i32, i32* %22
ret i32 %23
}