#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 */
scalar_t__ num_repeats(unsigned int, int);
unsigned int numlen(unsigned int);
unsigned lucky_nums(const unsigned limit) {
  unsigned result = 0;
  for (unsigned len = 0, i = 0; i <= limit; ++i, len = numlen(i))
    if (3 == len || 7 == len || num_repeats(i, 3) || num_repeats(i, 7))
      ++result;
  return result;
}


x86 assembly (clang, -O0):
<lucky_nums>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     11bd <lucky_nums+0x9d>
mov    $0x3,%eax
cmp    -0xc(%rbp),%eax
je     1196 <lucky_nums+0x76>
mov    $0x7,%eax
cmp    -0xc(%rbp),%eax
je     1196 <lucky_nums+0x76>
mov    -0x10(%rbp),%edi
mov    $0x3,%esi
call   1030 <num_repeats@plt>
cmp    $0x0,%rax
jne    1196 <lucky_nums+0x76>
mov    -0x10(%rbp),%edi
mov    $0x7,%esi
call   1030 <num_repeats@plt>
cmp    $0x0,%rax
je     119f <lucky_nums+0x7f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a4 <lucky_nums+0x84>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <numlen@plt>
mov    %eax,-0xc(%rbp)
jmp    1140 <lucky_nums+0x20>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lucky_nums>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %ebp,%ebp
xor    %eax,%eax
xor    %ebx,%ebx
nopl   (%rax)
and    $0xfffffffb,%eax
cmp    $0x3,%eax
je     1160 <lucky_nums+0x40>
mov    %ebp,%edi
mov    $0x3,%esi
call   1030 <num_repeats@plt>
test   %rax,%rax
jne    1160 <lucky_nums+0x40>
mov    %ebp,%edi
mov    $0x7,%esi
call   1030 <num_repeats@plt>
test   %rax,%rax
je     1163 <lucky_nums+0x43>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
add    $0x1,%ebp
mov    %ebp,%edi
call   1040 <numlen@plt>
cmp    %r14d,%ebp
jbe    1130 <lucky_nums+0x10>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @lucky_nums(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %28, %1
%7 = load i32, i32* %5
%8 = load i32, i32* %2
%9 = icmp ule i32 %7, %8
br i1 %9, label %10, label %33
10: ; preds = %6
%11 = load i32, i32* %4
%12 = icmp eq i32 3, %11
br i1 %12, label %24, label %13
13: ; preds = %10
%14 = load i32, i32* %4
%15 = icmp eq i32 7, %14
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = load i32, i32* %5
%18 = call i64 @num_repeats(i32 %17, i32 3)
%19 = icmp ne i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i32, i32* %5
%22 = call i64 @num_repeats(i32 %21, i32 7)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20, %16, %13, %10
%25 = load i32, i32* %3
%26 = add i32 %25, 1
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %20
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = add i32 %29, 1
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = call i32 @numlen(i32 %31)
store i32 %32, i32* %4
br label %6
33: ; preds = %6
%34 = load i32, i32* %3
ret i32 %34
}

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