#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 *strchr(char *, char);
void swap(char *orig, int s, int e) {
  char *tmp1, *tmp = orig;
  for (; (tmp1 = strchr(tmp, '%')) && tmp1 < orig + e; tmp1++) {
    *tmp1 = '&';
  }
}


x86 assembly (clang, -O0):
<swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     1166 <swap+0x56>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1176 <swap+0x66>
jmp    118e <swap+0x7e>
mov    -0x18(%rbp),%rax
movb   $0x26,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112a <swap+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
mov    $0x25,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     114a <swap+0x3a>
movslq %ebp,%rbp
add    %rbx,%rbp
nopl   (%rax)
cmp    %rbp,%rax
jae    114a <swap+0x3a>
movb   $0x26,(%rax)
mov    %rbx,%rdi
mov    $0x25,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1130 <swap+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @swap(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
store i8* %9, i8** %8
br label %10
10: ; preds = %25, %3
%11 = load i8*, i8** %8
%12 = call i8* @strchr(i8* %11, i8 signext 37)
store i8* %12, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i8*, i8** %7
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = icmp ult i8* %15, %19
br label %21
21: ; preds = %14, %10
%22 = phi i1 [ false, %10 ], [ %20, %14 ]
br i1 %22, label %23, label %28
23: ; preds = %21
%24 = load i8*, i8** %7
store i8 38, i8* %24
br label %25
25: ; preds = %23
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %7
br label %10
28: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @swap(i8* %0, i32 %1, i32 %2) {
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 37)
%7 = icmp ne i8* %6, null
%8 = icmp ult i8* %6, %5
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %16
10: ; preds = %3, %10
%11 = phi i8* [ %12, %10 ], [ %6, %3 ]
store i8 38, i8* %11
%12 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 37)
%13 = icmp ne i8* %12, null
%14 = icmp ult i8* %12, %5
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %10, label %16
16: ; preds = %10, %3
ret void
}