#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*/ fftw_die(char *);
int period(int n, int p) {
  int prod = n, period = 1;
  while (prod != 1) {
    prod = ((int)((((long long)(prod)) * ((long long)(n))) % ((long long)(p))));
    ++period;
    if (prod == 0)
      fftw_die("non-prime order in Rader\n");
  }
  return period;
}


x86 assembly (clang, -O0):
<period>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     1173 <period+0x63>
movslq -0xc(%rbp),%rax
movslq -0x4(%rbp),%rcx
imul   %rcx,%rax
movslq -0x8(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116e <period+0x5e>
lea    0xe97(%rip),%rdi
call   1030 <fftw_die@plt>
jmp    112b <period+0x1b>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<period>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x1,%edi
jne    1136 <period+0x26>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %esi,%r15d
mov    %edi,%ebp
movslq %edi,%r12
movslq %esi,%r13
mov    $0x2,%ebx
lea    0xeb3(%rip),%r14
jmp    115b <period+0x4b>
nop
mov    %r14,%rdi
call   1030 <fftw_die@plt>
add    $0x1,%ebx
movslq %ebp,%rax
imul   %r12,%rax
mov    %rax,%rcx
or     %r13,%rcx
shr    $0x20,%rcx
je     1180 <period+0x70>
cqto
idiv   %r13
mov    %rdx,%rbp
test   %ebp,%ebp
jne    118b <period+0x7b>
jmp    1150 <period+0x40>
nopl   0x0(%rax)
xor    %edx,%edx
div    %r15d
mov    %edx,%ebp
test   %ebp,%ebp
je     1150 <period+0x40>
cmp    $0x1,%ebp
je     1125 <period+0x15>
add    $0x1,%ebx
jmp    115b <period+0x4b>

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

LLVM IR (-O2):
@.str = [26 x i8] c"non-prime order in Rader\0A\00"
define i32 @period(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %18, label %4
4: ; preds = %2
%5 = sext i32 %0 to i64
%6 = sext i32 %1 to i64
br label %7
7: ; preds = %15, %4
%8 = phi i32 [ 1, %4 ], [ %14, %15 ]
%9 = phi i32 [ %0, %4 ], [ %13, %15 ]
%10 = sext i32 %9 to i64
%11 = mul nsw i64 %10, %5
%12 = srem i64 %11, %6
%13 = trunc i64 %12 to i32
%14 = add nuw nsw i32 %8, 1
switch i32 %13, label %15 [
i32 0, label %16
i32 1, label %18
]
15: ; preds = %7, %16
br label %7
16: ; preds = %7
%17 = tail call i32 @fftw_die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %15
18: ; preds = %7, %2
%19 = phi i32 [ 1, %2 ], [ %14, %7 ]
ret i32 %19
}