#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 getDigits(int);
int pow(int, int);
int /*<<< orphan*/ printf(char *, int);
void cyclic(int n) {
  int length = getDigits(n);
  int res = n;
  while (1) {
    printf("%d\n", res);
    int remainder = res % 10;
    int quotient = res / 10;
    res = remainder * pow(10, length - 1) + quotient;
    if (res == n) {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<cyclic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <getDigits@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11ac <cyclic+0x7c>
jmp    11b1 <cyclic+0x81>
jmp    114c <cyclic+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cyclic>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
call   1050 <getDigits@plt>
mov    %eax,%r12d
add    $0xffffffff,%r12d
lea    0xeaf(%rip),%r14
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
movslq %ebx,%r13
imul   $0x66666667,%r13,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x22,%rbp
add    %eax,%ebp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r13d
mov    $0xa,%edi
mov    %r12d,%esi
call   1040 <pow@plt>
mov    %eax,%ebx
imul   %r13d,%ebx
add    %ebp,%ebx
cmp    %r15d,%ebx
jne    1160 <cyclic+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define void @cyclic(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @getDigits(i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %2
store i32 %9, i32* %4
br label %10
10: ; preds = %1, %28
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %4
%14 = srem i32 %13, 10
store i32 %14, i32* %5
%15 = load i32, i32* %4
%16 = sdiv i32 %15, 10
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
%20 = call i32 @pow(i32 10, i32 %19)
%21 = mul nsw i32 %17, %20
%22 = load i32, i32* %6
%23 = add nsw i32 %21, %22
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %10
br label %29
28: ; preds = %10
br label %10
29: ; preds = %27
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define void @cyclic(i32 %0) {
%2 = tail call i32 @getDigits(i32 %0)
%3 = add nsw i32 %2, -1
br label %4
4: ; preds = %4, %1
%5 = phi i32 [ %0, %1 ], [ %11, %4 ]
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = srem i32 %5, 10
%8 = sdiv i32 %5, 10
%9 = tail call i32 @pow(i32 10, i32 %3)
%10 = mul nsw i32 %9, %7
%11 = add nsw i32 %10, %8
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %4
13: ; preds = %4
ret void
}