#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 */
scalar_t__ calloc(int, int);
scalar_t__ equals(int *, int *, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char const *argv[]) {
  int numbers = 0;
  scanf("%d", &numbers);
  while (numbers > 0) {
    int *perm = (int *)calloc(numbers, sizeof(int));
    int *revperm = (int *)calloc(numbers, sizeof(int));
    for (int i = 0; i < numbers; ++i) {
      scanf("%d", &perm[i]);
      revperm[perm[i] - 1] = i + 1;
    }
    if (equals(perm, revperm, numbers)) {
      printf("ambiguous\n");
    } else {
      printf("not ambiguous\n");
    }
    free(perm);
    free(revperm);
    scanf("%d", &numbers);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe8c(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1261 <main+0x111>
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1203 <main+0xb3>
mov    -0x20(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2e(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x2c(%rbp),%rsi
mov    (%rcx,%rsi,4),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b0 <main+0x60>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <equals@plt>
cmp    $0x0,%rax
je     122e <main+0xde>
lea    0xde3(%rip),%rdi
call   1040 <printf@plt>
jmp    123a <main+0xea>
lea    0xdce(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xdad(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
jmp    117d <main+0x2d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xe96(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    123a <main+0xea>
lea    0xe79(%rip),%r12
lea    0x4(%rsp),%r14
jmp    11d8 <main+0x88>
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <equals@plt>
test   %rax,%rax
lea    0xe62(%rip),%rdi
lea    0xe57(%rip),%rax
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    123a <main+0xea>
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
mov    0x4(%rsp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%r13
mov    0x4(%rsp),%edx
test   %edx,%edx
jle    1190 <main+0x40>
mov    %r15,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq (%rbx),%rax
mov    %ebp,-0x4(%r13,%rax,4)
movslq 0x4(%rsp),%rdx
add    $0x4,%rbx
cmp    %rdx,%rbp
jl     1210 <main+0xc0>
jmp    1190 <main+0x40>
xor    %eax,%eax
add    $0x8,%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 = [11 x i8] c"ambiguous\0A\00"
@.str.2 = [15 x i8] c"not ambiguous\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %11
11: ; preds = %55, %2
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %61
14: ; preds = %11
%15 = load i32, i32* %6
%16 = call i64 @calloc(i32 %15, i32 4)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %7
%18 = load i32, i32* %6
%19 = call i64 @calloc(i32 %18, i32 4)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %8
store i32 0, i32* %9
br label %21
21: ; preds = %42, %14
%22 = load i32, i32* %9
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %45
25: ; preds = %21
%26 = load i32*, i32** %7
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %29)
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
%33 = load i32*, i32** %8
%34 = load i32*, i32** %7
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %33, i64 %40
store i32 %32, i32* %41
br label %42
42: ; preds = %25
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %21
45: ; preds = %21
%46 = load i32*, i32** %7
%47 = load i32*, i32** %8
%48 = load i32, i32* %6
%49 = call i64 @equals(i32* %46, i32* %47, i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %55
53: ; preds = %45
%54 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53, %51
%56 = load i32*, i32** %7
%57 = call i32 @free(i32* %56)
%58 = load i32*, i32** %8
%59 = call i32 @free(i32* %58)
%60 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %11
61: ; preds = %11
ret i32 0
}

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