#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*/ assert(int /*<<< orphan*/);
char *dbgmem_malloc(scalar_t__, char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *Strdup(const char *p) {
  char *ret =
      dbgmem_malloc(strlen(p) + 1,
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/asmodehn/Workshop/refs/"
                    "heads/master/C/DbgMem/test/main.c",
                    22);
  ;
  assert(ret != NULL && "Out of memory");
  strcpy(ret, p);
  return ret;
}


x86 assembly (clang, -O0):
<Strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
lea    0xe9d(%rip),%rsi
mov    $0x16,%edx
call   1060 <dbgmem_malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     118b <Strdup+0x4b>
mov    $0x1,%al
mov    %al,-0x11(%rbp)
jmp    118b <Strdup+0x4b>
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Strdup>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
lea    0xea9(%rip),%rsi
mov    $0x16,%edx
call   1060 <dbgmem_malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/asmodehn/Workshop/refs/heads/master/C/DbgMem/test/main.c\00"
@.str.1 = [14 x i8] c"Out of memory\00"
define i8* @Strdup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
%6 = add nsw i64 %5, 1
%7 = call i8* @dbgmem_malloc(i64 %6, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0), i32 22)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
br label %11
11: ; preds = %10, %1
%12 = phi i1 [ false, %1 ], [ true, %10 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %3
ret i8* %18
}

LLVM IR (-O2):
@.str = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/asmodehn/Workshop/refs/heads/master/C/DbgMem/test/main.c\00"
define i8* @Strdup(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @dbgmem_malloc(i64 %3, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0), i32 22)
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @strcpy(i8* %4, i8* %0)
ret i8* %4
}