#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int i = 1;
  long sum = 0;
  long num;
  long new_num;
  int digit;
  printf("Enter an integer number: ");
  scanf("%ld", &num);
  printf("Enter the digit you want to count: ");
  scanf("%d", &digit);
  while (new_num > 1) {
    new_num = (num / i) % 10;
    if (new_num == digit)
      sum++;
    i = i * 10;
  }
  if (sum == 1)
    printf("The number of %d in %ld is %ld", digit, num, sum);
  else
    printf("The numbers of %ds in %ld is %ld", digit, num, sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf09(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpq   $0x1,-0x20(%rbp)
jle    11cd <main+0xad>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
cqto
idiv   %rcx
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jne    11c1 <main+0xa1>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    117e <main+0x5e>
cmpq   $0x1,-0x10(%rbp)
jne    11f6 <main+0xd6>
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <main+0xef>
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xed5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf25(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%rdx
lea    0xecb(%rip),%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter an integer number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [36 x i8] c"Enter the digit you want to count: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [31 x i8] c"The number of %d in %ld is %ld\00"
@.str.5 = [33 x i8] c"The numbers of %ds in %ld is %ld\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i64 0, i64* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
br label %11
11: ; preds = %27, %0
%12 = load i64, i64* %5
%13 = icmp sgt i64 %12, 1
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = load i64, i64* %4
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = sdiv i64 %15, %17
%19 = srem i64 %18, 10
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = icmp eq i64 %20, %22
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = load i64, i64* %3
%26 = add nsw i64 %25, 1
store i64 %26, i64* %3
br label %27
27: ; preds = %24, %14
%28 = load i32, i32* %2
%29 = mul nsw i32 %28, 10
store i32 %29, i32* %2
br label %11
30: ; preds = %11
%31 = load i64, i64* %3
%32 = icmp eq i64 %31, 1
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i32, i32* %6
%35 = load i64, i64* %4
%36 = load i64, i64* %3
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %34, i64 %35, i64 %36)
br label %43
38: ; preds = %30
%39 = load i32, i32* %6
%40 = load i64, i64* %4
%41 = load i64, i64* %3
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %39, i64 %40, i64 %41)
br label %43
43: ; preds = %38, %33
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter an integer number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [36 x i8] c"Enter the digit you want to count: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [33 x i8] c"The numbers of %ds in %ld is %ld\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i32
%3 = bitcast i64* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = load i64, i64* %1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %9, i64 %10, i64 0)
ret i32 0
}