#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*/ fmod(int, int);
double log(double);
int pow(double, int /*<<< orphan*/);
int p(int l, int n) {
  int test = 0;
  double logv = log(2.0) / log(10.0);
  int factor = 1;
  int loop = l;
  while (loop > 10) {
    factor *= 10;
    loop /= 10;
  }
  while (n > 0) {
    int val;
    test++;
    val = (int)(factor * pow(10.0, fmod(test * logv, 1)));
    if (val == l) {
      n--;
    }
  }
  return test;
}


x86 assembly (clang, -O0):
<p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movsd  0xebb(%rip),%xmm0
call   1040 <log@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  0xea1(%rip),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jle    11a6 <p+0x76>
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
jmp    1182 <p+0x52>
jmp    11ab <p+0x7b>
cmpl   $0x0,-0x8(%rbp)
jle    1210 <p+0xe0>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
mov    $0x1,%esi
call   1030 <fmod@plt>
mov    %eax,%edi
movsd  0xe1a(%rip),%xmm0
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    120b <p+0xdb>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11ab <p+0x7b>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x1,%ebx
cmp    $0xb,%edi
jl     1166 <p+0x46>
mov    $0x1,%ebx
mov    $0xcccccccd,%eax
mov    %r14d,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
mov    %ecx,%edx
imul   %rax,%rdx
shr    $0x23,%rdx
cmp    $0x6d,%ecx
mov    %edx,%ecx
ja     1150 <p+0x30>
xor    %ebp,%ebp
test   %r15d,%r15d
jle    11af <p+0x8f>
nopl   (%rax)
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xe7e(%rip),%xmm0
cvttsd2si %xmm0,%edi
mov    $0x1,%esi
call   1030 <fmod@plt>
movsd  0xe70(%rip),%xmm0
mov    %eax,%edi
call   1040 <pow@plt>
imul   %ebx,%eax
xor    %ecx,%ecx
cmp    %r14d,%eax
sete   %cl
sub    %ecx,%r15d
jne    1170 <p+0x50>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @p(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%10 = call double @log(double 2.000000e+00)
%11 = call double @log(double 1.000000e+01)
%12 = fdiv double %10, %11
store double %12, double* %6
store i32 1, i32* %7
%13 = load i32, i32* %3
store i32 %13, i32* %8
br label %14
14: ; preds = %17, %2
%15 = load i32, i32* %8
%16 = icmp sgt i32 %15, 10
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* %7
%19 = mul nsw i32 %18, 10
store i32 %19, i32* %7
%20 = load i32, i32* %8
%21 = sdiv i32 %20, 10
store i32 %21, i32* %8
br label %14
22: ; preds = %14
br label %23
23: ; preds = %44, %22
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
%29 = load i32, i32* %7
%30 = load i32, i32* %5
%31 = sitofp i32 %30 to double
%32 = load double, double* %6
%33 = fmul double %31, %32
%34 = fptosi double %33 to i32
%35 = call i32 @fmod(i32 %34, i32 1)
%36 = call i32 @pow(double 1.000000e+01, i32 %35)
%37 = mul nsw i32 %29, %36
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = load i32, i32* %3
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %26
%42 = load i32, i32* %4
%43 = add nsw i32 %42, -1
store i32 %43, i32* %4
br label %44
44: ; preds = %41, %26
br label %23
45: ; preds = %23
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
define i32 @p(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, 10
br i1 %3, label %7, label %4
4: ; preds = %7, %2
%5 = phi i32 [ 1, %2 ], [ %10, %7 ]
%6 = icmp sgt i32 %1, 0
br i1 %6, label %13, label %27
7: ; preds = %2, %7
%8 = phi i32 [ %11, %7 ], [ %0, %2 ]
%9 = phi i32 [ %10, %7 ], [ 1, %2 ]
%10 = mul nsw i32 %9, 10
%11 = udiv i32 %8, 10
%12 = icmp ugt i32 %8, 109
br i1 %12, label %7, label %4
13: ; preds = %4, %13
%14 = phi i32 [ %25, %13 ], [ %1, %4 ]
%15 = phi i32 [ %16, %13 ], [ 0, %4 ]
%16 = add nuw nsw i32 %15, 1
%17 = sitofp i32 %16 to double
%18 = fmul double %17, 0x3FD34413509F79FE
%19 = fptosi double %18 to i32
%20 = tail call i32 @fmod(i32 %19, i32 1)
%21 = tail call i32 @pow(double 1.000000e+01, i32 %20)
%22 = mul nsw i32 %21, %5
%23 = icmp eq i32 %22, %0
%24 = sext i1 %23 to i32
%25 = add nsw i32 %14, %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %13
27: ; preds = %13, %4
%28 = phi i32 [ 0, %4 ], [ %16, %13 ]
ret i32 %28
}