#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 *, long *);
int main() {
  long int n;
  int i, counter, temp;
  printf("Enter long integer: ");
  scanf("%ld", &n);
  for (temp = n; temp > 0; counter++) {
    temp = temp / 10;
  }
  printf("The given long integer is %ld and it has %d digits\n", n, counter);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    117a <main+0x5a>
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1154 <main+0x34>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%rsi
mov    $0xcccccccd,%eax
mov    %esi,%ecx
nopl   0x0(%rax)
mov    %ecx,%edi
imul   %rax,%rdi
shr    $0x23,%rdi
add    $0x1,%edx
cmp    $0x9,%ecx
mov    %edi,%ecx
ja     1150 <main+0x30>
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Enter long integer: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [52 x i8] c"The given long integer is %ld and it has %d digits\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%8 = load i64, i64* %2
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
br label %10
10: ; preds = %16, %0
%11 = load i32, i32* %5
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %5
%15 = sdiv i32 %14, 10
store i32 %15, i32* %5
br label %16
16: ; preds = %13
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %10
19: ; preds = %10
%20 = load i64, i64* %2
%21 = load i32, i32* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %20, i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"Enter long integer: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [52 x i8] c"The given long integer is %ld and it has %d digits\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = trunc i64 %5 to i32
%7 = icmp sgt i32 %6, 0
br label %8
8: ; preds = %0, %8
%9 = phi i32 [ %11, %8 ], [ %6, %0 ]
%10 = phi i32 [ %12, %8 ], [ undef, %0 ]
%11 = udiv i32 %9, 10
%12 = add nsw i32 %10, 1
%13 = icmp ult i32 %9, 10
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %5, i32 %12)
ret i32 0
}