#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;
int stringset_add_array(struct stringset *, char const *const *, int);
struct stringset *stringset_alloc();
int /*<<< orphan*/ stringset_free(struct stringset *);
struct stringset *stringset_alloc_from_array(char const *const *array,
                                             int count) {
  if (!array || count < 0) {
    errno = EINVAL;
    return NULL;
  }
  struct stringset *stringset = stringset_alloc();
  if (!stringset)
    return NULL;
  int result = stringset_add_array(stringset, array, count);
  if (-1 == result) {
    stringset_free(stringset);
    return NULL;
  }
  return stringset;
}


x86 assembly (clang, -O0):
<stringset_alloc_from_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1154 <stringset_alloc_from_array+0x24>
cmpl   $0x0,-0x14(%rbp)
jge    1173 <stringset_alloc_from_array+0x43>
mov    0x2e7d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7c(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11d5 <stringset_alloc_from_array+0xa5>
mov    $0x0,%al
call   1030 <stringset_alloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1196 <stringset_alloc_from_array+0x66>
movq   $0x0,-0x8(%rbp)
jmp    11d5 <stringset_alloc_from_array+0xa5>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <stringset_add_array@plt>
mov    %eax,-0x24(%rbp)
mov    $0xffffffff,%eax
cmp    -0x24(%rbp),%eax
jne    11cd <stringset_alloc_from_array+0x9d>
mov    -0x20(%rbp),%rdi
call   1040 <stringset_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d5 <stringset_alloc_from_array+0xa5>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringset_alloc_from_array>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     116f <stringset_alloc_from_array+0x3f>
mov    %esi,%r14d
test   %esi,%esi
js     116f <stringset_alloc_from_array+0x3f>
mov    %rdi,%rbp
xor    %eax,%eax
call   1030 <stringset_alloc@plt>
test   %rax,%rax
je     1181 <stringset_alloc_from_array+0x51>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1050 <stringset_add_array@plt>
cmp    $0xffffffff,%eax
jne    1183 <stringset_alloc_from_array+0x53>
mov    %rbx,%rdi
call   1040 <stringset_free@plt>
jmp    1181 <stringset_alloc_from_array+0x51>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    0x2e61(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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