#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*/ search_replace_string(char *, char *, char *);
int /*<<< orphan*/ timlib_strcpy(char *, char *, int);
char *latex_escape_data(char *destination, char *source, int buffer_size) {
  if (!source)
    return "";
  timlib_strcpy(destination, source, buffer_size);
  search_replace_string(destination, "#", "Number ");
  search_replace_string(destination, "&", "\\&");
  search_replace_string(destination, "%", "\\%");
  search_replace_string(destination, "_", "\\_");
  return destination;
}


x86 assembly (clang, -O0):
<latex_escape_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114e <latex_escape_data+0x2e>
lea    0xec4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <latex_escape_data+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <timlib_strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
lea    0xe92(%rip),%rdx
call   1030 <search_replace_string@plt>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
lea    0xe83(%rip),%rdx
call   1030 <search_replace_string@plt>
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
lea    0xe6f(%rip),%rdx
call   1030 <search_replace_string@plt>
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
lea    0xe5b(%rip),%rdx
call   1030 <search_replace_string@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<latex_escape_data>:
push   %rbx
test   %rsi,%rsi
je     1188 <latex_escape_data+0x68>
mov    %rdi,%rbx
call   1040 <timlib_strcpy@plt>
lea    0xecb(%rip),%rsi
lea    0xec6(%rip),%rdx
mov    %rbx,%rdi
call   1030 <search_replace_string@plt>
lea    0xec0(%rip),%rsi
lea    0xeb8(%rip),%rdx
mov    %rbx,%rdi
call   1030 <search_replace_string@plt>
lea    0xead(%rip),%rsi
lea    0xea5(%rip),%rdx
mov    %rbx,%rdi
call   1030 <search_replace_string@plt>
lea    0xe9a(%rip),%rsi
lea    0xe92(%rip),%rdx
mov    %rbx,%rdi
call   1030 <search_replace_string@plt>
jmp    118f <latex_escape_data+0x6f>
lea    0xe7a(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"#\00"
@.str.2 = [8 x i8] c"Number \00"
@.str.3 = [2 x i8] c"&\00"
@.str.4 = [3 x i8] c"\\&\00"
@.str.5 = [2 x i8] c"%\00"
@.str.6 = [3 x i8] c"\\%\00"
@.str.7 = [2 x i8] c"_\00"
@.str.8 = [3 x i8] c"\\_\00"
define i8* @latex_escape_data(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = tail call i32 @timlib_strcpy(i8* %0, i8* %1, i32 %2)
%7 = tail call i32 @search_replace_string(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @search_replace_string(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i32 @search_replace_string(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%10 = tail call i32 @search_replace_string(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %11
11: ; preds = %3, %5
%12 = phi i8* [ %0, %5 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %3 ]
ret i8* %12
}