#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
char *strdup(char const *);
void selfn_strdup(char **sel, const char *arg) {
  ;
  if (*sel != NULL) {
    free(*sel);
    *sel = NULL;
  }
  *sel = strdup(arg);
  ;
  if (*sel == NULL) {
    printf("String duplicate error!\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<selfn_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1175 <selfn_strdup+0x35>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b0 <selfn_strdup+0x70>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selfn_strdup>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     115e <selfn_strdup+0x1e>
call   1030 <free@plt>
movq   $0x0,(%rbx)
mov    %r14,%rdi
call   1060 <strdup@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1176 <selfn_strdup+0x36>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"String duplicate error!\0A\00"
@EXIT_FAILURE = global i32 0
define void @selfn_strdup(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 %8, label %13
8: ; preds = %2
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = call i32 @free(i8* %10)
%12 = load i8**, i8*** %3
store i8* null, i8** %12
br label %13
13: ; preds = %8, %2
%14 = load i8*, i8** %4
%15 = call i8* @strdup(i8* %14)
%16 = load i8**, i8*** %3
store i8* %15, i8** %16
%17 = load i8**, i8*** %3
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %13
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [24 x i8] c"String duplicate error!\00"
define void @selfn_strdup(i8** nocapture %0, i8* nocapture %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @free(i8* %3)
store i8* null, i8** %0
br label %7
7: ; preds = %5, %2
%8 = tail call i8* @strdup(i8* %1)
store i8* %8, i8** %0
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %7
ret void
}