#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*/ memmove(char *, char *, int);
int strlen(char *);
char *strstr(char *, char *);
void translate_amps(char *s) {
  char *t;
  char *start = NULL;
  while ((t = strstr(s, "&amp;")) != NULL) {
    if (start != NULL) {
      size_t n = t - s + 1;
      memmove(start, s, n);
      start += n;
    } else {
      start = t + 1;
    }
    s = t + 5;
  }
  if (start != NULL) {
    memmove(start, s, strlen(s) + 1);
  }
}


x86 assembly (clang, -O0):
<translate_amps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11c1 <translate_amps+0x91>
cmpq   $0x0,-0x18(%rbp)
je     11a4 <translate_amps+0x74>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
call   1040 <memmove@plt>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11b0 <translate_amps+0x80>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
jmp    1144 <translate_amps+0x14>
cmpq   $0x0,-0x18(%rbp)
je     11f7 <translate_amps+0xc7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memmove@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_amps>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rbx
lea    0xebd(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11c0 <translate_amps+0x90>
mov    %rax,%r15
xor    %r14d,%r14d
lea    0xea6(%rip),%r12
jmp    117e <translate_amps+0x4e>
nopl   0x0(%rax)
lea    0x1(%r15),%r14
mov    %r15,%rbx
add    $0x5,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strstr@plt>
mov    %rax,%r15
test   %rax,%rax
je     11a1 <translate_amps+0x71>
test   %r14,%r14
je     1160 <translate_amps+0x30>
mov    %r15,%r13
sub    %rbx,%r13
lea    0x1(%r13),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <memmove@plt>
add    %r13,%r14
add    $0x1,%r14
jmp    1164 <translate_amps+0x34>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <memmove@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"&amp;\00"
define void @translate_amps(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %4
br label %6
6: ; preds = %31, %1
%7 = load i8*, i8** %2
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %34
10: ; preds = %6
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load i8*, i8** %2
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = add nsw i64 %18, 1
store i64 %19, i64* %5
%20 = load i8*, i8** %4
%21 = load i8*, i8** %2
%22 = load i64, i64* %5
%23 = trunc i64 %22 to i32
%24 = call i32 @memmove(i8* %20, i8* %21, i32 %23)
%25 = load i64, i64* %5
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 %25
store i8* %27, i8** %4
br label %31
28: ; preds = %10
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %4
br label %31
31: ; preds = %28, %13
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 5
store i8* %33, i8** %2
br label %6
34: ; preds = %6
%35 = load i8*, i8** %4
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = load i8*, i8** %4
%39 = load i8*, i8** %2
%40 = load i8*, i8** %2
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %41, 1
%43 = call i32 @memmove(i8* %38, i8* %39, i32 %42)
br label %44
44: ; preds = %37, %34
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"&amp;\00"
define void @translate_amps(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %28, label %4
4: ; preds = %1, %19
%5 = phi i8* [ %22, %19 ], [ %2, %1 ]
%6 = phi i8* [ %21, %19 ], [ %0, %1 ]
%7 = phi i8* [ %20, %19 ], [ null, %1 ]
%8 = icmp eq i8* %7, null
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = ptrtoint i8* %5 to i64
%11 = ptrtoint i8* %6 to i64
%12 = sub i64 %10, %11
%13 = add nsw i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = tail call i32 @memmove(i8* %7, i8* %6, i32 %14)
%16 = getelementptr inbounds i8, i8* %7, i64 %13
br label %19
17: ; preds = %4
%18 = getelementptr inbounds i8, i8* %5, i64 1
br label %19
19: ; preds = %17, %9
%20 = phi i8* [ %16, %9 ], [ %18, %17 ]
%21 = getelementptr inbounds i8, i8* %5, i64 5
%22 = tail call i8* @strstr(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %4
24: ; preds = %19
%25 = tail call i32 @strlen(i8* %21)
%26 = add nsw i32 %25, 1
%27 = tail call i32 @memmove(i8* %20, i8* %21, i32 %26)
br label %28
28: ; preds = %1, %24
ret void
}