#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
unsigned long gauss_map(unsigned long, unsigned long);
scalar_t__ malloc(unsigned long);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ stderr;
void print_cycles_short(unsigned long n) {
  char *seen;
  unsigned long i, j, k;
  seen = (char *)malloc(n * sizeof(char));
  if (seen == NULL) {
    fprintf(stderr, "allocation error\n");
    exit(1);
  }
  memset(seen, 0, n * sizeof(char));
  for (i = 0; i < n; ++i) {
    if (seen[i])
      continue;
    j = i;
    do {
      seen[j] = 2;
      j = gauss_map(j, n);
    } while (!(seen[j]));
    k = i;
    if (seen[j] != 2) {
      do {
        seen[k] = 1;
        k = gauss_map(k, n);
      } while (seen[k] == 2);
      continue;
    }
    do {
      seen[k] = 1;
      k = gauss_map(k, n);
    } while (seen[k] == 2);
    k = j;
    while (gauss_map(k, n) != j) {
      printf("%lu ", k);
      k = gauss_map(k, n);
    }
    printf("%lu\n", k);
  }
}


x86 assembly (clang, -O0):
<print_cycles_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a7 <print_cycles_short+0x47>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
shl    $0x0,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    131b <print_cycles_short+0x1bb>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11e7 <print_cycles_short+0x87>
jmp    130a <print_cycles_short+0x1aa>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x2,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <gauss_map@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ef <print_cycles_short+0x8f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2,%eax
je     127e <print_cycles_short+0x11e>
jmp    1247 <print_cycles_short+0xe7>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <gauss_map@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2,%eax
je     1247 <print_cycles_short+0xe7>
jmp    130a <print_cycles_short+0x1aa>
jmp    1283 <print_cycles_short+0x123>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <gauss_map@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2,%eax
je     1283 <print_cycles_short+0x123>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <gauss_map@plt>
cmp    -0x20(%rbp),%rax
je     12fa <print_cycles_short+0x19a>
mov    -0x28(%rbp),%rsi
lea    0xd33(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <gauss_map@plt>
mov    %rax,-0x28(%rbp)
jmp    12bd <print_cycles_short+0x15d>
mov    -0x28(%rbp),%rsi
lea    0xd12(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c2 <print_cycles_short+0x62>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_cycles_short>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <malloc@plt>
test   %rax,%rax
je     12ad <print_cycles_short+0x14d>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
test   %r14,%r14
je     129e <print_cycles_short+0x13e>
xor    %r15d,%r15d
lea    0xe73(%rip),%r12
jmp    11cd <print_cycles_short+0x6d>
mov    %rbx,%rbp
lea    0xe6c(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15
cmp    %r14,%r15
je     129e <print_cycles_short+0x13e>
cmpb   $0x0,0x0(%r13,%r15,1)
jne    11c0 <print_cycles_short+0x60>
mov    %r15,%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x2,0x0(%r13,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <gauss_map@plt>
mov    %rax,%rbx
movzbl 0x0(%r13,%rax,1),%ecx
test   %cl,%cl
je     11e0 <print_cycles_short+0x80>
mov    %r15,%rax
cmp    $0x2,%cl
jne    126e <print_cycles_short+0x10e>
cs nopw 0x0(%rax,%rax,1)
movb   $0x1,0x0(%r13,%rax,1)
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <gauss_map@plt>
cmpb   $0x2,0x0(%r13,%rax,1)
je     1210 <print_cycles_short+0xb0>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <gauss_map@plt>
cmp    %rbx,%rax
je     11a1 <print_cycles_short+0x41>
mov    %rbx,%rbp
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1080 <gauss_map@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <gauss_map@plt>
cmp    %rbx,%rax
jne    1240 <print_cycles_short+0xe0>
jmp    11a4 <print_cycles_short+0x44>
mov    %r15,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x1,0x0(%r13,%rax,1)
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <gauss_map@plt>
cmpb   $0x2,0x0(%r13,%rax,1)
je     1280 <print_cycles_short+0x120>
jmp    11c0 <print_cycles_short+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"allocation error\0A\00"
@.str.1 = [5 x i8] c"%lu \00"
@.str.2 = [5 x i8] c"%lu\0A\00"
define void @print_cycles_short(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %2
%7 = load i64, i64* %2
%8 = mul i64 %7, 1
%9 = call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = load i64, i64* %2
%20 = mul i64 %19, 1
%21 = call i32 @memset(i8* %18, i32 0, i64 %20)
store i64 0, i64* %4
br label %22
22: ; preds = %105, %17
%23 = load i64, i64* %4
%24 = load i64, i64* %2
%25 = icmp ult i64 %23, %24
br i1 %25, label %26, label %108
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = load i64, i64* %4
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
br label %105
33: ; preds = %26
%34 = load i64, i64* %4
store i64 %34, i64* %5
br label %35
35: ; preds = %42, %33
%36 = load i8*, i8** %3
%37 = load i64, i64* %5
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8 2, i8* %38
%39 = load i64, i64* %5
%40 = load i64, i64* %2
%41 = call i64 @gauss_map(i64 %39, i64 %40)
store i64 %41, i64* %5
br label %42
42: ; preds = %35
%43 = load i8*, i8** %3
%44 = load i64, i64* %5
%45 = getelementptr inbounds i8, i8* %43, i64 %44
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
%48 = xor i1 %47, true
br i1 %48, label %35, label %49
49: ; preds = %42
%50 = load i64, i64* %4
store i64 %50, i64* %6
%51 = load i8*, i8** %3
%52 = load i64, i64* %5
%53 = getelementptr inbounds i8, i8* %51, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 2
br i1 %56, label %57, label %73
57: ; preds = %49
br label %58
58: ; preds = %65, %57
%59 = load i8*, i8** %3
%60 = load i64, i64* %6
%61 = getelementptr inbounds i8, i8* %59, i64 %60
store i8 1, i8* %61
%62 = load i64, i64* %6
%63 = load i64, i64* %2
%64 = call i64 @gauss_map(i64 %62, i64 %63)
store i64 %64, i64* %6
br label %65
65: ; preds = %58
%66 = load i8*, i8** %3
%67 = load i64, i64* %6
%68 = getelementptr inbounds i8, i8* %66, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 2
br i1 %71, label %58, label %72
72: ; preds = %65
br label %105
73: ; preds = %49
br label %74
74: ; preds = %81, %73
%75 = load i8*, i8** %3
%76 = load i64, i64* %6
%77 = getelementptr inbounds i8, i8* %75, i64 %76
store i8 1, i8* %77
%78 = load i64, i64* %6
%79 = load i64, i64* %2
%80 = call i64 @gauss_map(i64 %78, i64 %79)
store i64 %80, i64* %6
br label %81
81: ; preds = %74
%82 = load i8*, i8** %3
%83 = load i64, i64* %6
%84 = getelementptr inbounds i8, i8* %82, i64 %83
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 2
br i1 %87, label %74, label %88
88: ; preds = %81
%89 = load i64, i64* %5
store i64 %89, i64* %6
br label %90
90: ; preds = %96, %88
%91 = load i64, i64* %6
%92 = load i64, i64* %2
%93 = call i64 @gauss_map(i64 %91, i64 %92)
%94 = load i64, i64* %5
%95 = icmp ne i64 %93, %94
br i1 %95, label %96, label %102
96: ; preds = %90
%97 = load i64, i64* %6
%98 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %97)
%99 = load i64, i64* %6
%100 = load i64, i64* %2
%101 = call i64 @gauss_map(i64 %99, i64 %100)
store i64 %101, i64* %6
br label %90
102: ; preds = %90
%103 = load i64, i64* %6
%104 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %103)
br label %105
105: ; preds = %102, %72, %32
%106 = load i64, i64* %4
%107 = add i64 %106, 1
store i64 %107, i64* %4
br label %22
108: ; preds = %22
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"allocation error\0A\00"
@.str.1 = [5 x i8] c"%lu \00"
@.str.2 = [5 x i8] c"%lu\0A\00"
define void @print_cycles_short(i64 %0) {
%2 = tail call i64 @malloc(i64 %0)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = tail call i32 @memset(i8* %3, i32 0, i64 %0)
%11 = icmp eq i64 %0, 0
br i1 %11, label %52, label %12
12: ; preds = %9, %49
%13 = phi i64 [ %50, %49 ], [ 0, %9 ]
%14 = getelementptr inbounds i8, i8* %3, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %49
17: ; preds = %12, %17
%18 = phi i64 [ %20, %17 ], [ %13, %12 ]
%19 = getelementptr inbounds i8, i8* %3, i64 %18
store i8 2, i8* %19
%20 = tail call i64 @gauss_map(i64 %18, i64 %0)
%21 = getelementptr inbounds i8, i8* %3, i64 %20
%22 = load i8, i8* %21
switch i8 %22, label %23 [
i8 0, label %17
i8 2, label %30
]
23: ; preds = %17, %23
%24 = phi i64 [ %26, %23 ], [ %13, %17 ]
%25 = getelementptr inbounds i8, i8* %3, i64 %24
store i8 1, i8* %25
%26 = tail call i64 @gauss_map(i64 %24, i64 %0)
%27 = getelementptr inbounds i8, i8* %3, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 2
br i1 %29, label %23, label %49
30: ; preds = %17, %30
%31 = phi i64 [ %33, %30 ], [ %13, %17 ]
%32 = getelementptr inbounds i8, i8* %3, i64 %31
store i8 1, i8* %32
%33 = tail call i64 @gauss_map(i64 %31, i64 %0)
%34 = getelementptr inbounds i8, i8* %3, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 2
br i1 %36, label %30, label %37
37: ; preds = %30
%38 = tail call i64 @gauss_map(i64 %20, i64 %0)
%39 = icmp eq i64 %38, %20
br i1 %39, label %46, label %40
40: ; preds = %37, %40
%41 = phi i64 [ %43, %40 ], [ %20, %37 ]
%42 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %41)
%43 = tail call i64 @gauss_map(i64 %41, i64 %0)
%44 = tail call i64 @gauss_map(i64 %43, i64 %0)
%45 = icmp eq i64 %44, %20
br i1 %45, label %46, label %40
46: ; preds = %40, %37
%47 = phi i64 [ %20, %37 ], [ %43, %40 ]
%48 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %47)
br label %49
49: ; preds = %23, %12, %46
%50 = add nuw i64 %13, 1
%51 = icmp eq i64 %50, %0
br i1 %51, label %52, label %12
52: ; preds = %49, %9
ret void
}