#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*/ consoleEvalExpr(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ utilStrRealloc(char **, int /*<<< orphan*/, scalar_t__);
void evalExprSubstr(char *expr, int param) {
  static char *finalExpr = 0;
  utilStrRealloc(&finalExpr, 0, strlen(expr) + 32);
  char *str = finalExpr;
  while (*expr && (*expr != '%'))
    *str++ = *expr++;
  if (*expr++ == '%') {
    str += sprintf(str, "%d", param);
    while (*expr)
      *str++ = *expr++;
  }
  *str = '\0';
  consoleEvalExpr(finalExpr);
}


x86 assembly (clang, -O0):
<evalExprSubstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdx
add    $0x20,%rdx
lea    0x2ee2(%rip),%rdi
xor    %esi,%esi
call   1030 <utilStrRealloc@plt>
mov    0x2ed4(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     119d <evalExprSubstr+0x5d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ad <evalExprSubstr+0x6d>
jmp    11d4 <evalExprSubstr+0x94>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1178 <evalExprSubstr+0x38>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    124b <evalExprSubstr+0x10b>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe03(%rip),%rsi
call   1060 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1246 <evalExprSubstr+0x106>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1212 <evalExprSubstr+0xd2>
jmp    124b <evalExprSubstr+0x10b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2def(%rip),%rdi
call   1050 <consoleEvalExpr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evalExprSubstr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x20(%rax),%rdx
lea    0x2eef(%rip),%rdi
xor    %esi,%esi
call   1030 <utilStrRealloc@plt>
mov    0x2ee1(%rip),%r14
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
test   %al,%al
je     11d0 <evalExprSubstr+0x90>
cmp    $0x25,%al
je     1189 <evalExprSubstr+0x49>
mov    %al,(%r14)
add    $0x1,%r14
jmp    1170 <evalExprSubstr+0x30>
lea    0xe70(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
cltq
mov    (%rbx),%dl
test   %dl,%dl
je     11cd <evalExprSubstr+0x8d>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rax,%rcx,1),%rsi
mov    %dl,(%r14,%rsi,1)
movzbl 0x1(%rbx,%rcx,1),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    11b0 <evalExprSubstr+0x70>
add    %rax,%r14
add    %rcx,%r14
jmp    11d0 <evalExprSubstr+0x90>
add    %rax,%r14
movb   $0x0,(%r14)
mov    0x2e6d(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <consoleEvalExpr@plt>

LLVM IR (-O0):
@evalExprSubstr.finalExpr = internal global i8* null
@.str = [3 x i8] c"%d\00"
define void @evalExprSubstr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 32
%9 = call i32 @utilStrRealloc(i8** @evalExprSubstr.finalExpr, i32 0, i64 %8)
%10 = load i8*, i8** @evalExprSubstr.finalExpr
store i8* %10, i8** %5
br label %11
11: ; preds = %23, %2
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 37
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ false, %11 ], [ %20, %16 ]
br i1 %22, label %23, label %29
23: ; preds = %21
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
%26 = load i8, i8* %24
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
store i8 %26, i8* %27
br label %11
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %3
%32 = load i8, i8* %30
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 37
br i1 %34, label %35, label %53
35: ; preds = %29
%36 = load i8*, i8** %5
%37 = load i32, i32* %4
%38 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %5
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8* %41, i8** %5
br label %42
42: ; preds = %46, %35
%43 = load i8*, i8** %3
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i8*, i8** %3
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %3
%49 = load i8, i8* %47
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %5
store i8 %49, i8* %50
br label %42
52: ; preds = %42
br label %53
53: ; preds = %52, %29
%54 = load i8*, i8** %5
store i8 0, i8* %54
%55 = load i8*, i8** @evalExprSubstr.finalExpr
%56 = call i32 @consoleEvalExpr(i8* %55)
ret void
}

LLVM IR (-O2):
@evalExprSubstr.finalExpr = internal global i8* null
@.str = [3 x i8] c"%d\00"
define void @evalExprSubstr(i8* nocapture %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 32
%5 = tail call i32 @utilStrRealloc(i8** @evalExprSubstr.finalExpr, i32 0, i64 %4)
%6 = load i8*, i8** @evalExprSubstr.finalExpr
br label %7
7: ; preds = %11, %2
%8 = phi i8* [ %0, %2 ], [ %12, %11 ]
%9 = phi i8* [ %6, %2 ], [ %13, %11 ]
%10 = load i8, i8* %8
switch i8 %10, label %11 [
i8 37, label %14
i8 0, label %29
]
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %8, i64 1
%13 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %10, i8* %9
br label %7
14: ; preds = %7
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %9, i64 %16
%18 = getelementptr inbounds i8, i8* %8, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %14, %21
%22 = phi i8 [ %27, %21 ], [ %19, %14 ]
%23 = phi i8* [ %26, %21 ], [ %18, %14 ]
%24 = phi i8* [ %25, %21 ], [ %17, %14 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 %22, i8* %24
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %21
29: ; preds = %7, %21, %14
%30 = phi i8* [ %17, %14 ], [ %25, %21 ], [ %9, %7 ]
store i8 0, i8* %30
%31 = load i8*, i8** @evalExprSubstr.finalExpr
%32 = tail call i32 @consoleEvalExpr(i8* %31)
ret void
}