#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*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *newDbSerializeHelperStr(int MAXBUF, char *buf, char *str,
                              int proceedComma) {
  if (buf == NULL || str == NULL)
    return NULL;
  int blen = strlen(buf);
  int slen = strlen(str);
  if ((blen + slen + 1) < MAXBUF) {
    if (proceedComma)
      strcat(buf, ",");
    strcat(buf, str);
    return (&buf[blen + slen]);
  } else {
    printf("Serialization buffer overrun\n");
  }
  return NULL;
}


x86 assembly (clang, -O0):
<newDbSerializeHelperStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     115c <newDbSerializeHelperStr+0x2c>
cmpq   $0x0,-0x20(%rbp)
jne    1169 <newDbSerializeHelperStr+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11e7 <newDbSerializeHelperStr+0xb7>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
add    $0x1,%eax
cmp    -0xc(%rbp),%eax
jge    11d3 <newDbSerializeHelperStr+0xa3>
cmpl   $0x0,-0x24(%rbp)
je     11ad <newDbSerializeHelperStr+0x7d>
mov    -0x18(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11e7 <newDbSerializeHelperStr+0xb7>
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newDbSerializeHelperStr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %rsi,%rsi
je     11aa <newDbSerializeHelperStr+0x7a>
mov    %rdx,%r14
test   %rdx,%rdx
je     11aa <newDbSerializeHelperStr+0x7a>
mov    %ecx,%r15d
mov    %rsi,%rbx
mov    %edi,%r12d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x1(%rbp,%r13,1),%eax
cmp    %r12d,%eax
jge    119c <newDbSerializeHelperStr+0x6c>
add    %r13d,%ebp
test   %r15d,%r15d
je     1189 <newDbSerializeHelperStr+0x59>
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
movslq %ebp,%rax
add    %rbx,%rax
jmp    11aa <newDbSerializeHelperStr+0x7a>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [30 x i8] c"Serialization buffer overrun\0A\00"
define i8* @newDbSerializeHelperStr(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i8*, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14, %4
store i8* null, i8** %5
br label %48
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %10
%21 = load i8*, i8** %8
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %11
%23 = load i32, i32* %10
%24 = load i32, i32* %11
%25 = add nsw i32 %23, %24
%26 = add nsw i32 %25, 1
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %18
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %32, %29
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = load i8*, i8** %7
%40 = load i32, i32* %10
%41 = load i32, i32* %11
%42 = add nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %39, i64 %43
store i8* %44, i8** %5
br label %48
45: ; preds = %18
%46 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45
store i8* null, i8** %5
br label %48
48: ; preds = %47, %35, %17
%49 = load i8*, i8** %5
ret i8* %49
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@str = [29 x i8] c"Serialization buffer overrun\00"
define i8* @newDbSerializeHelperStr(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %1, null
%6 = icmp eq i8* %2, null
%7 = or i1 %5, %6
br i1 %7, label %24, label %8
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %1)
%10 = tail call i32 @strlen(i8* %2)
%11 = add nsw i32 %10, %9
%12 = add nsw i32 %11, 1
%13 = icmp slt i32 %12, %0
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = icmp eq i32 %3, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = tail call i32 @strcat(i8* %1, i8* %2)
%20 = sext i32 %11 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
br label %24
22: ; preds = %8
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %18, %22, %4
%25 = phi i8* [ null, %4 ], [ %21, %18 ], [ null, %22 ]
ret i8* %25
}