#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 core_strncpy(char *buff, const char *str, unsigned long *str_len) {
  if (65536 < *str_len) {
    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.c",
          39, "Invalid string (exceedes buffer length)\n");
    return -1;
  }
  strncpy(buff, str, *str_len);
  buff[*str_len] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<core_strncpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    $0x10000,%eax
cmp    (%rcx),%rax
jae    116f <core_strncpy+0x4f>
mov    $0x1,%edi
lea    0xeae(%rip),%rsi
mov    $0x27,%edx
lea    0xf3f(%rip),%rcx
call   1040 <pmesg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <core_strncpy+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<core_strncpy>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    (%rdx),%rdx
cmp    $0x10001,%rdx
jb     1157 <core_strncpy+0x37>
lea    0xec6(%rip),%rsi
lea    0xf5c(%rip),%rcx
mov    $0x1,%edi
mov    $0x27,%edx
call   1040 <pmesg@plt>
mov    $0xffffffff,%eax
jmp    1169 <core_strncpy+0x49>
mov    %rdi,%r14
call   1030 <strncpy@plt>
mov    (%rbx),%rax
movb   $0x0,(%r14,%rax,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [157 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.c\00"
@.str.1 = [41 x i8] c"Invalid string (exceedes buffer length)\0A\00"
define i32 @core_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 = load i64, i64* %8
%10 = icmp ult i64 65536, %9
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @pmesg(i32 1, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 39, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %23
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = load i64*, i64** %7
%17 = load i64, i64* %16
%18 = call i32 @strncpy(i8* %14, i8* %15, i64 %17)
%19 = load i8*, i8** %5
%20 = load i64*, i64** %7
%21 = load i64, i64* %20
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
store i32 0, i32* %4
br label %23
23: ; preds = %13, %11
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@.str = [157 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.c\00"
@.str.1 = [41 x i8] c"Invalid string (exceedes buffer length)\0A\00"
define i32 @core_strncpy(i8* %0, i8* %1, i64* nocapture %2) {
%4 = load i64, i64* %2
%5 = icmp ugt i64 %4, 65536
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @pmesg(i32 1, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0), i32 39, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %12
8: ; preds = %3
%9 = tail call i32 @strncpy(i8* %0, i8* %1, i64 %4)
%10 = load i64, i64* %2
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %13
}