#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*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
char *element_replace_javascript_variables(char *destination, char *source,
                                           int row, char *state) {
  char row_string[8];
  sprintf(row_string, "%d", row);
  strcpy(destination, source);
  search_replace_string(destination, "$row", row_string);
  if (state && *state) {
    search_replace_string(destination, "$state", state);
  }
  return destination;
}


x86 assembly (clang, -O0):
<element_replace_javascript_variables>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xeab(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rdx
lea    0xe8d(%rip),%rsi
call   1040 <search_replace_string@plt>
cmpq   $0x0,-0x20(%rbp)
je     11aa <element_replace_javascript_variables+0x7a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11aa <element_replace_javascript_variables+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1040 <search_replace_string@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<element_replace_javascript_variables>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xeb8(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1040 <search_replace_string@plt>
test   %r14,%r14
je     118d <element_replace_javascript_variables+0x5d>
cmpb   $0x0,(%r14)
je     118d <element_replace_javascript_variables+0x5d>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <search_replace_string@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"$row\00"
@.str.2 = [7 x i8] c"$state\00"
define i8* @element_replace_javascript_variables(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [8 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%11 = load i32, i32* %7
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %5
%14 = load i8*, i8** %6
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8*, i8** %5
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%18 = call i32 @search_replace_string(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %30
21: ; preds = %4
%22 = load i8*, i8** %8
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = load i8*, i8** %8
%29 = call i32 @search_replace_string(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %21, %4
%31 = load i8*, i8** %5
ret i8* %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"$row\00"
@.str.2 = [7 x i8] c"$state\00"
define i8* @element_replace_javascript_variables(i8* returned %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca [8 x i8]
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
%8 = tail call i32 @strcpy(i8* %0, i8* %1)
%9 = call i32 @search_replace_string(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%10 = icmp eq i8* %3, null
br i1 %10, label %16, label %11
11: ; preds = %4
%12 = load i8, i8* %3
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @search_replace_string(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %16
16: ; preds = %14, %11, %4
ret i8* %0
}