#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 */
scalar_t__ allocate(int);
int strlen(char *);
char *copyAndQuoteDollarSigns(char *unquotedString) {
  char *quotedString = (char *)allocate(strlen(unquotedString) * 2 + 1);
  char *source = unquotedString;
  char *destination = quotedString;
  while (*source != '\0') {
    if (*source == '$') {
      *destination++ = '$';
      *destination = '_';
    } else
      *destination = *source;
    source++;
    destination++;
  }
  return quotedString;
}


x86 assembly (clang, -O0):
<copyAndQuoteDollarSigns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1040 <allocate@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bd <copyAndQuoteDollarSigns+0x9d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    1194 <copyAndQuoteDollarSigns+0x74>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x24,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x5f,(%rax)
jmp    11a0 <copyAndQuoteDollarSigns+0x80>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1156 <copyAndQuoteDollarSigns+0x36>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyAndQuoteDollarSigns>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1040 <allocate@plt>
mov    %rax,%rcx
jmp    1151 <copyAndQuoteDollarSigns+0x31>
nopl   0x0(%rax)
movw   $0x5f24,(%rcx)
add    $0x1,%rcx
add    $0x1,%rbx
add    $0x1,%rcx
movzbl (%rbx),%edx
cmp    $0x24,%dl
je     1140 <copyAndQuoteDollarSigns+0x20>
test   %dl,%dl
je     1161 <copyAndQuoteDollarSigns+0x41>
mov    %dl,(%rcx)
jmp    1149 <copyAndQuoteDollarSigns+0x29>
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @copyAndQuoteDollarSigns(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 1
%4 = or i32 %3, 1
%5 = tail call i64 @allocate(i32 %4)
%6 = inttoptr i64 %5 to i8*
br label %7
7: ; preds = %14, %1
%8 = phi i8* [ %0, %1 ], [ %16, %14 ]
%9 = phi i8* [ %6, %1 ], [ %17, %14 ]
%10 = load i8, i8* %8
switch i8 %10, label %13 [
i8 0, label %18
i8 36, label %11
]
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %9, i64 1
store i8 36, i8* %9
store i8 95, i8* %12
br label %14
13: ; preds = %7
store i8 %10, i8* %9
br label %14
14: ; preds = %13, %11
%15 = phi i8* [ %12, %11 ], [ %9, %13 ]
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = getelementptr inbounds i8, i8* %15, i64 1
br label %7
18: ; preds = %7
ret i8* %6
}