#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*/ min(size_t, size_t);
char *strncat(char *, char const *, int /*<<< orphan*/);
char *OICStrcpyPartial(char *dest, size_t destSize, const char *source,
                       size_t sourceLen) {
  if (!dest || !source) {
    return NULL;
  }
  if (destSize == 0 || sourceLen == 0) {
    return dest;
  }
  dest[0] = '\0';
  return strncat(dest, source, min(destSize - 1, sourceLen));
}


x86 assembly (clang, -O0):
<OICStrcpyPartial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114e <OICStrcpyPartial+0x2e>
cmpq   $0x0,-0x20(%rbp)
jne    115b <OICStrcpyPartial+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <OICStrcpyPartial+0x99>
cmpq   $0x0,-0x18(%rbp)
je     1171 <OICStrcpyPartial+0x51>
cmpq   $0x0,-0x28(%rbp)
jne    117e <OICStrcpyPartial+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b9 <OICStrcpyPartial+0x99>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
sub    $0x1,%rdi
mov    -0x28(%rbp),%rsi
call   1030 <min@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OICStrcpyPartial>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     1169 <OICStrcpyPartial+0x49>
mov    %rdx,%r14
test   %rdx,%rdx
je     1169 <OICStrcpyPartial+0x49>
mov    %rdi,%rbx
test   %rsi,%rsi
je     1166 <OICStrcpyPartial+0x46>
test   %rcx,%rcx
je     1166 <OICStrcpyPartial+0x46>
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rsi
mov    %rsi,%rdi
mov    %rcx,%rsi
call   1030 <min@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strncat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @OICStrcpyPartial(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12, %4
store i8* null, i8** %5
br label %34
16: ; preds = %12
%17 = load i64, i64* %7
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i64, i64* %9
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19, %16
%23 = load i8*, i8** %6
store i8* %23, i8** %5
br label %34
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 0, i8* %26
%27 = load i8*, i8** %6
%28 = load i8*, i8** %8
%29 = load i64, i64* %7
%30 = sub i64 %29, 1
%31 = load i64, i64* %9
%32 = call i32 @min(i64 %30, i64 %31)
%33 = call i8* @strncat(i8* %27, i8* %28, i32 %32)
store i8* %33, i8** %5
br label %34
34: ; preds = %24, %22, %15
%35 = load i8*, i8** %5
ret i8* %35
}

LLVM IR (-O2):
define i8* @OICStrcpyPartial(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = icmp ne i8* %0, null
%6 = icmp ne i8* %2, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = icmp eq i64 %1, 0
%10 = icmp eq i64 %3, 0
%11 = or i1 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %8
store i8 0, i8* %0
%13 = add i64 %1, -1
%14 = tail call i32 @min(i64 %13, i64 %3)
%15 = tail call i8* @strncat(i8* %0, i8* %2, i32 %14)
br label %16
16: ; preds = %8, %4, %12
%17 = phi i8* [ %15, %12 ], [ null, %4 ], [ %0, %8 ]
ret i8* %17
}