#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 */
typedef int /*<<< orphan*/ set_b;
typedef int /*<<< orphan*/ set_a;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, unsigned int);
unsigned int set_intersection(unsigned int *, unsigned int *, unsigned int *,
                              unsigned int *);
int test_set_intersection() {
  unsigned int set_a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  unsigned int *set_a_end = set_a + sizeof(set_a) / sizeof(set_a[0]);
  unsigned int set_b[] = {5, 6, 7, 8, 9, 10, 11, 12};
  unsigned int *set_b_end = set_b + sizeof(set_b) / sizeof(set_b[0]);
  unsigned int members_in_common =
      set_intersection(set_a, set_a_end, set_b, set_b_end);
  if (members_in_common != 6) {
    printf("Got %i instead of 6\n", members_in_common);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_set_intersection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x30(%rbp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    -0x30(%rbp),%rax
add    $0x28,%rax
mov    %rax,-0x38(%rbp)
mov    0xed0(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x60(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x68(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x60(%rbp),%rdx
mov    -0x68(%rbp),%rcx
call   1040 <set_intersection@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0x6,-0x6c(%rbp)
je     11ce <test_set_intersection+0x9e>
mov    -0x6c(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <test_set_intersection+0xa5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_set_intersection>:
sub    $0x48,%rsp
mov    0xef5(%rip),%rax
mov    %rax,0x40(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x48(%rsp),%rsi
movaps 0xeec(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xed0(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%rcx
lea    0x20(%rsp),%rdi
mov    %rsp,%rdx
call   1040 <set_intersection@plt>
xor    %ecx,%ecx
cmp    $0x6,%eax
je     1190 <test_set_intersection+0x70>
lea    0xecc(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@__const.test_set_intersection.set_a = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@__const.test_set_intersection.set_b = [8 x i32] [i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12]
@.str = [21 x i8] c"Got %i instead of 6\0A\00"
define i32 @test_set_intersection() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32*
%4 = alloca [8 x i32]
%5 = alloca i32*
%6 = alloca i32
%7 = bitcast [10 x i32]* %2 to i8*
%8 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%9 = getelementptr inbounds i32, i32* %8, i64 10
store i32* %9, i32** %3
%10 = bitcast [8 x i32]* %4 to i8*
%11 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%12 = getelementptr inbounds i32, i32* %11, i64 8
store i32* %12, i32** %5
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32 @set_intersection(i32* %13, i32* %14, i32* %15, i32* %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 6
br i1 %19, label %20, label %23
20: ; preds = %0
%21 = load i32, i32* %6
%22 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 -1, i32* %1
br label %24
23: ; preds = %0
store i32 0, i32* %1
br label %24
24: ; preds = %23, %20
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@__const.test_set_intersection.set_a = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10]
@__const.test_set_intersection.set_b = [8 x i32] [i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12]
@.str = [21 x i8] c"Got %i instead of 6\0A\00"
define i32 @test_set_intersection() {
%1 = alloca [10 x i32]
%2 = alloca [8 x i32]
%3 = bitcast [10 x i32]* %1 to i8*
%4 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 10
%6 = bitcast [8 x i32]* %2 to i8*
%7 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 0
%8 = getelementptr inbounds [8 x i32], [8 x i32]* %2, i64 0, i64 8
%9 = call i32 @set_intersection(i32* %4, i32* %5, i32* %7, i32* %8)
%10 = icmp eq i32 %9, 6
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %13
13: ; preds = %0, %11
%14 = phi i32 [ -1, %11 ], [ 0, %0 ]
ret i32 %14
}