#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*/ clean_up(char *);
char *md_malloc(int);
int /*<<< orphan*/ strlcpy(char *, char const *, int);
void init_str(char **str, const char *dflt) {
  if (!(*str)) {
    *str = md_malloc(40 + 2);
    if (*str == NULL)
      clean_up("out of memory");
    (void)strlcpy(*str, dflt, 40 + 2);
  }
}


x86 assembly (clang, -O0):
<init_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1191 <init_str+0x61>
mov    $0x2a,%edi
call   1050 <md_malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    117c <init_str+0x4c>
lea    0xe89(%rip),%rdi
call   1030 <clean_up@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2a,%edx
call   1040 <strlcpy@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_str>:
push   %r14
push   %rbx
push   %rax
cmpq   $0x0,(%rdi)
je     1142 <init_str+0x12>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2a,%edi
call   1050 <md_malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    1169 <init_str+0x39>
lea    0xe9f(%rip),%rdi
call   1030 <clean_up@plt>
mov    (%rbx),%rax
mov    %rax,%rdi
mov    %r14,%rsi
mov    $0x2a,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strlcpy@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"out of memory\00"
define void @init_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 ne i8* %6, null
br i1 %7, label %21, label %8
8: ; preds = %2
%9 = call i8* @md_malloc(i32 42)
%10 = load i8**, i8*** %3
store i8* %9, i8** %10
%11 = load i8**, i8*** %3
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @clean_up(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
%17 = load i8**, i8*** %3
%18 = load i8*, i8** %17
%19 = load i8*, i8** %4
%20 = call i32 @strlcpy(i8* %18, i8* %19, i32 42)
br label %21
21: ; preds = %16, %2
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"out of memory\00"
define void @init_str(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i8* @md_malloc(i32 42)
store i8* %6, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @clean_up(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%10 = load i8*, i8** %0
br label %11
11: ; preds = %8, %5
%12 = phi i8* [ %10, %8 ], [ %6, %5 ]
%13 = tail call i32 @strlcpy(i8* %12, i8* %1, i32 42)
br label %14
14: ; preds = %11, %2
ret void
}