#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*/ printf(char *);
scalar_t__ scanf(char *, int *);
int main() {
  int n, i;
  while (scanf("%d", &n)) {
    if (n == 0)
      break;
    int a[n];
    for (i = 0; i < n; ++i)
      scanf("%d", &a[i]);
    for (i = 0; i < n; ++i)
      if (a[a[i] - 1] != i + 1)
        break;
    if (i < n)
      printf("not ambiguous\n");
    else
      printf("ambiguous\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x0,%rax
je     123d <main+0x11d>
cmpl   $0x0,-0x8(%rbp)
jne    1158 <main+0x38>
jmp    123d <main+0x11d>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11bb <main+0x9b>
mov    -0x28(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe58(%rip),%rdi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1186 <main+0x66>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1208 <main+0xe8>
mov    -0x28(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     11f5 <main+0xd5>
jmp    1208 <main+0xe8>
jmp    11fa <main+0xda>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c2 <main+0xa2>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1225 <main+0x105>
lea    0xde8(%rip),%rdi
call   1030 <printf@plt>
jmp    1231 <main+0x111>
lea    0xddb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    112f <main+0xf>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xecb(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     120b <main+0xeb>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     120b <main+0xeb>
lea    0xea7(%rip),%r15
nopl   0x0(%rax)
mov    %rsp,%r13
mov    %eax,%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    11ac <main+0x8c>
mov    %r12,%rbx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
add    $0x1,%r14
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r14
jl     1190 <main+0x70>
test   %eax,%eax
mov    $0x0,%ecx
cmovle %ecx,%eax
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
cmp    %rcx,%rax
je     11e0 <main+0xc0>
movslq (%r12,%rcx,4),%rdx
mov    -0x4(%r12,%rdx,4),%edx
add    $0x1,%rcx
cmp    %rdx,%rcx
je     11c0 <main+0xa0>
lea    0xe25(%rip),%rdi
jmp    11e7 <main+0xc7>
lea    0xe20(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rsp
mov    %r15,%rdi
lea    -0x2c(%rbp),%rsi
call   1040 <scanf@plt>
test   %rax,%rax
je     120b <main+0xeb>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jne    1160 <main+0x40>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [10 x i8] c"ambiguous\00"
@str.3 = [14 x i8] c"not ambiguous\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i64 %3, 0
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, 0
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %48, label %8
8: ; preds = %0, %40
%9 = phi i32 [ %45, %40 ], [ %5, %0 ]
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %19, %8
%16 = phi i32 [ %13, %8 ], [ %24, %19 ]
%17 = call i32 @llvm.smax.i32(i32 %16, i32 0)
%18 = zext i32 %17 to i64
br label %27
19: ; preds = %8, %19
%20 = phi i64 [ %23, %19 ], [ 0, %8 ]
%21 = getelementptr inbounds i32, i32* %12, i64 %20
%22 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %21)
%23 = add nuw nsw i64 %20, 1
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %19, label %15
27: ; preds = %15, %30
%28 = phi i64 [ 0, %15 ], [ %37, %30 ]
%29 = icmp eq i64 %28, %18
br i1 %29, label %40, label %30
30: ; preds = %27
%31 = getelementptr inbounds i32, i32* %12, i64 %28
%32 = load i32, i32* %31
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %12, i64 %34
%36 = load i32, i32* %35
%37 = add nuw nsw i64 %28, 1
%38 = zext i32 %36 to i64
%39 = icmp eq i64 %37, %38
br i1 %39, label %27, label %40
40: ; preds = %27, %30
%41 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.3, i64 0, i64 0), %30 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0), %27 ]
%42 = call i32 @puts(i8* dereferenceable(1) %41)
%43 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%44 = icmp eq i64 %43, 0
%45 = load i32, i32* %1
%46 = icmp eq i32 %45, 0
%47 = select i1 %44, i1 true, i1 %46
br i1 %47, label %48, label %8
48: ; preds = %40, %0
ret i32 0
}