#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*/ bucket_sort(int *, int);
int findMissingPositive(int a[], int n) {
  bucket_sort(a, n);
  for (int i = 0; i < n; i++) {
    if (a[i] != i + 1)
      return i + 1;
  }
  return n + 1;
}


x86 assembly (clang, -O0):
<findMissingPositive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <bucket_sort@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1178 <findMissingPositive+0x68>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1165 <findMissingPositive+0x55>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <findMissingPositive+0x71>
jmp    116a <findMissingPositive+0x5a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1132 <findMissingPositive+0x22>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findMissingPositive>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <bucket_sort@plt>
xor    %eax,%eax
test   %ebp,%ebp
mov    $0x0,%edx
cmovg  %ebp,%edx
nopl   0x0(%rax)
mov    %rax,%rcx
cmp    %rcx,%rdx
je     1144 <findMissingPositive+0x34>
mov    (%rbx,%rcx,4),%esi
lea    0x1(%rcx),%rax
cmp    %rsi,%rax
je     1130 <findMissingPositive+0x20>
movslq %ebp,%rdx
add    $0x1,%ebp
cmp    %rdx,%rcx
cmovl  %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findMissingPositive(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %5
%9 = call i32 @bucket_sort(i32* %7, i32 %8)
store i32 0, i32* %6
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %26
23: ; preds = %14
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %33
26: ; preds = %14
br label %27
27: ; preds = %26
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %10
30: ; preds = %10
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %33
33: ; preds = %30, %23
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @findMissingPositive(i32* %0, i32 %1) {
%3 = tail call i32 @bucket_sort(i32* %0, i32 %1)
%4 = call i32 @llvm.smax.i32(i32 %1, i32 0)
%5 = zext i32 %4 to i64
br label %6
6: ; preds = %9, %2
%7 = phi i64 [ %12, %9 ], [ 0, %2 ]
%8 = icmp eq i64 %7, %5
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = getelementptr inbounds i32, i32* %0, i64 %7
%11 = load i32, i32* %10
%12 = add nuw nsw i64 %7, 1
%13 = zext i32 %11 to i64
%14 = icmp eq i64 %12, %13
br i1 %14, label %6, label %15
15: ; preds = %9
%16 = trunc i64 %12 to i32
br label %17
17: ; preds = %6, %15
%18 = phi i32 [ %16, %15 ], [ undef, %6 ]
%19 = sext i32 %1 to i64
%20 = icmp slt i64 %7, %19
%21 = add nsw i32 %1, 1
%22 = select i1 %20, i32 %18, i32 %21
ret i32 %22
}