#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 */
typedef int /*<<< orphan*/ szPayload;

/* Variables and functions */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *swirjson_szSerialize(const char *szKey, const char *szValue,
                           unsigned long ulTimestamp) {
  char szPayload[2048];
  memset(szPayload, 0, sizeof(szPayload));
  if (ulTimestamp == 0) {
    sprintf(szPayload, "\"%s\":\"%s\"", szKey, szValue);
  } else {
    sprintf(szPayload, "\"%lu000\":{\"%s\":\"%s\"}", ulTimestamp, szKey,
            szValue);
  }
  char *pszJson = (char *)malloc(strlen(szPayload) + 1);
  strcpy(pszJson, szPayload);
  return pszJson;
}


x86 assembly (clang, -O0):
<swirjson_szSerialize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <swirjson_szSerialize+0x57>
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    11c8 <swirjson_szSerialize+0x78>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x828(%rbp)
mov    -0x828(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x828(%rbp),%rax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swirjson_szSerialize>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1050 <memset@plt>
test   %rbx,%rbx
je     1195 <swirjson_szSerialize+0x45>
lea    0xe8a(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    11ac <swirjson_szSerialize+0x5c>
lea    0xe64(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"\22%s\22:\22%s\22\00"
@.str.1 = [21 x i8] c"\22%lu000\22:{\22%s\22:\22%s\22}\00"
define i8* @swirjson_szSerialize(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [2048 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 2048)
%11 = load i64, i64* %6
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
br label %24
18: ; preds = %3
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%20 = load i64, i64* %6
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %20, i8* %21, i8* %22)
br label %24
24: ; preds = %18, %13
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = call i64 @malloc(i64 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %8
ret i8* %33
}

LLVM IR (-O2):
@.str = [10 x i8] c"\22%s\22:\22%s\22\00"
@.str.1 = [21 x i8] c"\22%lu000\22:{\22%s\22:\22%s\22}\00"
define i8* @swirjson_szSerialize(i8* %0, i8* %1, i64 %2) {
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 2048)
%7 = icmp eq i64 %2, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
br label %12
10: ; preds = %3
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %2, i8* %0, i8* %1)
br label %12
12: ; preds = %10, %8
%13 = call i64 @strlen(i8* %5)
%14 = add nsw i64 %13, 1
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
%17 = call i32 @strcpy(i8* %16, i8* %5)
ret i8* %16
}