#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*/ log_message(char *, char *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
scalar_t__ realloc(char *, size_t);
size_t strlen(char const *);
char *strmalloc(char *destination, const char *source) {
  size_t s_size = strlen(source);
  char *buff = (char *)realloc(destination, (s_size + 1) * sizeof(char));
  if (buff == NULL) {
    log_message("[ERROR][%d-%d-%d %d:%d:%d] ",
                "Could not allocate memory in config.c:63, out of memory?\r\n");
    return NULL;
  }
  memcpy(buff, source, s_size);
  *(buff + s_size) = '\0';
  return buff;
}


x86 assembly (clang, -O0):
<strmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
shl    $0x0,%rsi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a1 <strmalloc+0x61>
lea    0xe78(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <log_message@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c6 <strmalloc+0x86>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strmalloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%rsi
mov    %rbx,%rdi
call   1050 <realloc@plt>
test   %rax,%rax
je     117f <strmalloc+0x3f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%rbx,%r15,1)
jmp    1194 <strmalloc+0x54>
lea    0xe7a(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <log_message@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"[ERROR][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [59 x i8] c"Could not allocate memory in config.c:63, out of memory?\0D\0A\00"
define i8* @strmalloc(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %6
%10 = load i8*, i8** %4
%11 = load i64, i64* %6
%12 = add i64 %11, 1
%13 = mul i64 %12, 1
%14 = call i64 @realloc(i8* %10, i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %29
20: ; preds = %2
%21 = load i8*, i8** %7
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = call i32 @memcpy(i8* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %7
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %7
store i8* %28, i8** %3
br label %29
29: ; preds = %20, %18
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
@.str = [28 x i8] c"[ERROR][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [59 x i8] c"Could not allocate memory in config.c:63, out of memory?\0D\0A\00"
define i8* @strmalloc(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = add i64 %3, 1
%5 = tail call i64 @realloc(i8* %0, i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
br label %13
10: ; preds = %2
%11 = tail call i32 @memcpy(i8* %6, i8* %1, i64 %3)
%12 = getelementptr inbounds i8, i8* %6, i64 %3
store i8 0, i8* %12
br label %13
13: ; preds = %10, %8
%14 = phi i8* [ null, %8 ], [ %6, %10 ]
ret i8* %14
}