char *debug_strdup(const char *str, const char *file, int line) {
  void *ptr;
  int len = strlen(str);
  debug_print(file, line, "strdup", str, len, 0);
  ptr = strdup(str);
  debug_addpointer(ptr, len, file, line);
  debug_print(file, line, "strdup", ptr, len, 1);
  return ptr;
}


x86 assembly (clang, -O0):
<debug_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xe8b(%rip),%rdx
xor    %r9d,%r9d
mov    $0x0,%al
call   1050 <debug_print@plt>
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x0,%al
call   1040 <debug_addpointer@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xe49(%rip),%rdx
mov    $0x1,%r9d
mov    $0x0,%al
call   1050 <debug_print@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_strdup>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rbp
lea    0xea0(%rip),%r12
mov    %r15,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %ebp,%r8d
xor    %r9d,%r9d
xor    %eax,%eax
call   1050 <debug_print@plt>
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <debug_addpointer@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %ebp,%r8d
mov    $0x1,%r9d
xor    %eax,%eax
call   1050 <debug_print@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"strdup\00"
define i8* @debug_strdup(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %8
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = load i8*, i8** %4
%15 = load i32, i32* %8
%16 = call i32 (i8*, i32, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @debug_print to i32 (i8*, i32, i8*, i8*, i32, i32, ...)*)(i8* %12, i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15, i32 0)
%17 = load i8*, i8** %4
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = load i32, i32* %8
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = call i32 (i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @debug_addpointer to i32 (i8*, i32, i8*, i32, ...)*)(i8* %19, i32 %20, i8* %21, i32 %22)
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = call i32 (i8*, i32, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @debug_print to i32 (i8*, i32, i8*, i8*, i32, i32, ...)*)(i8* %24, i32 %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %27, i32 1)
%29 = load i8*, i8** %7
ret i8* %29
}

LLVM IR (-O2):
@.str = [7 x i8] c"strdup\00"
define i8* @debug_strdup(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
%6 = tail call i32 (i8*, i32, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @debug_print to i32 (i8*, i32, i8*, i8*, i32, i32, ...)*)(i8* %1, i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %5, i32 0)
%7 = tail call i8* @strdup(i8* %0)
%8 = tail call i32 (i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @debug_addpointer to i32 (i8*, i32, i8*, i32, ...)*)(i8* %7, i32 %5, i8* %1, i32 %2)
%9 = tail call i32 (i8*, i32, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @debug_print to i32 (i8*, i32, i8*, i8*, i32, i32, ...)*)(i8* %1, i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %5, i32 1)
ret i8* %7
}