#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 *);
void *malloc(size_t);
int /*<<< orphan*/ memcpy(void *, void const *, size_t);
int /*<<< orphan*/ stderr;
__attribute__((unused)) void *ls_xmemdup(const void *p, size_t n) {
  void *r = malloc(n);
  if (n) {
    if (!r) {
      do {
        fprintf(stderr, "LS_PANIC() at %s:%d: %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/shdown/luastatus/refs/heads/"
                "master/libls/alloc_utils.h",
                124, "out of memory");
        abort();
      } while (0);
    }
    memcpy(r, p, n);
  }
  return r;
}


x86 assembly (clang, -O0):
<ls_xmemdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b8 <ls_xmemdup+0x78>
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <ls_xmemdup+0x67>
jmp    1178 <ls_xmemdup+0x38>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
lea    0xe8a(%rip),%rdx
mov    $0x7c,%ecx
lea    0xf0f(%rip),%r8
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls_xmemdup>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     116e <ls_xmemdup+0x2e>
test   %r14,%r14
je     1177 <ls_xmemdup+0x37>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
lea    0xe8b(%rip),%rdx
lea    0xf15(%rip),%r8
mov    $0x7c,%ecx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"LS_PANIC() at %s:%d: %s\0A\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/shdown/luastatus/refs/heads/master/libls/alloc_utils.h\00"
@.str.2 = [14 x i8] c"out of memory\00"
define i8* @ls_xmemdup(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = call i8* @malloc(i64 %6)
store i8* %7, i8** %5
%8 = load i64, i64* %4
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10
br label %14
14: ; preds = %13
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %10
%20 = load i8*, i8** %5
%21 = load i8*, i8** %3
%22 = load i64, i64* %4
%23 = call i32 @memcpy(i8* %20, i8* %21, i64 %22)
br label %24
24: ; preds = %19, %2
%25 = load i8*, i8** %5
ret i8* %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"LS_PANIC() at %s:%d: %s\0A\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/shdown/luastatus/refs/heads/master/libls/alloc_utils.h\00"
@.str.2 = [14 x i8] c"out of memory\00"
define i8* @ls_xmemdup(i8* %0, i64 %1) {
%3 = tail call i8* @malloc(i64 %1)
%4 = icmp eq i64 %1, 0
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = icmp eq i8* %3, null
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 124, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %5
%12 = tail call i32 @memcpy(i8* %3, i8* %0, i64 %1)
br label %13
13: ; preds = %11, %2
ret i8* %3
}