#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*/ assert(char *);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
void repstr(char **sptr, const char *val) {
  if (*sptr == val)
    return;
  if (*sptr) {
    free(*sptr);
    *sptr = 0;
  }
  if (val) {
    *sptr = strdup(val);
    assert(*sptr);
  }
}


x86 assembly (clang, -O0):
<repstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
jne    1156 <repstr+0x26>
jmp    11a5 <repstr+0x75>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     117b <repstr+0x4b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11a5 <repstr+0x75>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<repstr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rdi
cmp    %rsi,%rdi
je     1172 <repstr+0x42>
mov    %rsi,%rbx
test   %rdi,%rdi
je     1153 <repstr+0x23>
call   1030 <free@plt>
movq   $0x0,(%r14)
test   %rbx,%rbx
je     1172 <repstr+0x42>
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <assert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @repstr(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 = load i8*, i8** %4
%8 = icmp eq i8* %6, %7
br i1 %8, label %9, label %10
9: ; preds = %2
br label %29
10: ; preds = %2
%11 = load i8**, i8*** %3
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8**, i8*** %3
%16 = load i8*, i8** %15
%17 = call i32 @free(i8* %16)
%18 = load i8**, i8*** %3
store i8* null, i8** %18
br label %19
19: ; preds = %14, %10
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i8* @strdup(i8* %23)
%25 = load i8**, i8*** %3
store i8* %24, i8** %25
%26 = load i8**, i8*** %3
%27 = load i8*, i8** %26
%28 = call i32 @assert(i8* %27)
br label %29
29: ; preds = %9, %22, %19
ret void
}

LLVM IR (-O2):
define void @repstr(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, %1
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = icmp eq i8* %3, null
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 @free(i8* %3)
store i8* null, i8** %0
br label %9
9: ; preds = %7, %5
%10 = icmp eq i8* %1, null
br i1 %10, label %14, label %11
11: ; preds = %9
%12 = tail call i8* @strdup(i8* %1)
store i8* %12, i8** %0
%13 = tail call i32 @assert(i8* %12)
br label %14
14: ; preds = %2, %11, %9
ret void
}