#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 */
struct XMLDBbuffer {
  int dummy;
};
struct Entitydata {
  int dummy;
};

/* Variables and functions */
int EntityAddSymbol(struct Entitydata *, struct XMLDBbuffer *);
int XMLDBAddBuffer(struct XMLDBbuffer *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ XMLDBFreeBuffer(struct XMLDBbuffer *);
struct XMLDBbuffer *XMLDBMakeBuffer(int);
int /*<<< orphan*/ strlen(char *);
int EntityAddSymbolString(struct Entitydata *ptr, char *str) {
  struct XMLDBbuffer *tmp = NULL;
  int s = 0;
  if (str != NULL) {
    tmp = XMLDBMakeBuffer(100);
    if (tmp == NULL)
      return -1;
    s = XMLDBAddBuffer(tmp, str, strlen(str));
  }
  if (s == 0)
    s = EntityAddSymbol(ptr, tmp);
  if (tmp != NULL)
    XMLDBFreeBuffer(tmp);
  return s;
}


x86 assembly (clang, -O0):
<EntityAddSymbolString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ca <EntityAddSymbolString+0x7a>
mov    $0x64,%edi
call   1040 <XMLDBMakeBuffer@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119f <EntityAddSymbolString+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <EntityAddSymbolString+0xae>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1060 <XMLDBAddBuffer@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11e4 <EntityAddSymbolString+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <EntityAddSymbol@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f8 <EntityAddSymbolString+0xa8>
mov    -0x20(%rbp),%rdi
call   1070 <XMLDBFreeBuffer@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EntityAddSymbolString>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     11a4 <EntityAddSymbolString+0x54>
mov    %rsi,%rbx
mov    $0x64,%edi
call   1040 <XMLDBMakeBuffer@plt>
test   %rax,%rax
je     11b3 <EntityAddSymbolString+0x63>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <XMLDBAddBuffer@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    119a <EntityAddSymbolString+0x4a>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <EntityAddSymbol@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1070 <XMLDBFreeBuffer@plt>
jmp    11b8 <EntityAddSymbolString+0x68>
mov    %r14,%rdi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <EntityAddSymbol@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Entitydata = type { i32 }
%struct.XMLDBbuffer = type { i32 }
define i32 @EntityAddSymbolString(%struct.Entitydata* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.Entitydata*
%5 = alloca i8*
%6 = alloca %struct.XMLDBbuffer*
%7 = alloca i32
store %struct.Entitydata* %0, %struct.Entitydata** %4
store i8* %1, i8** %5
store %struct.XMLDBbuffer* null, %struct.XMLDBbuffer** %6
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = call %struct.XMLDBbuffer* @XMLDBMakeBuffer(i32 100)
store %struct.XMLDBbuffer* %11, %struct.XMLDBbuffer** %6
%12 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%13 = icmp eq %struct.XMLDBbuffer* %12, null
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 -1, i32* %3
br label %36
15: ; preds = %10
%16 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%17 = load i8*, i8** %5
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @XMLDBAddBuffer(%struct.XMLDBbuffer* %16, i8* %17, i32 %19)
store i32 %20, i32* %7
br label %21
21: ; preds = %15, %2
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load %struct.Entitydata*, %struct.Entitydata** %4
%26 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%27 = call i32 @EntityAddSymbol(%struct.Entitydata* %25, %struct.XMLDBbuffer* %26)
store i32 %27, i32* %7
br label %28
28: ; preds = %24, %21
%29 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%30 = icmp ne %struct.XMLDBbuffer* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%33 = call i32 @XMLDBFreeBuffer(%struct.XMLDBbuffer* %32)
br label %34
34: ; preds = %31, %28
%35 = load i32, i32* %7
store i32 %35, i32* %3
br label %36
36: ; preds = %34, %14
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.Entitydata = type { i32 }
%struct.XMLDBbuffer = type { i32 }
define i32 @EntityAddSymbolString(%struct.Entitydata* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @EntityAddSymbol(%struct.Entitydata* %0, %struct.XMLDBbuffer* null)
br label %18
6: ; preds = %2
%7 = tail call %struct.XMLDBbuffer* @XMLDBMakeBuffer(i32 100)
%8 = icmp eq %struct.XMLDBbuffer* %7, null
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i32 @XMLDBAddBuffer(%struct.XMLDBbuffer* %7, i8* %1, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @EntityAddSymbol(%struct.Entitydata* %0, %struct.XMLDBbuffer* %7)
br label %15
15: ; preds = %9, %13
%16 = phi i32 [ %14, %13 ], [ %11, %9 ]
%17 = tail call i32 @XMLDBFreeBuffer(%struct.XMLDBbuffer* %7)
br label %18
18: ; preds = %4, %15, %6
%19 = phi i32 [ -1, %6 ], [ %16, %15 ], [ %5, %4 ]
ret i32 %19
}