#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*/ exit(int);
scalar_t__ inList(int, int *, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ realloc(int *, int);
int enqueueUnique(int element, int **arr, int *len) {
  if (*arr != NULL && inList(element, *arr, *len))
    return *len;
  (*len)++;
  {
    *arr = (int *)realloc((*arr), ((*len) * sizeof(int)));
    if (!(*arr)) {
      printf("\nError: realloc failed for %s.\n\n", ("arr"));
      exit(1);
    }
  };
  (*arr)[(*len) - 1] = element;
  return *len;
}


x86 assembly (clang, -O0):
<enqueueUnique>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     118e <enqueueUnique+0x4e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1030 <inList@plt>
cmp    $0x0,%rax
je     118e <enqueueUnique+0x4e>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1209 <enqueueUnique+0xc9>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11e7 <enqueueUnique+0xa7>
lea    0xe2f(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enqueueUnique>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r14d
mov    (%rsi),%rsi
test   %rsi,%rsi
je     116a <enqueueUnique+0x2a>
mov    (%rbx),%edx
mov    %r14d,%edi
call   1030 <inList@plt>
test   %rax,%rax
jne    1190 <enqueueUnique+0x50>
mov    0x0(%rbp),%rdi
jmp    116c <enqueueUnique+0x2c>
xor    %edi,%edi
mov    (%rbx),%eax
lea    0x1(%rax),%ecx
mov    %ecx,(%rbx)
lea    0x4(,%rax,4),%esi
call   1050 <realloc@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     1197 <enqueueUnique+0x57>
movslq (%rbx),%rcx
mov    %r14d,-0x4(%rax,%rcx,4)
mov    (%rbx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe62(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"\0AError: realloc failed for %s.\0A\0A\00"
@.str.1 = [4 x i8] c"arr\00"
define i32 @enqueueUnique(i32 %0, i32** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32*
store i32 %0, i32* %5
store i32** %1, i32*** %6
store i32* %2, i32** %7
%8 = load i32**, i32*** %6
%9 = load i32*, i32** %8
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32**, i32*** %6
%14 = load i32*, i32** %13
%15 = load i32*, i32** %7
%16 = load i32, i32* %15
%17 = call i64 @inList(i32 %12, i32* %14, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i32*, i32** %7
%21 = load i32, i32* %20
store i32 %21, i32* %4
br label %53
22: ; preds = %11, %3
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
store i32 %25, i32* %23
%26 = load i32**, i32*** %6
%27 = load i32*, i32** %26
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 4
%32 = trunc i64 %31 to i32
%33 = call i64 @realloc(i32* %27, i32 %32)
%34 = inttoptr i64 %33 to i32*
%35 = load i32**, i32*** %6
store i32* %34, i32** %35
%36 = load i32**, i32*** %6
%37 = load i32*, i32** %36
%38 = icmp ne i32* %37, null
br i1 %38, label %42, label %39
39: ; preds = %22
%40 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %22
%43 = load i32, i32* %5
%44 = load i32**, i32*** %6
%45 = load i32*, i32** %44
%46 = load i32*, i32** %7
%47 = load i32, i32* %46
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %45, i64 %49
store i32 %43, i32* %50
%51 = load i32*, i32** %7
%52 = load i32, i32* %51
store i32 %52, i32* %4
br label %53
53: ; preds = %42, %19
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [33 x i8] c"\0AError: realloc failed for %s.\0A\0A\00"
@.str.1 = [4 x i8] c"arr\00"
define i32 @enqueueUnique(i32 %0, i32** nocapture %1, i32* nocapture %2) {
%4 = load i32*, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = load i32, i32* %2
%8 = tail call i64 @inList(i32 %0, i32* %4, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = load i32*, i32** %1
br label %12
12: ; preds = %10, %3
%13 = phi i32* [ %11, %10 ], [ null, %3 ]
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
%16 = shl i32 %15, 2
%17 = tail call i64 @realloc(i32* %13, i32 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %1
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %12
%24 = load i32, i32* %2
%25 = add nsw i32 %24, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %18, i64 %26
store i32 %0, i32* %27
br label %28
28: ; preds = %6, %23
%29 = load i32, i32* %2
ret i32 %29
}