#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 */
typedef int uint32_t;

/* Variables and functions */
int eval_bouncy(int i, int (*cmp)(uint32_t, uint32_t)) {
  uint32_t last = i % 10;
  for (i /= 10; i; i /= ((last = i % 10), 10)) {
    if (cmp(i % 10, last)) {
      break;
    }
  }
  return !i;
}


x86 assembly (clang, -O0):
<eval_bouncy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1187 <eval_bouncy+0x87>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
mov    %edx,%edi
mov    -0x14(%rbp),%esi
call   *%rax
cmp    $0x0,%eax
je     1161 <eval_bouncy+0x61>
jmp    1187 <eval_bouncy+0x87>
jmp    1166 <eval_bouncy+0x66>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    112b <eval_bouncy+0x2b>
cmpl   $0x0,-0x4(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_bouncy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
movslq %edi,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
nopw   0x0(%rax,%rax,1)
lea    0x9(%rbx),%ebp
cmp    $0x13,%ebp
jb     117b <eval_bouncy+0x7b>
movslq %ebx,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
movslq %ebx,%r15
imul   $0x66666667,%r15,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r15d
mov    %r15d,%edi
call   *%r14
mov    %r15d,%esi
test   %eax,%eax
je     1130 <eval_bouncy+0x30>
xor    %eax,%eax
cmp    $0x13,%ebp
setb   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @eval_bouncy(i32 %0, i32 (i32, i32)* nocapture %1) {
%3 = srem i32 %0, 10
br label %4
4: ; preds = %10, %2
%5 = phi i32 [ %0, %2 ], [ %7, %10 ]
%6 = phi i32 [ %3, %2 ], [ %11, %10 ]
%7 = sdiv i32 %5, 10
%8 = add i32 %5, 9
%9 = icmp ult i32 %8, 19
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = srem i32 %7, 10
%12 = tail call i32 %1(i32 %11, i32 %6)
%13 = icmp eq i32 %12, 0
br i1 %13, label %4, label %14
14: ; preds = %10, %4
%15 = zext i1 %9 to i32
ret i32 %15
}