#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 stringset {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
struct stringset *stringset_alloc_from_array(char const *const *, int);
int /*<<< orphan*/ stringset_free(struct stringset *);
int stringset_retain_stringset(struct stringset *, struct stringset *);
int stringset_retain_array(struct stringset *stringset,
                           char const *const *array, int count) {
  if (!stringset || !array || count < 0) {
    errno = EINVAL;
    return -1;
  }
  struct stringset *other = stringset_alloc_from_array(array, count);
  if (!other)
    return -1;
  int result = stringset_retain_stringset(stringset, other);
  stringset_free(other);
  return result;
}


x86 assembly (clang, -O0):
<stringset_retain_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1163 <stringset_retain_array+0x33>
cmpq   $0x0,-0x18(%rbp)
je     1163 <stringset_retain_array+0x33>
cmpl   $0x0,-0x1c(%rbp)
jge    1181 <stringset_retain_array+0x51>
mov    0x2e6e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6d(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <stringset_retain_array+0x97>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <stringset_alloc_from_array@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a8 <stringset_retain_array+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <stringset_retain_array+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <stringset_retain_stringset@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <stringset_free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringset_retain_array>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1170 <stringset_retain_array+0x40>
test   %rsi,%rsi
je     1170 <stringset_retain_array+0x40>
test   %edx,%edx
js     1170 <stringset_retain_array+0x40>
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    %edx,%esi
call   1050 <stringset_alloc_from_array@plt>
test   %rax,%rax
je     1182 <stringset_retain_array+0x52>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <stringset_retain_stringset@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <stringset_free@plt>
mov    %ebx,%eax
jmp    1187 <stringset_retain_array+0x57>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    0x2e60(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stringset = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @stringset_retain_array(%struct.stringset* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.stringset*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca %struct.stringset*
%9 = alloca i32
store %struct.stringset* %0, %struct.stringset** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%10 = load %struct.stringset*, %struct.stringset** %5
%11 = icmp ne %struct.stringset* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8**, i8*** %6
%14 = icmp ne i8** %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15, %12, %3
%19 = load i32, i32* @EINVAL
store i32 %19, i32* @errno
store i32 -1, i32* %4
br label %34
20: ; preds = %15
%21 = load i8**, i8*** %6
%22 = load i32, i32* %7
%23 = call %struct.stringset* @stringset_alloc_from_array(i8** %21, i32 %22)
store %struct.stringset* %23, %struct.stringset** %8
%24 = load %struct.stringset*, %struct.stringset** %8
%25 = icmp ne %struct.stringset* %24, null
br i1 %25, label %27, label %26
26: ; preds = %20
store i32 -1, i32* %4
br label %34
27: ; preds = %20
%28 = load %struct.stringset*, %struct.stringset** %5
%29 = load %struct.stringset*, %struct.stringset** %8
%30 = call i32 @stringset_retain_stringset(%struct.stringset* %28, %struct.stringset* %29)
store i32 %30, i32* %9
%31 = load %struct.stringset*, %struct.stringset** %8
%32 = call i32 @stringset_free(%struct.stringset* %31)
%33 = load i32, i32* %9
store i32 %33, i32* %4
br label %34
34: ; preds = %27, %26, %18
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
%struct.stringset = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @stringset_retain_array(%struct.stringset* %0, i8** %1, i32 %2) {
%4 = icmp eq %struct.stringset* %0, null
%5 = icmp eq i8** %1, null
%6 = or i1 %4, %5
%7 = icmp slt i32 %2, 0
%8 = or i1 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
br label %17
11: ; preds = %3
%12 = tail call %struct.stringset* @stringset_alloc_from_array(i8** %1, i32 %2)
%13 = icmp eq %struct.stringset* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @stringset_retain_stringset(%struct.stringset* %0, %struct.stringset* %12)
%16 = tail call i32 @stringset_free(%struct.stringset* %12)
br label %17
17: ; preds = %14, %11, %9
%18 = phi i32 [ -1, %9 ], [ %15, %14 ], [ -1, %11 ]
ret i32 %18
}