#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 */

/* Variables and functions */
int /*<<< orphan*/ complement(int *, int, int *, int, int, int *, int *);
int /*<<< orphan*/ copy_list(int *, int *, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ intersection(int *, int, int *, int, int *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sort(int *, int *, int);
void sortB(int *list, int *slist, int l, int *B, int Bl) {
  int sl;
  int *tmp = (int *)malloc(l * sizeof(int)), tmpl;
  int *stmp = (int *)malloc(l * sizeof(int));
  intersection(B, Bl, list, l, slist, &sl);
  complement(list, l, B, Bl, 1, tmp, &tmpl);
  if (tmpl + sl != l)
    printf("Error in sortB\n");
  sort(tmp, stmp, tmpl);
  copy_list(stmp, slist + sl, tmpl);
  free(tmp);
  free(stmp);
}


x86 assembly (clang, -O0):
<sortB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%r8
lea    -0x28(%rbp),%r9
call   1080 <intersection@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r9
mov    $0x1,%r8d
lea    -0x34(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <complement@plt>
mov    -0x34(%rbp),%eax
add    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     120c <sortB+0x9c>
lea    0xdf9(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1060 <sort@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x34(%rbp),%edx
call   1090 <copy_list@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortB>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r13d
mov    %rcx,%r15
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x0(,%rbx,4),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,0x18(%rsp)
lea    0xc(%rsp),%r9
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
mov    %r12,0x20(%rsp)
mov    %r12,%r8
call   1080 <intersection@plt>
lea    0x8(%rsp),%rax
mov    %rax,(%rsp)
mov    %r14,%rdi
mov    0x10(%rsp),%rbp
mov    %ebx,%esi
mov    %r15,%rdx
mov    %r13d,%ecx
mov    $0x1,%r8d
mov    %rbp,%r9
call   1050 <complement@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%eax
add    %edx,%eax
cmp    %ebx,%eax
je     120d <sortB+0x9d>
lea    0xdfc(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edx
mov    %rbp,%rdi
mov    0x18(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <sort@plt>
movslq 0xc(%rsp),%rax
mov    0x20(%rsp),%rcx
lea    (%rcx,%rax,4),%rsi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
call   1090 <copy_list@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Error in sortB\0A\00"
define void @sortB(i32* %0, i32* %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %12
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i32*
store i32* %26, i32** %14
%27 = load i32*, i32** %9
%28 = load i32, i32* %10
%29 = load i32*, i32** %6
%30 = load i32, i32* %8
%31 = load i32*, i32** %7
%32 = call i32 @intersection(i32* %27, i32 %28, i32* %29, i32 %30, i32* %31, i32* %11)
%33 = load i32*, i32** %6
%34 = load i32, i32* %8
%35 = load i32*, i32** %9
%36 = load i32, i32* %10
%37 = load i32*, i32** %12
%38 = call i32 @complement(i32* %33, i32 %34, i32* %35, i32 %36, i32 1, i32* %37, i32* %13)
%39 = load i32, i32* %13
%40 = load i32, i32* %11
%41 = add nsw i32 %39, %40
%42 = load i32, i32* %8
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %5
%45 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %44, %5
%47 = load i32*, i32** %12
%48 = load i32*, i32** %14
%49 = load i32, i32* %13
%50 = call i32 @sort(i32* %47, i32* %48, i32 %49)
%51 = load i32*, i32** %14
%52 = load i32*, i32** %7
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %13
%57 = call i32 @copy_list(i32* %51, i32* %55, i32 %56)
%58 = load i32*, i32** %12
%59 = call i32 @free(i32* %58)
%60 = load i32*, i32** %14
%61 = call i32 @free(i32* %60)
ret void
}

LLVM IR (-O2):
@str = [15 x i8] c"Error in sortB\00"
define void @sortB(i32* %0, i32* %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %6 to i8*
%9 = shl i32 %2, 2
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i32*
%12 = bitcast i32* %7 to i8*
%13 = tail call i64 @malloc(i32 %9)
%14 = inttoptr i64 %13 to i32*
%15 = call i32 @intersection(i32* %3, i32 %4, i32* %0, i32 %2, i32* %1, i32* %6)
%16 = call i32 @complement(i32* %0, i32 %2, i32* %3, i32 %4, i32 1, i32* %11, i32* %7)
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = add nsw i32 %18, %17
%20 = icmp eq i32 %19, %2
br i1 %20, label %24, label %21
21: ; preds = %5
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%23 = load i32, i32* %7
br label %24
24: ; preds = %21, %5
%25 = phi i32 [ %23, %21 ], [ %17, %5 ]
%26 = call i32 @sort(i32* %11, i32* %14, i32 %25)
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %1, i64 %28
%30 = load i32, i32* %7
%31 = call i32 @copy_list(i32* %14, i32* %29, i32 %30)
%32 = call i32 @free(i32* %11)
%33 = call i32 @free(i32* %14)
ret void
}