#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 */
scalar_t__ iswhite(char *);
int /*<<< orphan*/ remove_chars(char *, char *, char);
char *rindex(char *, char);
int remove_ampersands(char *s) {
  char *p, *q;
  int retval;
  if ((p = rindex(s, '&')) != NULL) {
    if (iswhite(p + 1))
      retval = 1;
    else
      retval = 0;
  } else {
    retval = 0;
  }
  remove_chars(s, "&", ' ');
  return (retval);
}


x86 assembly (clang, -O0):
<remove_ampersands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x26,%esi
call   1050 <rindex@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1187 <remove_ampersands+0x57>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <iswhite@plt>
cmp    $0x0,%rax
je     117b <remove_ampersands+0x4b>
movl   $0x1,-0x1c(%rbp)
jmp    1182 <remove_ampersands+0x52>
movl   $0x0,-0x1c(%rbp)
jmp    118e <remove_ampersands+0x5e>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x20,%edx
call   1040 <remove_chars@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_ampersands>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x26,%esi
call   1050 <rindex@plt>
test   %rax,%rax
je     115c <remove_ampersands+0x2c>
add    $0x1,%rax
mov    %rax,%rdi
call   1030 <iswhite@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    115e <remove_ampersands+0x2e>
xor    %ebp,%ebp
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
mov    $0x20,%edx
call   1040 <remove_chars@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"&\00"
define i32 @remove_ampersands(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @rindex(i8* %6, i8 signext 38)
store i8* %7, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = call i64 @iswhite(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 1, i32* %5
br label %16
15: ; preds = %9
store i32 0, i32* %5
br label %16
16: ; preds = %15, %14
br label %18
17: ; preds = %1
store i32 0, i32* %5
br label %18
18: ; preds = %17, %16
%19 = load i8*, i8** %2
%20 = call i32 @remove_chars(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext 32)
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"&\00"
define i32 @remove_ampersands(i8* %0) {
%2 = tail call i8* @rindex(i8* %0, i8 signext 38)
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = tail call i64 @iswhite(i8* %5)
%7 = icmp ne i64 %6, 0
%8 = zext i1 %7 to i32
br label %9
9: ; preds = %1, %4
%10 = phi i32 [ %8, %4 ], [ 0, %1 ]
%11 = tail call i32 @remove_chars(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext 32)
ret i32 %10
}