#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 *strncpy(char *destination, const char *source, size_t number) {
  if (number == 0)
    return destination;
  while ((*destination++ = *source++) != '\0' && number--)
    ;
  return destination;
}


x86 assembly (clang, -O0):
<strncpy>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1128 <strncpy+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <strncpy+0x96>
jmp    112d <strncpy+0x2d>
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,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1179 <strncpy+0x79>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1189 <strncpy+0x89>
jmp    118e <strncpy+0x8e>
jmp    112d <strncpy+0x2d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

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

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

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