#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 */
unsigned long __memcpy_mcsafe(char *, char *, int);
unsigned long mcsafe_handle_tail(char *to, char *from, unsigned len) {
  for (; len; --len, to++, from++) {
    unsigned long rem = __memcpy_mcsafe(to, from, 1);
    if (rem)
      break;
  }
  return len;
}


x86 assembly (clang, -O0):
<mcsafe_handle_tail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117e <mcsafe_handle_tail+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <__memcpy_mcsafe@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1153 <mcsafe_handle_tail+0x43>
jmp    117e <mcsafe_handle_tail+0x6e>
jmp    1158 <mcsafe_handle_tail+0x48>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1123 <mcsafe_handle_tail+0x13>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcsafe_handle_tail>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %edx,%edx
je     1158 <mcsafe_handle_tail+0x48>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <__memcpy_mcsafe@plt>
test   %rax,%rax
jne    1155 <mcsafe_handle_tail+0x45>
add    $0x1,%rbp
add    $0x1,%rbx
add    $0xffffffff,%r14d
jne    1130 <mcsafe_handle_tail+0x20>
jmp    1158 <mcsafe_handle_tail+0x48>
mov    %r14d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @mcsafe_handle_tail(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %16, label %5
5: ; preds = %3, %11
%6 = phi i8* [ %13, %11 ], [ %0, %3 ]
%7 = phi i32 [ %12, %11 ], [ %2, %3 ]
%8 = phi i8* [ %14, %11 ], [ %1, %3 ]
%9 = tail call i64 @__memcpy_mcsafe(i8* %6, i8* %8, i32 1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = add i32 %7, -1
%13 = getelementptr inbounds i8, i8* %6, i64 1
%14 = getelementptr inbounds i8, i8* %8, i64 1
%15 = icmp eq i32 %12, 0
br i1 %15, label %16, label %5
16: ; preds = %11, %5, %3
%17 = phi i32 [ 0, %3 ], [ %7, %5 ], [ 0, %11 ]
%18 = zext i32 %17 to i64
ret i64 %18
}