#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 /*<<< orphan*/ __put_user(int /*<<< orphan*/, int /*<<< orphan*/, int);
void memcpy_tofs(void *to, const void *from, unsigned long n) {
  char *d = (char *)to;
  const char *s = (const char *)from;
  while (n-- > 0) {
    __put_user(*s++, d++, 1);
  }
}


x86 assembly (clang, -O0):
<memcpy_tofs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
jbe    117f <memcpy_tofs+0x6f>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax),%edi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%esi
mov    $0x1,%edx
call   1030 <__put_user@plt>
jmp    1134 <memcpy_tofs+0x24>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memcpy_tofs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     114c <memcpy_tofs+0x3c>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
lea    (%r15,%rbx,1),%esi
mov    $0x1,%edx
call   1030 <__put_user@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <memcpy_tofs+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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