#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *str_replace(char *, char *, char const *);
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char const *);
char *set_template_var(char *template, const char *key, const char *value) {
  int keylen = strlen("{{data.}}") + strlen(key) + 1;
  char *fullkey = malloc(keylen);
  memset(fullkey, 0, keylen);
  strcat(fullkey, "{{data.");
  strcat(fullkey, key);
  strcat(fullkey, "}}");
  char *ret = str_replace(template, fullkey, value);
  free(fullkey);
  return ret;
}


x86 assembly (clang, -O0):
<set_template_var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe85(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <str_replace@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_template_var>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xe88(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
lea    0xe43(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <str_replace@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"{{data.}}\00"
@.str.1 = [8 x i8] c"{{data.\00"
@.str.2 = [3 x i8] c"}}\00"
define i8* @set_template_var(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = load i32, i32* %7
%19 = call i32 @memset(i8* %17, i32 0, i32 %18)
%20 = load i8*, i8** %8
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%22 = load i8*, i8** %8
%23 = load i8*, i8** %5
%24 = call i32 @strcat(i8* %22, i8* %23)
%25 = load i8*, i8** %8
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %4
%28 = load i8*, i8** %8
%29 = load i8*, i8** %6
%30 = call i8* @str_replace(i8* %27, i8* %28, i8* %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %8
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %9
ret i8* %33
}

LLVM IR (-O2):
@.str = [10 x i8] c"{{data.}}\00"
@.str.1 = [8 x i8] c"{{data.\00"
@.str.2 = [3 x i8] c"}}\00"
define i8* @set_template_var(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 1
%7 = add i32 %6, %5
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @memset(i8* %8, i32 0, i32 %7)
%10 = tail call i32 @strcat(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @strcat(i8* %8, i8* %1)
%12 = tail call i32 @strcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i8* @str_replace(i8* %0, i8* %8, i8* %2)
%14 = tail call i32 @free(i8* %8)
ret i8* %13
}