#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 /*<<< orphan*/ str_number;

/* Variables and functions */
scalar_t__ count_char_in_str(unsigned int, char *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
unsigned int count_digit_in_range(unsigned int digit, unsigned int min,
                                  unsigned int max) {
  char str_number[1024] = {0x00};
  unsigned int count = 0;
  for (int i = min; i < max; i++) {
    sprintf(str_number, "%02d", i);
    count += count_char_in_str(digit + 0x30, str_number);
    memset(str_number, 0x00, sizeof(str_number));
  }
  return count;
}


x86 assembly (clang, -O0):
<count_digit_in_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
movl   $0x0,-0x414(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11dd <count_digit_in_range+0xad>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%edx
lea    0xe73(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x4(%rbp),%edi
add    $0x30,%edi
lea    -0x410(%rbp),%rsi
call   1040 <count_char_in_str@plt>
mov    %rax,%rcx
mov    -0x414(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    116a <count_digit_in_range+0x3a>
mov    -0x414(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_digit_in_range>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
mov    %rsp,%rdi
xor    %ebx,%ebx
mov    $0x400,%edx
xor    %esi,%esi
call   1030 <memset@plt>
cmp    %r14d,%ebp
jae    11a1 <count_digit_in_range+0x71>
add    $0x30,%r15d
xor    %ebx,%ebx
lea    0xe94(%rip),%r12
mov    %rsp,%r13
nop
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %r15d,%edi
mov    %r13,%rsi
call   1040 <count_char_in_str@plt>
add    %eax,%ebx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1170 <count_digit_in_range+0x40>
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02d\00"
define i32 @count_digit_in_range(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = bitcast [1024 x i8]* %7 to i8*
store i32 0, i32* %8
%11 = load i32, i32* %5
store i32 %11, i32* %9
br label %12
12: ; preds = %30, %3
%13 = load i32, i32* %9
%14 = load i32, i32* %6
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* %9
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
%21 = add i32 %20, 48
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%23 = call i64 @count_char_in_str(i32 %21, i8* %22)
%24 = load i32, i32* %8
%25 = zext i32 %24 to i64
%26 = add nsw i64 %25, %23
%27 = trunc i64 %26 to i32
store i32 %27, i32* %8
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 1024)
br label %30
30: ; preds = %16
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %12
33: ; preds = %12
%34 = load i32, i32* %8
ret i32 %34
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02d\00"
define i32 @count_digit_in_range(i32 %0, i32 %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = icmp ult i32 %1, %2
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = add i32 %0, 48
br label %11
9: ; preds = %11, %3
%10 = phi i32 [ 0, %3 ], [ %17, %11 ]
ret i32 %10
11: ; preds = %7, %11
%12 = phi i32 [ %1, %7 ], [ %19, %11 ]
%13 = phi i32 [ 0, %7 ], [ %17, %11 ]
%14 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%15 = call i64 @count_char_in_str(i32 %8, i8* %5)
%16 = trunc i64 %15 to i32
%17 = add i32 %13, %16
%18 = call i32 @memset(i8* %5, i32 0, i32 1024)
%19 = add i32 %12, 1
%20 = icmp eq i32 %19, %2
br i1 %20, label %9, label %11
}