#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*/ EXIT_FAILURE;
char *calloc(size_t, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *hurl_allocstrcpy(const char *str, size_t str_len, size_t alloc_padding) {
  char *newstr;
  if (str != NULL) {
    if ((newstr = calloc(str_len + alloc_padding, sizeof(char))) == NULL) {
      exit(EXIT_FAILURE);
    }
    memcpy(newstr, str, str_len);
    return newstr;
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<hurl_allocstrcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119b <hurl_allocstrcpy+0x6b>
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    117d <hurl_allocstrcpy+0x4d>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <hurl_allocstrcpy+0x73>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hurl_allocstrcpy>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1168 <hurl_allocstrcpy+0x38>
mov    %rsi,%r14
mov    %rdi,%r15
add    %rsi,%rdx
mov    %rdx,%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     1173 <hurl_allocstrcpy+0x43>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
jmp    116a <hurl_allocstrcpy+0x3a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define i8* @hurl_allocstrcpy(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %26
11: ; preds = %3
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = add i64 %12, %13
%15 = call i8* @calloc(i64 %14, i32 1)
store i8* %15, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %11
%21 = load i8*, i8** %8
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = call i32 @memcpy(i8* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %8
store i8* %25, i8** %4
br label %27
26: ; preds = %3
store i8* null, i8** %4
br label %27
27: ; preds = %26, %20
%28 = load i8*, i8** %4
ret i8* %28
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i8* @hurl_allocstrcpy(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = add i64 %2, %1
%7 = tail call i8* @calloc(i64 %6, i32 1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %5
%13 = tail call i32 @memcpy(i8* %7, i8* %0, i64 %1)
br label %14
14: ; preds = %3, %12
%15 = phi i8* [ %7, %12 ], [ null, %3 ]
ret i8* %15
}