#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 */
char *xstrdup(char const *);
char *xstrsub(const char *str, char a, char b) {
  char *cpy = xstrdup(str);
  char *s = cpy;
  while (*s) {
    if (*s == a)
      *s = b;
    s++;
  }
  return cpy;
}


x86 assembly (clang, -O0):
<xstrsub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <xstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1176 <xstrsub+0x66>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1165 <xstrsub+0x55>
mov    -0xa(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113c <xstrsub+0x2c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrsub>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
call   1030 <xstrdup@plt>
mov    (%rax),%cl
test   %cl,%cl
je     1145 <xstrsub+0x35>
mov    %rax,%rdx
add    $0x1,%rdx
jmp    113b <xstrsub+0x2b>
nopl   0x0(%rax,%rax,1)
movzbl (%rdx),%ecx
add    $0x1,%rdx
test   %cl,%cl
je     1145 <xstrsub+0x35>
cmp    %bpl,%cl
jne    1130 <xstrsub+0x20>
mov    %bl,-0x1(%rdx)
jmp    1130 <xstrsub+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @xstrsub(i8* %0, i8 signext %1, i8 signext %2) {
%4 = tail call i8* @xstrdup(i8* %0)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %3, %12
%8 = phi i8 [ %14, %12 ], [ %5, %3 ]
%9 = phi i8* [ %13, %12 ], [ %4, %3 ]
%10 = icmp eq i8 %8, %1
br i1 %10, label %11, label %12
11: ; preds = %7
store i8 %2, i8* %9
br label %12
12: ; preds = %11, %7
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %12, %3
ret i8* %4
}