#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 *strncpyy(char *s1, const char *s2, size_t n) {
  register char *endp = s1 + n;
  register char *s = s1;
  while (s < endp && (*s++ = *s2++))
    ;
  return s1;
}


x86 assembly (clang, -O0):
<strncpyy>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x29(%rbp)
jae    1165 <strncpyy+0x65>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1175 <strncpyy+0x75>
jmp    117a <strncpyy+0x7a>
jmp    1124 <strncpyy+0x24>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncpyy>:
mov    %rdi,%rax
add    %rdi,%rdx
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
lea    (%rax,%rcx,1),%rdi
cmp    %rdx,%rdi
jae    112a <strncpyy+0x2a>
movzbl (%rsi,%rcx,1),%r8d
mov    %r8b,(%rdi)
add    $0x1,%rcx
test   %r8b,%r8b
jne    1110 <strncpyy+0x10>
ret

LLVM IR (-O0):
define i8* @strncpyy(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
%10 = load i64, i64* %6
%11 = getelementptr inbounds i8, i8* %9, i64 %10
store i8* %11, i8** %7
%12 = load i8*, i8** %4
store i8* %12, i8** %8
br label %13
13: ; preds = %27, %3
%14 = load i8*, i8** %8
%15 = load i8*, i8** %7
%16 = icmp ult i8* %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
%20 = load i8, i8* %18
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %8
store i8 %20, i8* %21
%23 = sext i8 %20 to i32
%24 = icmp ne i32 %23, 0
br label %25
25: ; preds = %17, %13
%26 = phi i1 [ false, %13 ], [ %24, %17 ]
br i1 %26, label %27, label %28
27: ; preds = %25
br label %13
28: ; preds = %25
%29 = load i8*, i8** %4
ret i8* %29
}

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