#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*/ pmesg(int, char *, int, char *);
int /*<<< orphan*/ strncpy(char *, char const *, unsigned long);
int oph_subset_strncpy(char *buff, const char *str, unsigned long len) {
  if (len > 1024) {
    pmesg(1,
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/OphidiaBigData/ophidia-primitives/refs/"
          "heads/master/src/oph_core_subset.c",
          25, "Invalid string (exceedes buffer length)\n");
    return -1;
  }
  strncpy(buff, str, len);
  buff[len] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<oph_subset_strncpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x400,-0x20(%rbp)
jbe    116b <oph_subset_strncpy+0x4b>
mov    $0x1,%edi
lea    0xeb2(%rip),%rsi
mov    $0x19,%edx
lea    0xf4a(%rip),%rcx
call   1040 <pmesg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <oph_subset_strncpy+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oph_subset_strncpy>:
push   %r14
push   %rbx
push   %rax
cmp    $0x401,%rdx
jb     1151 <oph_subset_strncpy+0x31>
lea    0xecc(%rip),%rsi
lea    0xf69(%rip),%rcx
mov    $0x1,%edi
mov    $0x19,%edx
call   1040 <pmesg@plt>
mov    $0xffffffff,%eax
jmp    1163 <oph_subset_strncpy+0x43>
mov    %rdx,%rbx
mov    %rdi,%r14
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [164 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OphidiaBigData/ophidia-primitives/refs/heads/master/src/oph_core_subset.c\00"
@.str.1 = [41 x i8] c"Invalid string (exceedes buffer length)\0A\00"
define i32 @oph_subset_strncpy(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%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 ugt i64 %8, 1024
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @pmesg(i32 1, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %20
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %6
%15 = load i64, i64* %7
%16 = call i32 @strncpy(i8* %13, i8* %14, i64 %15)
%17 = load i8*, i8** %5
%18 = load i64, i64* %7
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8 0, i8* %19
store i32 0, i32* %4
br label %20
20: ; preds = %12, %10
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@.str = [164 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OphidiaBigData/ophidia-primitives/refs/heads/master/src/oph_core_subset.c\00"
@.str.1 = [41 x i8] c"Invalid string (exceedes buffer length)\0A\00"
define i32 @oph_subset_strncpy(i8* %0, i8* %1, i64 %2) {
%4 = icmp ugt i64 %2, 1024
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @pmesg(i32 1, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %10
7: ; preds = %3
%8 = tail call i32 @strncpy(i8* %0, i8* %1, i64 %2)
%9 = getelementptr inbounds i8, i8* %0, i64 %2
store i8 0, i8* %9
br label %10
10: ; preds = %7, %5
%11 = phi i32 [ -1, %5 ], [ 0, %7 ]
ret i32 %11
}