#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*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ memcpy(char *, char const *, scalar_t__);
char *safe_malloc_internal(scalar_t__, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char const *);
char *safe_strdup_internal(const char *str, char *file, int line) {
  char *ret;
  if (strlen(str) + 1 < strlen(str)) {
    fprintf(
        stderr, "Unrecoverable error in %s(%d): %s\n\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c",
        146, "Overflow.");
    abort();
  };
  ret = safe_malloc_internal(strlen(str) + 1, file, line);
  memcpy(ret, str, strlen(str) + 1);
  return ret;
}


x86 assembly (clang, -O0):
<safe_strdup_internal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jge    11bc <safe_strdup_internal+0x6c>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
lea    0xe80(%rip),%rdx
mov    $0x92,%ecx
lea    0xef8(%rip),%r8
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <safe_malloc_internal@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_strdup_internal>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <safe_malloc_internal@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <memcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Unrecoverable error in %s(%d): %s\0A\0A\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/iagox86/nbtool/refs/heads/master/memory.c\00"
@.str.2 = [10 x i8] c"Overflow.\00"
define i8* @safe_strdup_internal(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
%13 = icmp slt i64 %10, %12
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 146, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 1
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = call i8* @safe_malloc_internal(i64 %21, i8* %22, i32 %23)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = load i8*, i8** %4
%27 = load i8*, i8** %4
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i32 @memcpy(i8* %25, i8* %26, i64 %29)
%31 = load i8*, i8** %7
ret i8* %31
}

LLVM IR (-O2):
@stderr = global i32 0
define i8* @safe_strdup_internal(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 1
%6 = tail call i8* @safe_malloc_internal(i64 %5, i8* %1, i32 %2)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = add nsw i64 %7, 1
%9 = tail call i32 @memcpy(i8* %6, i8* %0, i64 %8)
ret i8* %6
}