#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 */
char *malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void str_new(char *argstr, char *value) {
  if (argstr == NULL) {
    argstr = malloc(strlen(value) + 1);
    strcpy(argstr, value);
    printf("%s", argstr);
  } else {
    argstr = realloc(argstr, strlen(value) + 1);
    strcpy(argstr, value);
  }
}


x86 assembly (clang, -O0):
<str_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a6 <str_new+0x56>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1050 <printf@plt>
jmp    11d8 <str_new+0x88>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_new>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
test   %rbx,%rbx
je     1188 <str_new+0x38>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <realloc@plt>
mov    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>
mov    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe5b(%rip),%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @str_new(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %26
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 1
%22 = call i8* @realloc(i8* %18, i64 %21)
store i8* %22, i8** %3
%23 = load i8*, i8** %3
%24 = load i8*, i8** %4
%25 = call i32 @strcpy(i8* %23, i8* %24)
br label %26
26: ; preds = %17, %7
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define void @str_new(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add nsw i64 %4, 1
br i1 %3, label %6, label %10
6: ; preds = %2
%7 = tail call i8* @malloc(i64 %5)
%8 = tail call i32 @strcpy(i8* %7, i8* %1)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %13
10: ; preds = %2
%11 = tail call i8* @realloc(i8* %0, i64 %5)
%12 = tail call i32 @strcpy(i8* %11, i8* %1)
br label %13
13: ; preds = %10, %6
ret void
}