#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 snoopy_datasourceregistry_callByName(char *, char *, char *);
int /*<<< orphan*/ snoopy_datasourceregistry_doesNameExist(char *);
int /*<<< orphan*/ snoopy_message_append(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strlen(char *);
char *strstr(char *, char *);
void snoopy_message_generateFromFormat(char *logMessage,
                                       char *logMessageFormat) {
  char *fmtPos_cur;
  char *fmtPos_nextFormatTag;
  char *fmtPos_nextFormatTagClose;
  char *msgPos_cur;
  int retVal;
  fmtPos_cur = logMessageFormat;
  fmtPos_nextFormatTag = logMessageFormat;
  msgPos_cur = logMessage;
  while (strlen(fmtPos_nextFormatTag) > 0) {
    int lengthToCopy;
    char fmtStaticText[1024];
    char dataSourceTag[100];
    int dataSourceTagLength;
    char *fmtPos_dataSourceTagArg;
    char *dataSourceNamePtr;
    char *dataSourceArgPtr;
    char dataSourceArg[1024];
    char dataSourceMsg[1024];
    fmtPos_nextFormatTag = strstr(fmtPos_cur, "%{");
    if (NULL == fmtPos_nextFormatTag) {
      snoopy_message_append(logMessage, fmtPos_cur);
      break;
    }
    lengthToCopy = fmtPos_nextFormatTag - fmtPos_cur + 1;
    if (lengthToCopy > (int)(16383 - strlen(logMessage))) {
      lengthToCopy = 16383 - strlen(logMessage);
    }
    fmtStaticText[0] = '\0';
    snprintf(fmtStaticText, lengthToCopy, "%s", fmtPos_cur);
    snoopy_message_append(logMessage, fmtStaticText);
    msgPos_cur += lengthToCopy;
    fmtPos_nextFormatTagClose = strstr(fmtPos_nextFormatTag, "}");
    if (NULL == fmtPos_nextFormatTagClose) {
      snoopy_message_append(logMessage,
                            " ERROR: Closing data source tag not found: '}'");
      break;
    }
    dataSourceTag[0] = '\0';
    dataSourceTagLength =
        (fmtPos_nextFormatTagClose - 1) - (fmtPos_nextFormatTag + 2) + 2;
    snprintf(dataSourceTag, dataSourceTagLength, "%s",
             fmtPos_nextFormatTag + 2);
    fmtPos_dataSourceTagArg = strstr(dataSourceTag, ":");
    if (NULL == fmtPos_dataSourceTagArg) {
      dataSourceNamePtr = dataSourceTag;
      dataSourceArg[0] = '\0';
      dataSourceArgPtr = dataSourceArg;
    } else {
      fmtPos_dataSourceTagArg[0] = '\0';
      dataSourceNamePtr = dataSourceTag;
      dataSourceArgPtr = fmtPos_dataSourceTagArg + 1;
    }
    if (!snoopy_datasourceregistry_doesNameExist(dataSourceNamePtr)) {
      snoopy_message_append(logMessage, "ERROR(Data source not found - ");
      snoopy_message_append(logMessage, dataSourceNamePtr);
      snoopy_message_append(logMessage, ")");
      break;
    }
    dataSourceMsg[0] = '\0';
    retVal = snoopy_datasourceregistry_callByName(
        dataSourceNamePtr, dataSourceMsg, dataSourceArgPtr);
    if ((retVal < 0)) {
      snoopy_message_append(logMessage, "ERROR(Data source failed, msg:");
      snoopy_message_append(logMessage, dataSourceMsg);
      snoopy_message_append(logMessage, ")");
    } else {
      snoopy_message_append(logMessage, dataSourceMsg);
    }
    fmtPos_cur = fmtPos_nextFormatTagClose + 1;
    msgPos_cur = fmtPos_nextFormatTagClose + 1;
  }
}


x86 assembly (clang, -O0):
<snoopy_message_generateFromFormat>:
push   %rbp
mov    %rsp,%rbp
sub    $0xce0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    1435 <snoopy_message_generateFromFormat+0x2d5>
mov    -0x18(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11d0 <snoopy_message_generateFromFormat+0x70>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <snoopy_message_append@plt>
jmp    1435 <snoopy_message_generateFromFormat+0x2d5>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0xcd4(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdx
mov    -0xcd4(%rbp),%eax
mov    $0x3fff,%ecx
sub    %rdx,%rcx
cmp    %ecx,%eax
jle    1224 <snoopy_message_generateFromFormat+0xc4>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    $0x3fff,%eax
sub    %rcx,%rax
mov    %eax,-0x38(%rbp)
movb   $0x0,-0x440(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xdc3(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x440(%rbp),%rsi
call   1070 <snoopy_message_append@plt>
mov    -0x38(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd95(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    129b <snoopy_message_generateFromFormat+0x13b>
mov    -0x8(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1070 <snoopy_message_append@plt>
jmp    1435 <snoopy_message_generateFromFormat+0x2d5>
movb   $0x0,-0x4b0(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    -0x20(%rbp),%rcx
add    $0x2,%rcx
sub    %rcx,%rax
add    $0x2,%rax
mov    %eax,-0x4b4(%rbp)
lea    -0x4b0(%rbp),%rdi
mov    -0x4b4(%rbp),%esi
mov    -0x20(%rbp),%rcx
add    $0x2,%rcx
lea    0xd28(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x4b0(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x4c0(%rbp)
xor    %eax,%eax
cmp    -0x4c0(%rbp),%rax
jne    1331 <snoopy_message_generateFromFormat+0x1d1>
lea    -0x4b0(%rbp),%rax
mov    %rax,-0x4c8(%rbp)
movb   $0x0,-0x8d0(%rbp)
lea    -0x8d0(%rbp),%rax
mov    %rax,-0x4d0(%rbp)
jmp    135b <snoopy_message_generateFromFormat+0x1fb>
mov    -0x4c0(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x4b0(%rbp),%rax
mov    %rax,-0x4c8(%rbp)
mov    -0x4c0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x4d0(%rbp)
mov    -0x4c8(%rbp),%rdi
call   1060 <snoopy_datasourceregistry_doesNameExist@plt>
cmp    $0x0,%eax
jne    13a5 <snoopy_message_generateFromFormat+0x245>
mov    -0x8(%rbp),%rdi
lea    0xcbc(%rip),%rsi
call   1070 <snoopy_message_append@plt>
mov    -0x8(%rbp),%rdi
mov    -0x4c8(%rbp),%rsi
call   1070 <snoopy_message_append@plt>
mov    -0x8(%rbp),%rdi
lea    0xcbb(%rip),%rsi
call   1070 <snoopy_message_append@plt>
jmp    1435 <snoopy_message_generateFromFormat+0x2d5>
movb   $0x0,-0xcd0(%rbp)
mov    -0x4c8(%rbp),%rdi
lea    -0xcd0(%rbp),%rsi
mov    -0x4d0(%rbp),%rdx
call   1030 <snoopy_datasourceregistry_callByName@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1408 <snoopy_message_generateFromFormat+0x2a8>
mov    -0x8(%rbp),%rdi
lea    0xc7a(%rip),%rsi
call   1070 <snoopy_message_append@plt>
mov    -0x8(%rbp),%rdi
lea    -0xcd0(%rbp),%rsi
call   1070 <snoopy_message_append@plt>
mov    -0x8(%rbp),%rdi
lea    0xc58(%rip),%rsi
call   1070 <snoopy_message_append@plt>
jmp    1418 <snoopy_message_generateFromFormat+0x2b8>
mov    -0x8(%rbp),%rdi
lea    -0xcd0(%rbp),%rsi
call   1070 <snoopy_message_append@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    118b <snoopy_message_generateFromFormat+0x2b>
add    $0xce0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snoopy_message_generateFromFormat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc88,%rsp
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    134b <snoopy_message_generateFromFormat+0x1db>
lea    0xe64(%rip),%r12
lea    0x80(%rsp),%r15
mov    %r13,0x8(%rsp)
jmp    11dc <snoopy_message_generateFromFormat+0x6c>
xchg   %ax,%ax
mov    0x8(%rsp),%r13
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <snoopy_message_append@plt>
lea    0xe3c(%rip),%r12
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    134b <snoopy_message_generateFromFormat+0x1db>
mov    %rbx,%rdi
lea    0xe1a(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     130d <snoopy_message_generateFromFormat+0x19d>
mov    %rax,%r14
mov    %r14d,%ebp
sub    %ebx,%ebp
add    $0x1,%ebp
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    $0x3fff,%esi
sub    %eax,%esi
cmp    %esi,%ebp
cmovle %ebp,%esi
movb   $0x0,0x880(%rsp)
lea    0x880(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1060 <snprintf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1080 <snoopy_message_append@plt>
mov    %r14,%rdi
mov    $0x7d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1312 <snoopy_message_generateFromFormat+0x1a2>
mov    %rax,%rbx
movb   $0x0,0x10(%rsp)
mov    %r14,%rcx
add    $0x2,%rcx
mov    %ecx,%eax
not    %eax
lea    (%rax,%rbx,1),%esi
add    $0x2,%esi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rdx
call   1060 <snprintf@plt>
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     12a0 <snoopy_message_generateFromFormat+0x130>
mov    %rax,%r13
movb   $0x0,(%rax)
add    $0x1,%r13
jmp    12b0 <snoopy_message_generateFromFormat+0x140>
nopl   0x0(%rax)
movb   $0x0,0x480(%rsp)
lea    0x480(%rsp),%r13
lea    0x10(%rsp),%rdi
mov    %rdi,%r12
call   1070 <snoopy_datasourceregistry_doesNameExist@plt>
test   %eax,%eax
je     131b <snoopy_message_generateFromFormat+0x1ab>
movb   $0x0,0x80(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <snoopy_datasourceregistry_callByName@plt>
test   %eax,%eax
jns    11b0 <snoopy_message_generateFromFormat+0x40>
mov    0x8(%rsp),%r13
mov    %r13,%rdi
lea    0xd68(%rip),%rsi
call   1080 <snoopy_message_append@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1080 <snoopy_message_append@plt>
mov    %r13,%rdi
lea    0xd4c(%rip),%rsi
jmp    11bb <snoopy_message_generateFromFormat+0x4b>
mov    %rbx,%rsi
jmp    1343 <snoopy_message_generateFromFormat+0x1d3>
lea    0xced(%rip),%rsi
jmp    1343 <snoopy_message_generateFromFormat+0x1d3>
lea    0xd13(%rip),%rsi
mov    0x8(%rsp),%r13
mov    %r13,%rdi
call   1080 <snoopy_message_append@plt>
lea    0x10(%rsp),%rsi
mov    %r13,%rdi
call   1080 <snoopy_message_append@plt>
lea    0xd11(%rip),%rsi
mov    %r13,%rdi
call   1080 <snoopy_message_append@plt>
add    $0xc88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%{\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"}\00"
@.str.3 = [47 x i8] c" ERROR: Closing data source tag not found: '}'\00"
@.str.4 = [2 x i8] c":\00"
@.str.5 = [31 x i8] c"ERROR(Data source not found - \00"
@.str.6 = [2 x i8] c")\00"
@.str.7 = [31 x i8] c"ERROR(Data source failed, msg:\00"
define void @snoopy_message_generateFromFormat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca [100 x i8]
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca [1024 x i8]
%18 = alloca [1024 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%19 = load i8*, i8** %4
store i8* %19, i8** %5
%20 = load i8*, i8** %4
store i8* %20, i8** %6
%21 = load i8*, i8** %3
store i8* %21, i8** %8
br label %22
22: ; preds = %136, %2
%23 = load i8*, i8** %6
%24 = call i64 @strlen(i8* %23)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %141
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = call i8* @strstr(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* null, %29
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = load i8*, i8** %5
%34 = call i32 @snoopy_message_append(i8* %32, i8* %33)
br label %141
35: ; preds = %26
%36 = load i8*, i8** %6
%37 = load i8*, i8** %5
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = add nsw i64 %40, 1
%42 = trunc i64 %41 to i32
store i32 %42, i32* %10
%43 = load i32, i32* %10
%44 = load i8*, i8** %3
%45 = call i64 @strlen(i8* %44)
%46 = sub nsw i64 16383, %45
%47 = trunc i64 %46 to i32
%48 = icmp sgt i32 %43, %47
br i1 %48, label %49, label %54
49: ; preds = %35
%50 = load i8*, i8** %3
%51 = call i64 @strlen(i8* %50)
%52 = sub nsw i64 16383, %51
%53 = trunc i64 %52 to i32
store i32 %53, i32* %10
br label %54
54: ; preds = %49, %35
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
store i8 0, i8* %55
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%57 = load i32, i32* %10
%58 = load i8*, i8** %5
%59 = call i32 @snprintf(i8* %56, i32 %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %58)
%60 = load i8*, i8** %3
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%62 = call i32 @snoopy_message_append(i8* %60, i8* %61)
%63 = load i32, i32* %10
%64 = load i8*, i8** %8
%65 = sext i32 %63 to i64
%66 = getelementptr inbounds i8, i8* %64, i64 %65
store i8* %66, i8** %8
%67 = load i8*, i8** %6
%68 = call i8* @strstr(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %68, i8** %7
%69 = load i8*, i8** %7
%70 = icmp eq i8* null, %69
br i1 %70, label %71, label %74
71: ; preds = %54
%72 = load i8*, i8** %3
%73 = call i32 @snoopy_message_append(i8* %72, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0))
br label %141
74: ; preds = %54
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
store i8 0, i8* %75
%76 = load i8*, i8** %7
%77 = getelementptr inbounds i8, i8* %76, i64 -1
%78 = load i8*, i8** %6
%79 = getelementptr inbounds i8, i8* %78, i64 2
%80 = ptrtoint i8* %77 to i64
%81 = ptrtoint i8* %79 to i64
%82 = sub i64 %80, %81
%83 = add nsw i64 %82, 2
%84 = trunc i64 %83 to i32
store i32 %84, i32* %13
%85 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%86 = load i32, i32* %13
%87 = load i8*, i8** %6
%88 = getelementptr inbounds i8, i8* %87, i64 2
%89 = call i32 @snprintf(i8* %85, i32 %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %88)
%90 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%91 = call i8* @strstr(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %91, i8** %14
%92 = load i8*, i8** %14
%93 = icmp eq i8* null, %92
br i1 %93, label %94, label %98
94: ; preds = %74
%95 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
store i8* %95, i8** %15
%96 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
store i8 0, i8* %96
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
store i8* %97, i8** %16
br label %104
98: ; preds = %74
%99 = load i8*, i8** %14
%100 = getelementptr inbounds i8, i8* %99, i64 0
store i8 0, i8* %100
%101 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
store i8* %101, i8** %15
%102 = load i8*, i8** %14
%103 = getelementptr inbounds i8, i8* %102, i64 1
store i8* %103, i8** %16
br label %104
104: ; preds = %98, %94
%105 = load i8*, i8** %15
%106 = call i32 @snoopy_datasourceregistry_doesNameExist(i8* %105)
%107 = icmp ne i32 %106, 0
br i1 %107, label %116, label %108
108: ; preds = %104
%109 = load i8*, i8** %3
%110 = call i32 @snoopy_message_append(i8* %109, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%111 = load i8*, i8** %3
%112 = load i8*, i8** %15
%113 = call i32 @snoopy_message_append(i8* %111, i8* %112)
%114 = load i8*, i8** %3
%115 = call i32 @snoopy_message_append(i8* %114, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %141
116: ; preds = %104
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
store i8 0, i8* %117
%118 = load i8*, i8** %15
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%120 = load i8*, i8** %16
%121 = call i32 @snoopy_datasourceregistry_callByName(i8* %118, i8* %119, i8* %120)
store i32 %121, i32* %9
%122 = load i32, i32* %9
%123 = icmp slt i32 %122, 0
br i1 %123, label %124, label %132
124: ; preds = %116
%125 = load i8*, i8** %3
%126 = call i32 @snoopy_message_append(i8* %125, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%127 = load i8*, i8** %3
%128 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%129 = call i32 @snoopy_message_append(i8* %127, i8* %128)
%130 = load i8*, i8** %3
%131 = call i32 @snoopy_message_append(i8* %130, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %136
132: ; preds = %116
%133 = load i8*, i8** %3
%134 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%135 = call i32 @snoopy_message_append(i8* %133, i8* %134)
br label %136
136: ; preds = %132, %124
%137 = load i8*, i8** %7
%138 = getelementptr inbounds i8, i8* %137, i64 1
store i8* %138, i8** %5
%139 = load i8*, i8** %7
%140 = getelementptr inbounds i8, i8* %139, i64 1
store i8* %140, i8** %8
br label %22
141: ; preds = %108, %71, %31, %22
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%{\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.3 = [47 x i8] c" ERROR: Closing data source tag not found: '}'\00"
@.str.5 = [31 x i8] c"ERROR(Data source not found - \00"
@.str.6 = [2 x i8] c")\00"
@.str.7 = [31 x i8] c"ERROR(Data source failed, msg:\00"
define void @snoopy_message_generateFromFormat(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [100 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = call i64 @strlen(i8* dereferenceable(1) %1)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %70
9: ; preds = %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
br label %14
14: ; preds = %9, %66
%15 = phi i8* [ %1, %9 ], [ %67, %66 ]
%16 = call i8* @strstr(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %63, label %18
18: ; preds = %14
%19 = ptrtoint i8* %16 to i64
%20 = ptrtoint i8* %15 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = add i32 %22, 1
%24 = call i64 @strlen(i8* dereferenceable(1) %0)
%25 = trunc i64 %24 to i32
%26 = sub i32 16383, %25
%27 = icmp sgt i32 %23, %26
%28 = select i1 %27, i32 %26, i32 %23
store i8 0, i8* %10
%29 = call i32 @snprintf(i8* %10, i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%30 = call i32 @snoopy_message_append(i8* %0, i8* %10)
%31 = call i8* @strchr(i8* %16, i32 125)
%32 = icmp eq i8* %31, null
br i1 %32, label %63, label %33
33: ; preds = %18
store i8 0, i8* %11
%34 = getelementptr inbounds i8, i8* %31, i64 -1
%35 = getelementptr inbounds i8, i8* %16, i64 2
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = add i32 %39, 2
%41 = call i32 @snprintf(i8* %11, i32 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%42 = call i8* @strchr(i8* %11, i32 58)
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %45
44: ; preds = %33
store i8 0, i8* %12
br label %47
45: ; preds = %33
store i8 0, i8* %42
%46 = getelementptr inbounds i8, i8* %42, i64 1
br label %47
47: ; preds = %45, %44
%48 = phi i8* [ %12, %44 ], [ %46, %45 ]
%49 = call i32 @snoopy_datasourceregistry_doesNameExist(i8* %11)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = call i32 @snoopy_message_append(i8* %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%53 = call i32 @snoopy_message_append(i8* %0, i8* %11)
br label %63
54: ; preds = %47
store i8 0, i8* %13
%55 = call i32 @snoopy_datasourceregistry_callByName(i8* %11, i8* %13, i8* %48)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %54
%58 = call i32 @snoopy_message_append(i8* %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%59 = call i32 @snoopy_message_append(i8* %0, i8* %13)
%60 = call i32 @snoopy_message_append(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %66
61: ; preds = %54
%62 = call i32 @snoopy_message_append(i8* %0, i8* %13)
br label %66
63: ; preds = %18, %14, %51
%64 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), %51 ], [ %15, %14 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), %18 ]
%65 = call i32 @snoopy_message_append(i8* %0, i8* %64)
br label %70
66: ; preds = %57, %61
%67 = getelementptr inbounds i8, i8* %31, i64 1
%68 = call i64 @strlen(i8* dereferenceable(1) %16)
%69 = icmp sgt i64 %68, 0
br i1 %69, label %14, label %70
70: ; preds = %66, %2, %63
ret void
}