#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 */
typedef int /*<<< orphan*/ const wchar_t;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ const *);
int /*<<< orphan*/ const *vifm_wcsdup(int /*<<< orphan*/ const *);
int replace_wstring(wchar_t **str, const wchar_t with[]) {
  if (*str != with) {
    wchar_t *const new = vifm_wcsdup(with);
    if (new == NULL) {
      return 1;
    }
    free(*str);
    *str = new;
  }
  return 0;
}


x86 assembly (clang, -O0):
<replace_wstring>:
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
je     117c <replace_wstring+0x5c>
mov    -0x18(%rbp),%rdi
call   1040 <vifm_wcsdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1165 <replace_wstring+0x45>
movl   $0x1,-0x4(%rbp)
jmp    1183 <replace_wstring+0x63>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_wstring>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
cmp    %rsi,(%rdi)
je     1152 <replace_wstring+0x32>
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <vifm_wcsdup@plt>
test   %rax,%rax
je     114c <replace_wstring+0x2c>
mov    %rax,%rbp
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    %rbp,(%rbx)
jmp    1152 <replace_wstring+0x32>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @replace_wstring(i32** nocapture %0, i32* %1) {
%3 = load i32*, i32** %0
%4 = icmp eq i32* %3, %1
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i32* @vifm_wcsdup(i32* %1)
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = load i32*, i32** %0
%10 = tail call i32 @free(i32* %9)
store i32* %6, i32** %0
br label %11
11: ; preds = %2, %8, %5
%12 = phi i32 [ 1, %5 ], [ 0, %8 ], [ 0, %2 ]
ret i32 %12
}