#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*/ aug_abort(char *, int, char *);
char *mem_alloc(size_t, void *, char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *aug_strdup_loc(const char *str, void *parent, char *file, int line) {
  char *new;
  size_t size;
  ;
  if (!str)
    aug_abort(file, line, "Attempt to duplicate a NULL string");
  size = strlen(str) + 1;
  ;
  new = mem_alloc(size, parent, file, line);
  ;
  strcpy(new, str);
  return new;
}


x86 assembly (clang, -O0):
<aug_strdup_loc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1175 <aug_strdup_loc+0x35>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    0xe90(%rip),%rdx
call   1060 <aug_abort@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1050 <mem_alloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aug_strdup_loc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
test   %rdi,%rdi
jne    116a <aug_strdup_loc+0x2a>
lea    0xea1(%rip),%rdx
mov    %rbp,%rdi
mov    %r14d,%esi
call   1060 <aug_abort@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1050 <mem_alloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Attempt to duplicate a NULL string\00"
define i8* @aug_strdup_loc(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %4
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = call i32 @aug_abort(i8* %14, i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %13, %4
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
store i64 %21, i64* %10
%22 = load i64, i64* %10
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = load i32, i32* %8
%26 = call i8* @mem_alloc(i64 %22, i8* %23, i8* %24, i32 %25)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = load i8*, i8** %5
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** %9
ret i8* %30
}

LLVM IR (-O2):
@.str = [35 x i8] c"Attempt to duplicate a NULL string\00"
define i8* @aug_strdup_loc(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @aug_abort(i8* %2, i32 %3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = tail call i8* @mem_alloc(i64 %11, i8* %1, i8* %2, i32 %3)
%13 = tail call i32 @strcpy(i8* %12, i8* %0)
ret i8* %12
}