#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 *str_cpy(char *dest, const char *src, size_t dest_size) {
  unsigned c;
  for (c = 0; (c < dest_size) && (dest[c] = src[c]); c++)
    ;
  dest[dest_size - 1] = 0;
  return dest;
}


x86 assembly (clang, -O0):
<str_cpy>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x1d(%rbp)
jae    114b <str_cpy+0x4b>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rcx
mov    -0x1c(%rbp),%edx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    115b <str_cpy+0x5b>
jmp    116e <str_cpy+0x6e>
jmp    1160 <str_cpy+0x60>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <str_cpy+0x17>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cpy>:
mov    %rdi,%rax
test   %rdx,%rdx
je     1125 <str_cpy+0x25>
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%rsi,%rcx,1),%edi
mov    %dil,(%rax,%rcx,1)
test   %dil,%dil
je     1125 <str_cpy+0x25>
add    $0x1,%ecx
cmp    %rdx,%rcx
jb     1110 <str_cpy+0x10>
movb   $0x0,-0x1(%rdx,%rax,1)
ret

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

LLVM IR (-O2):
define i8* @str_cpy(i8* returned writeonly %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %15, label %9
5: ; preds = %9
%6 = add nuw nsw i64 %10, 1
%7 = and i64 %6, 4294967295
%8 = icmp ult i64 %7, %2
br i1 %8, label %9, label %15
9: ; preds = %3, %5
%10 = phi i64 [ %7, %5 ], [ 0, %3 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %12, i8* %13
%14 = icmp eq i8 %12, 0
br i1 %14, label %15, label %5
15: ; preds = %9, %5, %3
%16 = add i64 %2, -1
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %17
ret i8* %0
}