#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 */
long long fastTimes(long long, long long, long long);
long long fastPow(long long a, long long b, long long m) {
  long long ret = 1;
  while (b) {
    if (b & 1)
      b = fastTimes(a, b, m);
    b >>= 1;
    a = (a << 1) % m;
  }
  return ret;
}


x86 assembly (clang, -O0):
<fastPow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1181 <fastPow+0x71>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     115e <fastPow+0x4e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <fastTimes@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sar    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x1,%rax
cqto
idivq  -0x18(%rbp)
mov    %rdx,-0x8(%rbp)
jmp    112c <fastPow+0x1c>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fastPow>:
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1178 <fastPow+0x68>
mov    %rdx,%r14
mov    %rdi,%rbx
jmp    114a <fastPow+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
cqto
idiv   %r14
mov    %rdx,%rbx
mov    %rsi,%rax
sar    %rax
cmp    $0x1,%rsi
mov    %rax,%rsi
jbe    1178 <fastPow+0x68>
test   $0x1,%sil
je     115e <fastPow+0x4e>
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <fastTimes@plt>
mov    %rax,%rsi
add    %rbx,%rbx
mov    %rbx,%rax
or     %r14,%rax
shr    $0x20,%rax
jne    1130 <fastPow+0x20>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%ebx
jmp    113b <fastPow+0x2b>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @fastPow(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i64 1, i64* %7
br label %8
8: ; preds = %20, %3
%9 = load i64, i64* %5
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i64, i64* %5
%13 = and i64 %12, 1
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i64, i64* %4
%17 = load i64, i64* %5
%18 = load i64, i64* %6
%19 = call i64 @fastTimes(i64 %16, i64 %17, i64 %18)
store i64 %19, i64* %5
br label %20
20: ; preds = %15, %11
%21 = load i64, i64* %5
%22 = ashr i64 %21, 1
store i64 %22, i64* %5
%23 = load i64, i64* %4
%24 = shl i64 %23, 1
%25 = load i64, i64* %6
%26 = srem i64 %24, %25
store i64 %26, i64* %4
br label %8
27: ; preds = %8
%28 = load i64, i64* %7
ret i64 %28
}

LLVM IR (-O2):
define i64 @fastPow(i64 %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %18, label %5
5: ; preds = %3, %12
%6 = phi i64 [ %16, %12 ], [ %0, %3 ]
%7 = phi i64 [ %14, %12 ], [ %1, %3 ]
%8 = and i64 %7, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i64 @fastTimes(i64 %6, i64 %7, i64 %2)
br label %12
12: ; preds = %10, %5
%13 = phi i64 [ %11, %10 ], [ %7, %5 ]
%14 = ashr i64 %13, 1
%15 = shl i64 %6, 1
%16 = srem i64 %15, %2
%17 = icmp ult i64 %13, 2
br i1 %17, label %18, label %5
18: ; preds = %12, %3
ret i64 1
}