#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*/ ht_insert(char *, unsigned long, char *);
int /*<<< orphan*/ initialize();
char *malloc(unsigned long);
int /*<<< orphan*/ mark_corruption(char *, unsigned long);
int /*<<< orphan*/ memcpy(char *, char const *, unsigned long);
int /*<<< orphan*/ outofmem(char *);
int strlen(char const *);
char *mhandle_strdup(const char *s, char *at) {
  char *ptr;
  unsigned long size = strlen(s) + 1;
  initialize();
  ptr = malloc(size + (2 * 2));
  if (!ptr)
    outofmem(at);
  memcpy(ptr + 2, s, size);
  mark_corruption(ptr, size);
  ht_insert(ptr, size, at);
  return ptr + 2;
}


x86 assembly (clang, -O0):
<mhandle_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <initialize@plt>
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11be <mhandle_strdup+0x4e>
mov    -0x10(%rbp),%rdi
call   1080 <outofmem@plt>
mov    -0x18(%rbp),%rdi
add    $0x2,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <mark_corruption@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1090 <ht_insert@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mhandle_strdup>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
movslq %eax,%rbx
lea    0x1(%rbx),%r12
xor    %eax,%eax
call   1050 <initialize@plt>
add    $0x5,%rbx
mov    %rbx,%rdi
call   1070 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11ae <mhandle_strdup+0x3e>
mov    %r14,%rdi
call   1080 <outofmem@plt>
mov    %r13,%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <memcpy@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <mark_corruption@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1090 <ht_insert@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @mhandle_strdup(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
store i64 %10, i64* %6
%11 = call i32 (...) @initialize()
%12 = load i64, i64* %6
%13 = add i64 %12, 4
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 @outofmem(i8* %18)
br label %20
20: ; preds = %17, %2
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = load i8*, i8** %3
%24 = load i64, i64* %6
%25 = call i32 @memcpy(i8* %22, i8* %23, i64 %24)
%26 = load i8*, i8** %5
%27 = load i64, i64* %6
%28 = call i32 @mark_corruption(i8* %26, i64 %27)
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = load i8*, i8** %4
%32 = call i32 @ht_insert(i8* %29, i64 %30, i8* %31)
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 2
ret i8* %34
}

LLVM IR (-O2):
define i8* @mhandle_strdup(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = sext i32 %4 to i64
%6 = tail call i32 (...) @initialize()
%7 = add nsw i64 %5, 4
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @outofmem(i8* %1)
br label %12
12: ; preds = %10, %2
%13 = getelementptr inbounds i8, i8* %8, i64 2
%14 = tail call i32 @memcpy(i8* %13, i8* %0, i64 %5)
%15 = tail call i32 @mark_corruption(i8* %8, i64 %5)
%16 = tail call i32 @ht_insert(i8* %8, i64 %5, i8* %1)
ret i8* %13
}