#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 *strstr(char *, char *);
void FixTildes(char *s) {
  char *p, *p3;
  while ((p = strstr(s, "\\~{}")) != NULL) {
    *p = '~';
    p++;
    p3 = p + 3;
    while (*p3) {
      *p++ = *p3++;
    }
    *p = '\0';
  }
}


x86 assembly (clang, -O0):
<FixTildes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed9(%rip),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1199 <FixTildes+0x89>
mov    -0x10(%rbp),%rax
movb   $0x7e,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     118d <FixTildes+0x7d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1159 <FixTildes+0x49>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    111c <FixTildes+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FixTildes>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xee2(%rip),%rsi
call   1030 <strstr@plt>
test   %rax,%rax
je     1170 <FixTildes+0x60>
lea    0xed1(%rip),%r14
jmp    1153 <FixTildes+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strstr@plt>
test   %rax,%rax
je     1170 <FixTildes+0x60>
movb   $0x7e,(%rax)
cs nopw 0x0(%rax,%rax,1)
movzbl 0x4(%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     1140 <FixTildes+0x30>
mov    %cl,(%rax)
jmp    1160 <FixTildes+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\\~{}\00"
define void @FixTildes(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
br label %5
5: ; preds = %25, %1
%6 = load i8*, i8** %2
%7 = call i8* @strstr(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %27
9: ; preds = %5
%10 = load i8*, i8** %3
store i8 126, i8* %10
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 3
store i8* %14, i8** %4
br label %15
15: ; preds = %19, %9
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
store i8 %22, i8* %23
br label %15
25: ; preds = %15
%26 = load i8*, i8** %3
store i8 0, i8* %26
br label %5
27: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"\\~{}\00"
define void @FixTildes(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %22, label %4
4: ; preds = %1, %18
%5 = phi i8* [ %20, %18 ], [ %2, %1 ]
store i8 126, i8* %5
%6 = getelementptr inbounds i8, i8* %5, i64 4
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %4, %10
%11 = phi i8 [ %16, %10 ], [ %8, %4 ]
%12 = phi i8* [ %15, %10 ], [ %7, %4 ]
%13 = phi i8* [ %14, %10 ], [ %6, %4 ]
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %11, i8* %12
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %4
%19 = phi i8* [ %7, %4 ], [ %15, %10 ]
store i8 0, i8* %19
%20 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %4
22: ; preds = %18, %1
ret void
}