#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*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
int /*<<< orphan*/ memset(char *, char, scalar_t__);
char *strdup(char *);
scalar_t__ strlen(char *);
char *config_assign_str(char **dst, char *v) {
  if (*dst == NULL) {
    if (v != NULL && strlen(v) > 0)
      *dst = strdup(v);
  } else {
    if (v != NULL && strlen(v) > 0) {
      memset(*dst, '\0', strlen(v) + 1);
      memcpy(*dst, v, strlen(v));
    } else
      free(*dst);
  }
  return *dst;
}


x86 assembly (clang, -O0):
<config_assign_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11a4 <config_assign_str+0x54>
cmpq   $0x0,-0x10(%rbp)
je     119f <config_assign_str+0x4f>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    119f <config_assign_str+0x4f>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    122a <config_assign_str+0xda>
cmpq   $0x0,-0x10(%rbp)
je     1219 <config_assign_str+0xc9>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    1219 <config_assign_str+0xc9>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
call   1060 <memcpy@plt>
jmp    1225 <config_assign_str+0xd5>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
jmp    122a <config_assign_str+0xda>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_assign_str>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rbx
test   %rbx,%rbx
je     11a1 <config_assign_str+0x51>
test   %r15,%r15
je     11c0 <config_assign_str+0x70>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    11c0 <config_assign_str+0x70>
add    $0x1,%rax
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   1050 <memset@plt>
mov    (%r14),%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1060 <memcpy@plt>
jmp    11c8 <config_assign_str+0x78>
test   %r15,%r15
je     11c8 <config_assign_str+0x78>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    11c8 <config_assign_str+0x78>
mov    %r15,%rdi
call   1070 <strdup@plt>
mov    %rax,(%r14)
jmp    11c8 <config_assign_str+0x78>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    (%r14),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @config_assign_str(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 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i8* @strdup(i8* %16)
%18 = load i8**, i8*** %3
store i8* %17, i8** %18
br label %19
19: ; preds = %15, %11, %8
br label %45
20: ; preds = %2
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = call i64 @strlen(i8* %24)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %23
%28 = load i8**, i8*** %3
%29 = load i8*, i8** %28
%30 = load i8*, i8** %4
%31 = call i64 @strlen(i8* %30)
%32 = add nsw i64 %31, 1
%33 = call i32 @memset(i8* %29, i8 signext 0, i64 %32)
%34 = load i8**, i8*** %3
%35 = load i8*, i8** %34
%36 = load i8*, i8** %4
%37 = load i8*, i8** %4
%38 = call i64 @strlen(i8* %37)
%39 = call i32 @memcpy(i8* %35, i8* %36, i64 %38)
br label %44
40: ; preds = %23, %20
%41 = load i8**, i8*** %3
%42 = load i8*, i8** %41
%43 = call i32 @free(i8* %42)
br label %44
44: ; preds = %40, %27
br label %45
45: ; preds = %44, %19
%46 = load i8**, i8*** %3
%47 = load i8*, i8** %46
ret i8* %47
}

LLVM IR (-O2):
define i8* @config_assign_str(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
%5 = icmp eq i8* %1, null
br i1 %4, label %6, label %12
6: ; preds = %2
br i1 %5, label %24, label %7
7: ; preds = %6
%8 = tail call i64 @strlen(i8* %1)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = tail call i8* @strdup(i8* %1)
store i8* %11, i8** %0
br label %24
12: ; preds = %2
br i1 %5, label %22, label %13
13: ; preds = %12
%14 = tail call i64 @strlen(i8* %1)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = add nuw nsw i64 %14, 1
%18 = tail call i32 @memset(i8* %3, i8 signext 0, i64 %17)
%19 = load i8*, i8** %0
%20 = tail call i64 @strlen(i8* %1)
%21 = tail call i32 @memcpy(i8* %19, i8* %1, i64 %20)
br label %24
22: ; preds = %13, %12
%23 = tail call i32 @free(i8* %3)
br label %24
24: ; preds = %16, %22, %6, %7, %10
%25 = load i8*, i8** %0
ret i8* %25
}