#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 *);
char *strdup(char const *);
int al_util_replace_string(char **dst, const char *src) {
  if (*dst == src)
    return 0;
  if (*dst)
    free(*dst);
  *dst = src ? strdup(src) : NULL;
  return 1;
}


x86 assembly (clang, -O0):
<al_util_replace_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    114d <al_util_replace_string+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    11a1 <al_util_replace_string+0x81>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1167 <al_util_replace_string+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     1184 <al_util_replace_string+0x64>
mov    -0x18(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    118f <al_util_replace_string+0x6f>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    118f <al_util_replace_string+0x6f>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<al_util_replace_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rdi
cmp    %rsi,%rdi
je     114b <al_util_replace_string+0x2b>
mov    %rsi,%rbx
test   %rdi,%rdi
je     113c <al_util_replace_string+0x1c>
call   1030 <free@plt>
test   %rbx,%rbx
je     114f <al_util_replace_string+0x2f>
mov    %rbx,%rdi
call   1040 <strdup@plt>
jmp    1151 <al_util_replace_string+0x31>
xor    %eax,%eax
jmp    1159 <al_util_replace_string+0x39>
xor    %eax,%eax
mov    %rax,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @al_util_replace_string(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%6 = load i8**, i8*** %4
%7 = load i8*, i8** %6
%8 = load i8*, i8** %5
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %29
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = call i32 @free(i8* %17)
br label %19
19: ; preds = %15, %11
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = call i8* @strdup(i8* %23)
br label %26
25: ; preds = %19
br label %26
26: ; preds = %25, %22
%27 = phi i8* [ %24, %22 ], [ null, %25 ]
%28 = load i8**, i8*** %4
store i8* %27, i8** %28
store i32 1, i32* %3
br label %29
29: ; preds = %26, %10
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @al_util_replace_string(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, %1
br i1 %4, label %15, 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)
br label %9
9: ; preds = %7, %5
%10 = icmp eq i8* %1, null
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i8* @strdup(i8* %1)
br label %13
13: ; preds = %9, %11
%14 = phi i8* [ %12, %11 ], [ null, %9 ]
store i8* %14, i8** %0
br label %15
15: ; preds = %2, %13
%16 = phi i32 [ 1, %13 ], [ 0, %2 ]
ret i32 %16
}