#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 fast_plus(int, int, int);
int fast_pow(int a, int b, int m) {
  int ret = 1;
  while (b) {
    if (b & 1) {
      ret = fast_plus(ret, a, m);
    }
    b >>= 1;
    a = fast_plus(a, a, m);
  }
  return ret;
}


x86 assembly (clang, -O0):
<fast_pow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1171 <fast_pow+0x61>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1152 <fast_pow+0x42>
mov    -0x10(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <fast_plus@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <fast_plus@plt>
mov    %eax,-0x4(%rbp)
jmp    1128 <fast_pow+0x18>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fast_pow>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     1164 <fast_pow+0x54>
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%r12d
mov    $0x1,%r14d
jmp    114c <fast_pow+0x3c>
nopl   0x0(%rax)
mov    %ebx,%ebp
sar    %ebp
mov    %r12d,%edi
mov    %r12d,%esi
mov    %r15d,%edx
call   1030 <fast_plus@plt>
mov    %eax,%r12d
cmp    $0x1,%ebx
mov    %ebp,%ebx
jbe    116a <fast_pow+0x5a>
test   $0x1,%bl
je     1130 <fast_pow+0x20>
mov    %r14d,%edi
mov    %r12d,%esi
mov    %r15d,%edx
call   1030 <fast_plus@plt>
mov    %eax,%r14d
jmp    1130 <fast_pow+0x20>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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