#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*/ back_move(char *);
int strlen(char *);
void add_quote(char *s) {
  char *p = s + strlen(s);
  while (p != s) {
    if (*p == '\'') {
      back_move(p);
    }
    p--;
  }
  if ('\'' == *s) {
    back_move(s);
  }
}


x86 assembly (clang, -O0):
<add_quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     1185 <add_quote+0x65>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    1174 <add_quote+0x54>
mov    -0x10(%rbp),%rdi
call   1040 <back_move@plt>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    114d <add_quote+0x2d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x27,%eax
cmp    %ecx,%eax
jne    11a2 <add_quote+0x82>
mov    -0x8(%rbp),%rdi
call   1040 <back_move@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_quote>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     1158 <add_quote+0x38>
movslq %eax,%rbx
jmp    1146 <add_quote+0x26>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffffffffffff,%rbx
je     1158 <add_quote+0x38>
cmpb   $0x27,(%r14,%rbx,1)
jne    1140 <add_quote+0x20>
lea    (%r14,%rbx,1),%rdi
call   1040 <back_move@plt>
jmp    1140 <add_quote+0x20>
cmpb   $0x27,(%r14)
jne    116d <add_quote+0x4d>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <back_move@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @add_quote(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %4, %13
%8 = phi i8* [ %14, %13 ], [ %6, %4 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 39
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @back_move(i8* %8)
br label %13
13: ; preds = %11, %7
%14 = getelementptr inbounds i8, i8* %8, i64 -1
%15 = icmp eq i8* %14, %0
br i1 %15, label %16, label %7
16: ; preds = %13, %1
%17 = load i8, i8* %0
%18 = icmp eq i8 %17, 39
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @back_move(i8* %0)
br label %21
21: ; preds = %19, %16
ret void
}