#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*/ Rf_error(char *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int trio_copy_max(char *target, size_t max, const char *source) {
  if (!(target))
    Rf_error("internal error in trio library");
  if (!(source))
    Rf_error("internal error in trio library");
  if (!(max > 0))
    Rf_error("internal error in trio library");
  (void)strncpy(target, source, max - 1);
  target[max - 1] = (char)0;
  return (!(1 == 0));
}


x86 assembly (clang, -O0):
<trio_copy_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114b <trio_copy_max+0x2b>
lea    0xeba(%rip),%rdi
call   1040 <Rf_error@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1162 <trio_copy_max+0x42>
lea    0xea3(%rip),%rdi
call   1040 <Rf_error@plt>
cmpq   $0x0,-0x10(%rbp)
ja     1179 <trio_copy_max+0x59>
lea    0xe8c(%rip),%rdi
call   1040 <Rf_error@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trio_copy_max>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     115d <trio_copy_max+0x3d>
test   %r15,%r15
je     116e <trio_copy_max+0x4e>
test   %r14,%r14
je     117f <trio_copy_max+0x5f>
lea    -0x1(%r14),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%rbx,%r14,1)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe9c(%rip),%rdi
call   1040 <Rf_error@plt>
test   %r15,%r15
jne    1138 <trio_copy_max+0x18>
lea    0xe8b(%rip),%rdi
call   1040 <Rf_error@plt>
test   %r14,%r14
jne    113d <trio_copy_max+0x1d>
lea    0xe7a(%rip),%rdi
call   1040 <Rf_error@plt>
jmp    113d <trio_copy_max+0x1d>

LLVM IR (-O0):
@.str = [31 x i8] c"internal error in trio library\00"
define i32 @trio_copy_max(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = call i32 @Rf_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @Rf_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = load i64, i64* %5
%18 = icmp ugt i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 @Rf_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = load i8*, i8** %4
%23 = load i8*, i8** %6
%24 = load i64, i64* %5
%25 = sub i64 %24, 1
%26 = call i32 @strncpy(i8* %22, i8* %23, i64 %25)
%27 = load i8*, i8** %4
%28 = load i64, i64* %5
%29 = sub i64 %28, 1
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
ret i32 1
}

LLVM IR (-O2):
@.str = [31 x i8] c"internal error in trio library\00"
define i32 @trio_copy_max(i8* %0, i64 %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @Rf_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = icmp eq i8* %2, null
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @Rf_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = icmp eq i64 %1, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @Rf_error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %11
%16 = add i64 %1, -1
%17 = tail call i32 @strncpy(i8* %0, i8* %2, i64 %16)
%18 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 0, i8* %18
ret i32 1
}