#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 pow(int, int);
int primepow(int n, int p) {
  int j, k[10000], s;
  j = 0;
  s = 0;
  while (j >= 0) {
    ++j;
    k[j] = n / (pow(p, j));
    s = s + k[j];
    if (k[j] == 0) {
      break;
    }
  }
  return s;
}


x86 assembly (clang, -O0):
<primepow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x9c54(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11a4 <primepow+0x94>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x9c58(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <pow@plt>
mov    %eax,%ecx
mov    -0x9c58(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x9c50(%rbp,%rax,4)
mov    -0x9c54(%rbp),%eax
movslq -0xc(%rbp),%rcx
add    -0x9c50(%rbp,%rcx,4),%eax
mov    %eax,-0x9c54(%rbp)
movslq -0xc(%rbp),%rax
cmpl   $0x0,-0x9c50(%rbp,%rax,4)
jne    119f <primepow+0x8f>
jmp    11a4 <primepow+0x94>
jmp    1132 <primepow+0x22>
mov    -0x9c54(%rbp),%eax
add    $0x9c60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<primepow>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
xor    %ebp,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14d,%edi
mov    %ebx,%esi
call   1030 <pow@plt>
mov    %eax,%ecx
mov    %r15d,%eax
cltd
idiv   %ecx
add    %eax,%ebp
add    $0x1,%ebx
test   %eax,%eax
jne    1130 <primepow+0x20>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @primepow(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10000 x i32]
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %7
br label %8
8: ; preds = %34, %2
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %35
11: ; preds = %8
%12 = load i32, i32* %5
%13 = add nsw i32 %12, 1
store i32 %13, i32* %5
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @pow(i32 %15, i32 %16)
%18 = sdiv i32 %14, %17
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 %20
store i32 %18, i32* %21
%22 = load i32, i32* %7
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = add nsw i32 %22, %26
store i32 %27, i32* %7
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [10000 x i32], [10000 x i32]* %6, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %11
br label %35
34: ; preds = %11
br label %8
35: ; preds = %33, %8
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
define i32 @primepow(i32 %0, i32 %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ 0, %2 ], [ %6, %3 ]
%5 = phi i32 [ 0, %2 ], [ %9, %3 ]
%6 = add nuw nsw i32 %4, 1
%7 = tail call i32 @pow(i32 %1, i32 %6)
%8 = sdiv i32 %0, %7
%9 = add nsw i32 %8, %5
%10 = icmp eq i32 %8, 0
br i1 %10, label %11, label %3
11: ; preds = %3
ret i32 %9
}