#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 */
typedef int /*<<< orphan*/ int8_t;
typedef scalar_t__ int64_t;

/* Variables and functions */
scalar_t__ ll_strlen(int /*<<< orphan*/ *);
scalar_t__ strncpy(char *, char *, scalar_t__);
int8_t *ll_strncopy(int8_t *dst, int8_t *src, int64_t i) {
  int64_t src_size = ll_strlen(src);
  int64_t dst_size = ll_strlen(dst);
  if (i >= dst_size)
    return dst;
  else
    return (int8_t *)strncpy((char *)dst + i, (char *)src, dst_size - i);
}


x86 assembly (clang, -O0):
<ll_strncopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ll_strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ll_strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jl     1169 <ll_strncopy+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1186 <ll_strncopy+0x66>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
sub    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ll_strncopy>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <ll_strlen@plt>
mov    %rbx,%rdi
call   1040 <ll_strlen@plt>
sub    %r15,%rax
jle    1157 <ll_strncopy+0x37>
add    %r15,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @ll_strncopy(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
%10 = load i32*, i32** %6
%11 = call i64 @ll_strlen(i32* %10)
store i64 %11, i64* %8
%12 = load i32*, i32** %5
%13 = call i64 @ll_strlen(i32* %12)
store i64 %13, i64* %9
%14 = load i64, i64* %7
%15 = load i64, i64* %9
%16 = icmp sge i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32*, i32** %5
store i32* %18, i32** %4
br label %31
19: ; preds = %3
%20 = load i32*, i32** %5
%21 = bitcast i32* %20 to i8*
%22 = load i64, i64* %7
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i32*, i32** %6
%25 = bitcast i32* %24 to i8*
%26 = load i64, i64* %9
%27 = load i64, i64* %7
%28 = sub nsw i64 %26, %27
%29 = call i64 @strncpy(i8* %23, i8* %25, i64 %28)
%30 = inttoptr i64 %29 to i32*
store i32* %30, i32** %4
br label %31
31: ; preds = %19, %17
%32 = load i32*, i32** %4
ret i32* %32
}

LLVM IR (-O2):
define i32* @ll_strncopy(i32* %0, i32* %1, i64 %2) {
%4 = tail call i64 @ll_strlen(i32* %1)
%5 = tail call i64 @ll_strlen(i32* %0)
%6 = icmp sgt i64 %5, %2
br i1 %6, label %7, label %14
7: ; preds = %3
%8 = bitcast i32* %0 to i8*
%9 = getelementptr inbounds i8, i8* %8, i64 %2
%10 = bitcast i32* %1 to i8*
%11 = sub nsw i64 %5, %2
%12 = tail call i64 @strncpy(i8* %9, i8* %10, i64 %11)
%13 = inttoptr i64 %12 to i32*
br label %14
14: ; preds = %3, %7
%15 = phi i32* [ %13, %7 ], [ %0, %3 ]
ret i32* %15
}