#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);
int firstMissingPositive(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int n1[] = {-1, -3};
  int n2[] = {1, 2, 3};
  int n3[] = {0, 2, 1, 3};
  for (int i = 0; i < 3; ++i) {
    printf("n2[%d] = %d\n", i, n2[i]);
  }
  if (!(firstMissingPositive(n1, 2) == 1)) {
    printf("assert fail: %s\n", "all negative");
    exit(-1);
  };
  for (int i = 0; i < 3; ++i) {
    printf("n2[%d] = %d\n", i, n2[i]);
  }
  if (!(firstMissingPositive(n2, 3) == 4)) {
    printf("assert fail: %s\n", "1 2 3");
    exit(-1);
  };
  if (!(firstMissingPositive(n1, 0) == 1)) {
    printf("assert fail: %s\n", "zero element");
    exit(-1);
  };
  if (!(firstMissingPositive(n3, 4) == 4)) {
    printf("assert fail: %s\n", "out of order");
    exit(-1);
  };
  printf("everything is fine!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x24(%rbp)
mov    0xeae(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeb1(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x3,-0x44(%rbp)
jge    11b3 <main+0x83>
mov    -0x44(%rbp),%esi
movslq -0x44(%rbp),%rax
mov    -0x24(%rbp,%rax,4),%edx
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1182 <main+0x52>
lea    -0x18(%rbp),%rdi
mov    $0x2,%esi
call   1040 <firstMissingPositive@plt>
cmp    $0x1,%eax
je     11e9 <main+0xb9>
lea    0xe6c(%rip),%rdi
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
movl   $0x0,-0x48(%rbp)
cmpl   $0x3,-0x48(%rbp)
jge    1221 <main+0xf1>
mov    -0x48(%rbp),%esi
movslq -0x48(%rbp),%rax
mov    -0x24(%rbp,%rax,4),%edx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11f0 <main+0xc0>
lea    -0x24(%rbp),%rdi
mov    $0x3,%esi
call   1040 <firstMissingPositive@plt>
cmp    $0x4,%eax
je     1257 <main+0x127>
lea    0xdfe(%rip),%rdi
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <firstMissingPositive@plt>
cmp    $0x1,%eax
je     128a <main+0x15a>
lea    0xdcb(%rip),%rdi
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    $0x4,%esi
call   1040 <firstMissingPositive@plt>
cmp    $0x4,%eax
je     12c0 <main+0x190>
lea    0xd95(%rip),%rdi
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movabs $0xfffffffdffffffff,%rax
ff ff ff
mov    %rax,0x8(%rsp)
mov    0xeae(%rip),%eax
mov    %eax,0x18(%rsp)
mov    0xe9b(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xea3(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
mov    $0x2,%esi
call   1050 <firstMissingPositive@plt>
cmp    $0x1,%eax
jne    125b <main+0x11b>
lea    0xe4b(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x3,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x3,%esi
call   1050 <firstMissingPositive@plt>
cmp    $0x4,%eax
jne    126b <main+0x12b>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <firstMissingPositive@plt>
cmp    $0x1,%eax
jne    127b <main+0x13b>
lea    0x20(%rsp),%rdi
mov    $0x4,%esi
call   1050 <firstMissingPositive@plt>
cmp    $0x4,%eax
jne    128b <main+0x14b>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xdcb(%rip),%rdi
lea    0xdd5(%rip),%rsi
jmp    1299 <main+0x159>
lea    0xdbb(%rip),%rdi
lea    0xdd2(%rip),%rsi
jmp    1299 <main+0x159>
lea    0xdab(%rip),%rdi
lea    0xdc8(%rip),%rsi
jmp    1299 <main+0x159>
lea    0xd9b(%rip),%rdi
lea    0xdc5(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.main.n1 = [2 x i32] [i32 -1, i32 -3]
@__const.main.n2 = [3 x i32] [i32 1, i32 2, i32 3]
@__const.main.n3 = [4 x i32] [i32 0, i32 2, i32 1, i32 3]
@.str = [13 x i8] c"n2[%d] = %d\0A\00"
@.str.1 = [17 x i8] c"assert fail: %s\0A\00"
@.str.2 = [13 x i8] c"all negative\00"
@.str.3 = [6 x i8] c"1 2 3\00"
@.str.4 = [13 x i8] c"zero element\00"
@.str.5 = [13 x i8] c"out of order\00"
@.str.6 = [21 x i8] c"everything is fine!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [3 x i32]
%8 = alloca [4 x i32]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [2 x i32]* %6 to i8*
%12 = bitcast [3 x i32]* %7 to i8*
%13 = bitcast [4 x i32]* %8 to i8*
store i32 0, i32* %9
br label %14
14: ; preds = %24, %2
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %9
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %22)
br label %24
24: ; preds = %17
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
br label %14
27: ; preds = %14
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%29 = call i32 @firstMissingPositive(i32* %28, i32 2)
%30 = icmp eq i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %27
store i32 0, i32* %10
br label %35
35: ; preds = %45, %34
%36 = load i32, i32* %10
%37 = icmp slt i32 %36, 3
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i32, i32* %10
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %39, i32 %43)
br label %45
45: ; preds = %38
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %35
48: ; preds = %35
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %7, i64 0, i64 0
%50 = call i32 @firstMissingPositive(i32* %49, i32 3)
%51 = icmp eq i32 %50, 4
br i1 %51, label %55, label %52
52: ; preds = %48
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 -1)
unreachable
55: ; preds = %48
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%57 = call i32 @firstMissingPositive(i32* %56, i32 0)
%58 = icmp eq i32 %57, 1
br i1 %58, label %62, label %59
59: ; preds = %55
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %55
%63 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%64 = call i32 @firstMissingPositive(i32* %63, i32 4)
%65 = icmp eq i32 %64, 4
br i1 %65, label %69, label %66
66: ; preds = %62
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%68 = call i32 @exit(i32 -1)
unreachable
69: ; preds = %62
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.n2 = [3 x i32] [i32 1, i32 2, i32 3]
@__const.main.n3 = [4 x i32] [i32 0, i32 2, i32 1, i32 3]
@.str = [13 x i8] c"n2[%d] = %d\0A\00"
@.str.1 = [17 x i8] c"assert fail: %s\0A\00"
@.str.2 = [13 x i8] c"all negative\00"
@.str.3 = [6 x i8] c"1 2 3\00"
@.str.4 = [13 x i8] c"zero element\00"
@.str.5 = [13 x i8] c"out of order\00"
@str = [20 x i8] c"everything is fine!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [3 x i32]
%5 = alloca [4 x i32]
%6 = bitcast i64* %3 to i8*
store i64 -8589934593, i64* %3
%7 = bitcast [3 x i32]* %4 to i8*
%8 = bitcast [4 x i32]* %5 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 0, i32 1)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1, i32 2)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 2, i32 3)
%12 = bitcast i64* %3 to i32*
%13 = call i32 @firstMissingPositive(i32* %12, i32 2)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 0, i32 1)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1, i32 2)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 2, i32 3)
%20 = call i32 @firstMissingPositive(i32* %16, i32 3)
%21 = icmp eq i32 %20, 4
br i1 %21, label %28, label %25
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %15
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %15
%29 = call i32 @firstMissingPositive(i32* %12, i32 0)
%30 = icmp eq i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %28
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
%36 = call i32 @firstMissingPositive(i32* %35, i32 4)
%37 = icmp eq i32 %36, 4
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %34
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
ret i32 0
}