#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*/ printf(char *, ...);
int strlen(char *);
void ReplaceQuote(char *string) {
  bool flag = 0;
  for (int i = 0; i < strlen(string); i++) {
    if (string[i] == '"') {
      switch (flag) {
      case 0:
        printf("``");
        break;
      case 1:
        printf("''");
      }
      flag = !flag;
      continue;
    }
    printf("%c", string[i]);
  }
}


x86 assembly (clang, -O0):
<ReplaceQuote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11ee <ReplaceQuote+0xce>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    11c6 <ReplaceQuote+0xa6>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     118f <ReplaceQuote+0x6f>
jmp    117e <ReplaceQuote+0x5e>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     11a2 <ReplaceQuote+0x82>
jmp    11b0 <ReplaceQuote+0x90>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11b0 <ReplaceQuote+0x90>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
jmp    11e0 <ReplaceQuote+0xc0>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <ReplaceQuote+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReplaceQuote>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   1040 <strlen@plt>
test   %eax,%eax
jle    11a3 <ReplaceQuote+0x73>
lea    0xeb5(%rip),%r14
lea    0xeb1(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1178 <ReplaceQuote+0x48>
nopl   0x0(%rax,%rax,1)
call   1030 <putchar@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11a3 <ReplaceQuote+0x73>
movsbl (%r12,%rbx,1),%edi
cmp    $0x22,%edi
jne    1160 <ReplaceQuote+0x30>
mov    %r14,%rdi
test   %ebp,%ebp
je     1191 <ReplaceQuote+0x61>
cmp    $0x1,%ebp
jne    1198 <ReplaceQuote+0x68>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
mov    %eax,%ebp
jmp    1165 <ReplaceQuote+0x35>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"``\00"
@.str.1 = [3 x i8] c"''\00"
@.str.2 = [3 x i8] c"%c\00"
define void @ReplaceQuote(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %37, %1
%6 = load i32, i32* %4
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %40
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 34
br i1 %17, label %18, label %29
18: ; preds = %10
%19 = load i32, i32* %3
switch i32 %19, label %24 [
i32 0, label %20
i32 1, label %22
]
20: ; preds = %18
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %24
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %18, %20
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
%28 = zext i1 %27 to i32
store i32 %28, i32* %3
br label %37
29: ; preds = %10
%30 = load i8*, i8** %2
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %29, %24
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %5
40: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"``\00"
@.str.1 = [3 x i8] c"''\00"
define void @ReplaceQuote(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %5, label %4
4: ; preds = %22, %1
ret void
5: ; preds = %1, %22
%6 = phi i64 [ %24, %22 ], [ 0, %1 ]
%7 = phi i32 [ %23, %22 ], [ 0, %1 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 34
br i1 %10, label %11, label %19
11: ; preds = %5
switch i32 %7, label %16 [
i32 0, label %13
i32 1, label %12
]
12: ; preds = %11
br label %13
13: ; preds = %11, %12
%14 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %12 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %11 ]
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %14)
br label %16
16: ; preds = %13, %11
%17 = icmp eq i32 %7, 0
%18 = zext i1 %17 to i32
br label %22
19: ; preds = %5
%20 = sext i8 %9 to i32
%21 = tail call i32 @putchar(i32 %20)
br label %22
22: ; preds = %19, %16
%23 = phi i32 [ %18, %16 ], [ %7, %19 ]
%24 = add nuw nsw i64 %6, 1
%25 = tail call i32 @strlen(i8* %0)
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %5, label %4
}