#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;
scalar_t__ calloc(scalar_t__, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sld_memory_pool_add(char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
char *sld_string_allocate(char *string) {
  char *new_string = NULL;
  new_string = (char *)calloc(strlen(string) + 1, sizeof(char));
  if (new_string == NULL) {
    printf("Unable to allocate memory for string: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else
    sld_memory_pool_add(new_string);
  return new_string;
}


x86 assembly (clang, -O0):
<sld_string_allocate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c8 <sld_string_allocate+0x68>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1060 <sld_memory_pool_add@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sld_string_allocate>:
push   %rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     1189 <sld_string_allocate+0x29>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <sld_memory_pool_add@plt>
mov    %rbx,%rax
pop    %rbx
ret
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe62(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"Unable to allocate memory for string: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @sld_string_allocate(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
%6 = add nsw i64 %5, 1
%7 = call i64 @calloc(i64 %6, i32 1)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i32 @sld_memory_pool_add(i8* %18)
br label %20
20: ; preds = %17
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@.str = [42 x i8] c"Unable to allocate memory for string: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @sld_string_allocate(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i64 @calloc(i64 %3, i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = tail call i32 @sld_memory_pool_add(i8* %5)
ret i8* %5
}