#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_intersection(struct stringset *,
                                               struct stringset const *);
int /*<<< orphan*/ stringset_free(struct stringset *);
int /*<<< orphan*/ swap(struct stringset *, struct stringset *);
int stringset_retain_stringset(struct stringset *stringset,
                               struct stringset const *other) {
  if (!stringset || !other) {
    errno = EINVAL;
    return -1;
  }
  struct stringset *intersection =
      stringset_alloc_intersection(stringset, other);
  if (!intersection)
    return -1;
  swap(stringset, intersection);
  stringset_free(intersection);
  return 0;
}


x86 assembly (clang, -O0):
<stringset_retain_stringset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <stringset_retain_stringset+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1174 <stringset_retain_stringset+0x44>
mov    0x2e7b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e7a(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <stringset_retain_stringset+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stringset_alloc_intersection@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119c <stringset_retain_stringset+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <stringset_retain_stringset+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <swap@plt>
mov    -0x20(%rbp),%rdi
call   1040 <stringset_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringset_retain_stringset>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1165 <stringset_retain_stringset+0x35>
test   %rsi,%rsi
je     1165 <stringset_retain_stringset+0x35>
mov    %rdi,%rbx
call   1030 <stringset_alloc_intersection@plt>
test   %rax,%rax
je     1177 <stringset_retain_stringset+0x47>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <swap@plt>
mov    %r14,%rdi
call   1040 <stringset_free@plt>
xor    %eax,%eax
jmp    117c <stringset_retain_stringset+0x4c>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    0x2e6b(%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_stringset(%struct.stringset* %0, %struct.stringset* %1) {
%3 = alloca i32
%4 = alloca %struct.stringset*
%5 = alloca %struct.stringset*
%6 = alloca %struct.stringset*
store %struct.stringset* %0, %struct.stringset** %4
store %struct.stringset* %1, %struct.stringset** %5
%7 = load %struct.stringset*, %struct.stringset** %4
%8 = icmp ne %struct.stringset* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load %struct.stringset*, %struct.stringset** %5
%11 = icmp ne %struct.stringset* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9, %2
%13 = load i32, i32* @EINVAL
store i32 %13, i32* @errno
store i32 -1, i32* %3
br label %27
14: ; preds = %9
%15 = load %struct.stringset*, %struct.stringset** %4
%16 = load %struct.stringset*, %struct.stringset** %5
%17 = call %struct.stringset* @stringset_alloc_intersection(%struct.stringset* %15, %struct.stringset* %16)
store %struct.stringset* %17, %struct.stringset** %6
%18 = load %struct.stringset*, %struct.stringset** %6
%19 = icmp ne %struct.stringset* %18, null
br i1 %19, label %21, label %20
20: ; preds = %14
store i32 -1, i32* %3
br label %27
21: ; preds = %14
%22 = load %struct.stringset*, %struct.stringset** %4
%23 = load %struct.stringset*, %struct.stringset** %6
%24 = call i32 @swap(%struct.stringset* %22, %struct.stringset* %23)
%25 = load %struct.stringset*, %struct.stringset** %6
%26 = call i32 @stringset_free(%struct.stringset* %25)
store i32 0, i32* %3
br label %27
27: ; preds = %21, %20, %12
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.stringset = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @stringset_retain_stringset(%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 %14
8: ; preds = %2
%9 = tail call %struct.stringset* @stringset_alloc_intersection(%struct.stringset* %0, %struct.stringset* %1)
%10 = icmp eq %struct.stringset* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @swap(%struct.stringset* %0, %struct.stringset* %9)
%13 = tail call i32 @stringset_free(%struct.stringset* %9)
br label %14
14: ; preds = %11, %8, %6
%15 = phi i32 [ -1, %6 ], [ 0, %11 ], [ -1, %8 ]
ret i32 %15
}