#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*/ printf(char *, int, long);
long last_4_pow(int b, int e) {
  long ret = 1;
  int i;
  for (i = 1; i <= e; i++) {
    ret *= b;
    ret %= 10000000000;
  }
  printf("b : %d l4: %ld\n", b, ret);
  return ret;
}


x86 assembly (clang, -O0):
<last_4_pow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     116b <last_4_pow+0x5b>
movslq -0x4(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movabs $0x2540be400,%rcx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <last_4_pow+0x1d>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_4_pow>:
push   %rbx
mov    %edi,%r8d
test   %esi,%esi
jle    1146 <last_4_pow+0x36>
movslq %r8d,%rdi
lea    -0x1(%rsi),%eax
mov    %esi,%ecx
and    $0x3,%ecx
movabs $0x36f9bfb3af7b757,%r9
9b 6f 03
movabs $0x2540be400,%r10
cmp    $0x3,%eax
jae    1150 <last_4_pow+0x40>
mov    $0x1,%ebx
jmp    11e5 <last_4_pow+0xd5>
mov    $0x1,%ebx
jmp    1214 <last_4_pow+0x104>
and    $0xfffffffc,%esi
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
imul   %rdi,%rbx
mov    %rbx,%rax
imul   %r9
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1b,%rdx
add    %rax,%rdx
imul   %r10,%rdx
sub    %rdx,%rbx
imul   %rdi,%rbx
mov    %rbx,%rax
imul   %r9
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1b,%rdx
add    %rax,%rdx
imul   %r10,%rdx
sub    %rdx,%rbx
imul   %rdi,%rbx
mov    %rbx,%rax
imul   %r9
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1b,%rdx
add    %rax,%rdx
imul   %r10,%rdx
sub    %rdx,%rbx
imul   %rdi,%rbx
mov    %rbx,%rax
imul   %r9
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1b,%rdx
add    %rax,%rdx
imul   %r10,%rdx
sub    %rdx,%rbx
add    $0xfffffffc,%esi
jne    1160 <last_4_pow+0x50>
test   %ecx,%ecx
je     1214 <last_4_pow+0x104>
nopl   0x0(%rax)
imul   %rdi,%rbx
mov    %rbx,%rax
imul   %r9
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1b,%rdx
add    %rax,%rdx
imul   %r10,%rdx
sub    %rdx,%rbx
add    $0xffffffff,%ecx
jne    11f0 <last_4_pow+0xe0>
lea    0xde5(%rip),%rdi
mov    %r8d,%esi
mov    %rbx,%rdx
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"b : %d l4: %ld\0A\00"
define i64 @last_4_pow(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i64 1, i64* %5
store i32 1, i32* %6
br label %7
7: ; preds = %18, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = load i64, i64* %5
%15 = mul nsw i64 %14, %13
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = srem i64 %16, 10000000000
store i64 %17, i64* %5
br label %18
18: ; preds = %11
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %7
21: ; preds = %7
%22 = load i32, i32* %3
%23 = load i64, i64* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %22, i64 %23)
%25 = load i64, i64* %5
ret i64 %25
}

LLVM IR (-O2):
@.str = [16 x i8] c"b : %d l4: %ld\0A\00"
define i64 @last_4_pow(i32 %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %35, label %4
4: ; preds = %2
%5 = sext i32 %0 to i64
%6 = add i32 %1, -1
%7 = and i32 %1, 3
%8 = icmp ult i32 %6, 3
br i1 %8, label %24, label %9
9: ; preds = %4
%10 = and i32 %1, -4
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 1, %9 ], [ %21, %11 ]
%13 = phi i32 [ 0, %9 ], [ %22, %11 ]
%14 = mul nsw i64 %12, %5
%15 = srem i64 %14, 10000000000
%16 = mul nsw i64 %15, %5
%17 = srem i64 %16, 10000000000
%18 = mul nsw i64 %17, %5
%19 = srem i64 %18, 10000000000
%20 = mul nsw i64 %19, %5
%21 = srem i64 %20, 10000000000
%22 = add i32 %13, 4
%23 = icmp eq i32 %22, %10
br i1 %23, label %24, label %11
24: ; preds = %11, %4
%25 = phi i64 [ undef, %4 ], [ %21, %11 ]
%26 = phi i64 [ 1, %4 ], [ %21, %11 ]
%27 = icmp eq i32 %7, 0
br i1 %27, label %35, label %28
28: ; preds = %24, %28
%29 = phi i64 [ %32, %28 ], [ %26, %24 ]
%30 = phi i32 [ %33, %28 ], [ 0, %24 ]
%31 = mul nsw i64 %29, %5
%32 = srem i64 %31, 10000000000
%33 = add i32 %30, 1
%34 = icmp eq i32 %33, %7
br i1 %34, label %35, label %28
35: ; preds = %24, %28, %2
%36 = phi i64 [ 1, %2 ], [ %25, %24 ], [ %32, %28 ]
%37 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %0, i64 %36)
ret i64 %36
}