#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_stringset(struct stringset *, struct stringset const *);
struct stringset *stringset_alloc();
int /*<<< orphan*/ stringset_free(struct stringset *);
struct stringset *stringset_alloc_union(struct stringset const *first,
                                        struct stringset const *second) {
  if (!first || !second) {
    errno = EINVAL;
    return NULL;
  }
  struct stringset *stringset = stringset_alloc();
  if (!stringset)
    return NULL;
  int result = stringset_add_stringset(stringset, first);
  if (-1 == result) {
    stringset_free(stringset);
    return NULL;
  }
  result = stringset_add_stringset(stringset, second);
  if (-1 == result) {
    stringset_free(stringset);
    return NULL;
  }
  return stringset;
}


x86 assembly (clang, -O0):
<stringset_alloc_union>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <stringset_alloc_union+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1175 <stringset_alloc_union+0x45>
mov    0x2e7b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7a(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1208 <stringset_alloc_union+0xd8>
mov    $0x0,%al
call   1030 <stringset_alloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1198 <stringset_alloc_union+0x68>
movq   $0x0,-0x8(%rbp)
jmp    1208 <stringset_alloc_union+0xd8>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <stringset_add_stringset@plt>
mov    %eax,-0x24(%rbp)
mov    $0xffffffff,%eax
cmp    -0x24(%rbp),%eax
jne    11cc <stringset_alloc_union+0x9c>
mov    -0x20(%rbp),%rdi
call   1040 <stringset_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1208 <stringset_alloc_union+0xd8>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <stringset_add_stringset@plt>
mov    %eax,-0x24(%rbp)
mov    $0xffffffff,%eax
cmp    -0x24(%rbp),%eax
jne    1200 <stringset_alloc_union+0xd0>
mov    -0x20(%rbp),%rdi
call   1040 <stringset_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1208 <stringset_alloc_union+0xd8>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringset_alloc_union>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     117e <stringset_alloc_union+0x4e>
mov    %rsi,%r14
test   %rsi,%rsi
je     117e <stringset_alloc_union+0x4e>
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <stringset_alloc@plt>
test   %rax,%rax
je     1190 <stringset_alloc_union+0x60>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <stringset_add_stringset@plt>
cmp    $0xffffffff,%eax
je     1174 <stringset_alloc_union+0x44>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <stringset_add_stringset@plt>
cmp    $0xffffffff,%eax
jne    1192 <stringset_alloc_union+0x62>
mov    %rbx,%rdi
call   1040 <stringset_free@plt>
jmp    1190 <stringset_alloc_union+0x60>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    0x2e52(%rip),%rcx
mov    %eax,(%rcx)
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stringset = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define %struct.stringset* @stringset_alloc_union(%struct.stringset* %0, %struct.stringset* %1) {
%3 = alloca %struct.stringset*
%4 = alloca %struct.stringset*
%5 = alloca %struct.stringset*
%6 = alloca %struct.stringset*
%7 = alloca i32
store %struct.stringset* %0, %struct.stringset** %4
store %struct.stringset* %1, %struct.stringset** %5
%8 = load %struct.stringset*, %struct.stringset** %4
%9 = icmp ne %struct.stringset* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load %struct.stringset*, %struct.stringset** %5
%12 = icmp ne %struct.stringset* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10, %2
%14 = load i32, i32* @EINVAL
store i32 %14, i32* @errno
store %struct.stringset* null, %struct.stringset** %3
br label %40
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 %40
20: ; preds = %15
%21 = load %struct.stringset*, %struct.stringset** %6
%22 = load %struct.stringset*, %struct.stringset** %4
%23 = call i32 @stringset_add_stringset(%struct.stringset* %21, %struct.stringset* %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp eq i32 -1, %24
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load %struct.stringset*, %struct.stringset** %6
%28 = call i32 @stringset_free(%struct.stringset* %27)
store %struct.stringset* null, %struct.stringset** %3
br label %40
29: ; preds = %20
%30 = load %struct.stringset*, %struct.stringset** %6
%31 = load %struct.stringset*, %struct.stringset** %5
%32 = call i32 @stringset_add_stringset(%struct.stringset* %30, %struct.stringset* %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 -1, %33
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load %struct.stringset*, %struct.stringset** %6
%37 = call i32 @stringset_free(%struct.stringset* %36)
store %struct.stringset* null, %struct.stringset** %3
br label %40
38: ; preds = %29
%39 = load %struct.stringset*, %struct.stringset** %6
store %struct.stringset* %39, %struct.stringset** %3
br label %40
40: ; preds = %38, %35, %26, %19, %13
%41 = load %struct.stringset*, %struct.stringset** %3
ret %struct.stringset* %41
}

LLVM IR (-O2):
%struct.stringset = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define %struct.stringset* @stringset_alloc_union(%struct.stringset* %0, %struct.stringset* %1) {
%3 = icmp ne %struct.stringset* %0, null
%4 = icmp ne %struct.stringset* %1, null
%5 = and i1 %3, %4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = load i32, i32* @EINVAL
store i32 %7, i32* @errno
br label %21
8: ; preds = %2
%9 = tail call %struct.stringset* (...) @stringset_alloc()
%10 = icmp eq %struct.stringset* %9, null
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = tail call i32 @stringset_add_stringset(%struct.stringset* %9, %struct.stringset* %0)
%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 %21
16: ; preds = %11
%17 = tail call i32 @stringset_add_stringset(%struct.stringset* %9, %struct.stringset* %1)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @stringset_free(%struct.stringset* %9)
br label %21
21: ; preds = %8, %16, %19, %14, %6
%22 = phi %struct.stringset* [ null, %6 ], [ null, %8 ], [ null, %14 ], [ null, %19 ], [ %9, %16 ]
ret %struct.stringset* %22
}