#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 EntityAddEntity(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 EntityAddEntityStringArray(struct Entitydata *ptr, char **str) {
  struct XMLDBbuffer *tmp = NULL;
  int s = 0, n = 0;
  for (n = 0; str[n] != NULL; n++) {
    tmp = XMLDBMakeBuffer(100);
    if (tmp == NULL)
      return -1;
    s = XMLDBAddBuffer(tmp, str[n], strlen(str[n]));
    if (s == 0)
      s = EntityAddEntity(ptr, tmp);
    XMLDBFreeBuffer(tmp);
    if (s != 0)
      break;
  }
  return s;
}


x86 assembly (clang, -O0):
<EntityAddEntityStringArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1235 <EntityAddEntityStringArray+0xe5>
mov    $0x64,%edi
call   1030 <XMLDBMakeBuffer@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <EntityAddEntityStringArray+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <EntityAddEntityStringArray+0xeb>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%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    120a <EntityAddEntityStringArray+0xba>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <EntityAddEntity@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <XMLDBFreeBuffer@plt>
cmpl   $0x0,-0x24(%rbp)
je     1222 <EntityAddEntityStringArray+0xd2>
jmp    1235 <EntityAddEntityStringArray+0xe5>
jmp    1227 <EntityAddEntityStringArray+0xd7>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117d <EntityAddEntityStringArray+0x2d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EntityAddEntityStringArray>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r14d,%r14d
cmpq   $0x0,(%rsi)
je     11dc <EntityAddEntityStringArray+0x8c>
mov    %rsi,%r12
mov    %rdi,%r15
add    $0x8,%r12
nopl   0x0(%rax,%rax,1)
mov    $0x64,%edi
call   1030 <XMLDBMakeBuffer@plt>
test   %rax,%rax
je     11c7 <EntityAddEntityStringArray+0x77>
mov    %rax,%rbp
mov    -0x8(%r12),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <XMLDBAddBuffer@plt>
test   %eax,%eax
jne    11cf <EntityAddEntityStringArray+0x7f>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <EntityAddEntity@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1070 <XMLDBFreeBuffer@plt>
test   %ebx,%ebx
jne    11d9 <EntityAddEntityStringArray+0x89>
cmpq   $0x0,(%r12)
lea    0x8(%r12),%r12
jne    1170 <EntityAddEntityStringArray+0x20>
jmp    11dc <EntityAddEntityStringArray+0x8c>
mov    $0xffffffff,%r14d
jmp    11dc <EntityAddEntityStringArray+0x8c>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1070 <XMLDBFreeBuffer@plt>
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Entitydata = type { i32 }
%struct.XMLDBbuffer = type { i32 }
define i32 @EntityAddEntityStringArray(%struct.Entitydata* %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.Entitydata*
%5 = alloca i8**
%6 = alloca %struct.XMLDBbuffer*
%7 = alloca i32
%8 = 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
store i32 0, i32* %8
store i32 0, i32* %8
br label %9
9: ; preds = %48, %2
%10 = load i8**, i8*** %5
%11 = load i32, i32* %8
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %51
16: ; preds = %9
%17 = call %struct.XMLDBbuffer* @XMLDBMakeBuffer(i32 100)
store %struct.XMLDBbuffer* %17, %struct.XMLDBbuffer** %6
%18 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%19 = icmp eq %struct.XMLDBbuffer* %18, null
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 -1, i32* %3
br label %53
21: ; preds = %16
%22 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%23 = load i8**, i8*** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @XMLDBAddBuffer(%struct.XMLDBbuffer* %22, i8* %27, i32 %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %21
%38 = load %struct.Entitydata*, %struct.Entitydata** %4
%39 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%40 = call i32 @EntityAddEntity(%struct.Entitydata* %38, %struct.XMLDBbuffer* %39)
store i32 %40, i32* %7
br label %41
41: ; preds = %37, %21
%42 = load %struct.XMLDBbuffer*, %struct.XMLDBbuffer** %6
%43 = call i32 @XMLDBFreeBuffer(%struct.XMLDBbuffer* %42)
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
br label %51
47: ; preds = %41
br label %48
48: ; preds = %47
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %9
51: ; preds = %46, %9
%52 = load i32, i32* %7
store i32 %52, i32* %3
br label %53
53: ; preds = %51, %20
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.Entitydata = type { i32 }
%struct.XMLDBbuffer = type { i32 }
define i32 @EntityAddEntityStringArray(%struct.Entitydata* %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %26, label %9
5: ; preds = %21
%6 = getelementptr inbounds i8*, i8** %1, i64 %25
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %26, label %9
9: ; preds = %2, %5
%10 = phi i64 [ %25, %5 ], [ 0, %2 ]
%11 = phi i8** [ %6, %5 ], [ %1, %2 ]
%12 = tail call %struct.XMLDBbuffer* @XMLDBMakeBuffer(i32 100)
%13 = icmp eq %struct.XMLDBbuffer* %12, null
br i1 %13, label %26, label %14
14: ; preds = %9
%15 = load i8*, i8** %11
%16 = tail call i32 @strlen(i8* %15)
%17 = tail call i32 @XMLDBAddBuffer(%struct.XMLDBbuffer* %12, i8* %15, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = tail call i32 @XMLDBFreeBuffer(%struct.XMLDBbuffer* %12)
br label %26
21: ; preds = %14
%22 = tail call i32 @EntityAddEntity(%struct.Entitydata* %0, %struct.XMLDBbuffer* %12)
%23 = tail call i32 @XMLDBFreeBuffer(%struct.XMLDBbuffer* %12)
%24 = icmp eq i32 %22, 0
%25 = add nuw i64 %10, 1
br i1 %24, label %5, label %26
26: ; preds = %9, %21, %5, %2, %19
%27 = phi i32 [ %17, %19 ], [ 0, %2 ], [ -1, %9 ], [ %22, %21 ], [ 0, %5 ]
ret i32 %27
}