#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*/ errx(int, char *);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
void isns_assign_string(char **var, const char *val) {
  char *s = NULL;
  if (val && !(s = strdup(val)))
    errx(1, "out of memory");
  if (*var)
    free(*var);
  *var = s;
}


x86 assembly (clang, -O0):
<isns_assign_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117b <isns_assign_string+0x4b>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    117b <isns_assign_string+0x4b>
mov    $0x1,%edi
lea    0xe8a(%rip),%rsi
call   1040 <errx@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1195 <isns_assign_string+0x65>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isns_assign_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rsi,%rsi
je     115d <isns_assign_string+0x2d>
mov    %rsi,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    115f <isns_assign_string+0x2f>
lea    0xead(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
xor    %ebx,%ebx
mov    (%r14),%rdi
test   %rdi,%rdi
je     116c <isns_assign_string+0x3c>
call   1030 <free@plt>
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"out of memory\00"
define void @isns_assign_string(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = call i32 @errx(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %8, %2
%15 = load i8**, i8*** %3
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i8**, i8*** %3
%20 = load i8*, i8** %19
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %18, %14
%23 = load i8*, i8** %5
%24 = load i8**, i8*** %3
store i8* %23, i8** %24
ret void
}

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