#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_ERR;
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
char *NewStr(char *str) {
  char *stmp;
  if ((stmp = (char *)malloc((unsigned)(strlen(str) + 1))) == NULL) {
    syslog(LOG_ERR, "NewStr: out of memory (%s)", str);
    return (NULL);
  }
  (void)strcpy(stmp, str);
  return (stmp);
}


x86 assembly (clang, -O0):
<NewStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1194 <NewStr+0x54>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7e(%rip),%rsi
call   1060 <syslog@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a9 <NewStr+0x69>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NewStr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1169 <NewStr+0x29>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    1183 <NewStr+0x43>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
mov    %r14,%rdx
call   1060 <syslog@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [27 x i8] c"NewStr: out of memory (%s)\00"
define i8* @NewStr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strlen(i8* %5)
%7 = add nsw i64 %6, 1
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @LOG_ERR
%14 = load i8*, i8** %3
%15 = call i32 @syslog(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
store i8* null, i8** %2
br label %21
16: ; preds = %1
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %4
store i8* %20, i8** %2
br label %21
21: ; preds = %16, %12
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [27 x i8] c"NewStr: out of memory (%s)\00"
define i8* @NewStr(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @LOG_ERR
%10 = tail call i32 @syslog(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
11: ; preds = %1
%12 = tail call i32 @strcpy(i8* %6, i8* %0)
br label %13
13: ; preds = %11, %8
%14 = phi i8* [ null, %8 ], [ %6, %11 ]
ret i8* %14
}