#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*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *talloc_named_const(void const *, size_t, char *);
char *talloc_strdup(const void *context, const char *p) {
  char *ptr;
  size_t len;
  if (!p)
    return NULL;
  len = strlen(p);
  ptr = talloc_named_const(
      context, len + 1,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/osmocom/libosmocore/refs/heads/master/src/"
      "pseudotalloc/pseudotalloc.c"
      ":"
      "67");
  if (!ptr)
    return NULL;
  memcpy(ptr, p, len + 1);
  return ptr;
}


x86 assembly (clang, -O0):
<talloc_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1158 <talloc_strdup+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11b6 <talloc_strdup+0x86>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
lea    0xe88(%rip),%rdx
call   1030 <talloc_named_const@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1199 <talloc_strdup+0x69>
movq   $0x0,-0x8(%rbp)
jmp    11b6 <talloc_strdup+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<talloc_strdup>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     1179 <talloc_strdup+0x49>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
add    $0x1,%r15
lea    0xeaa(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <talloc_named_const@plt>
test   %rax,%rax
je     1179 <talloc_strdup+0x49>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
jmp    117b <talloc_strdup+0x4b>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/osmocom/libosmocore/refs/heads/master/src/pseudotalloc/pseudotalloc.c:67\00"
define i8* @talloc_strdup(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %2
store i8* null, i8** %3
br label %28
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %7
%14 = load i8*, i8** %4
%15 = load i64, i64* %7
%16 = add i64 %15, 1
%17 = call i8* @talloc_named_const(i8* %14, i64 %16, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %11
store i8* null, i8** %3
br label %28
21: ; preds = %11
%22 = load i8*, i8** %6
%23 = load i8*, i8** %5
%24 = load i64, i64* %7
%25 = add i64 %24, 1
%26 = call i32 @memcpy(i8* %22, i8* %23, i64 %25)
%27 = load i8*, i8** %6
store i8* %27, i8** %3
br label %28
28: ; preds = %21, %20, %10
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@.str = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/osmocom/libosmocore/refs/heads/master/src/pseudotalloc/pseudotalloc.c:67\00"
define i8* @talloc_strdup(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %1)
%6 = add i64 %5, 1
%7 = tail call i8* @talloc_named_const(i8* %0, i64 %6, i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @memcpy(i8* %7, i8* %1, i64 %6)
br label %11
11: ; preds = %4, %2, %9
%12 = phi i8* [ %7, %9 ], [ null, %2 ], [ null, %4 ]
ret i8* %12
}