#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*/ getchar();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int num, n = 0;
  scanf("%d", &num);
  num = num > 0 ? num : -num;
  do {
    n++;
    num /= 10;
  } while (num > 0);
  printf("n=%d \n", n);
  getchar();
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
jle    1164 <main+0x34>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    116c <main+0x3c>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1172 <main+0x42>
mov    -0x8(%rbp),%esi
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%ecx
mov    %ecx,%eax
neg    %eax
cmovs  %ecx,%eax
xor    %esi,%esi
nop
add    $0x1,%esi
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
cmp    $0x9,%ecx
jg     1150 <main+0x20>
mov    %eax,0x4(%rsp)
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"n=%d \0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %2
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = load i32, i32* %1
br label %11
8: ; preds = %0
%9 = load i32, i32* %1
%10 = sub nsw i32 0, %9
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ %7, %6 ], [ %10, %8 ]
store i32 %12, i32* %1
br label %13
13: ; preds = %18, %11
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
%16 = load i32, i32* %1
%17 = sdiv i32 %16, 10
store i32 %17, i32* %1
br label %18
18: ; preds = %13
%19 = load i32, i32* %1
%20 = icmp sgt i32 %19, 0
br i1 %20, label %13, label %21
21: ; preds = %18
%22 = load i32, i32* %2
%23 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @getchar()
%25 = call i32 (...) @getchar()
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [7 x i8] c"n=%d \0A\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = call i32 @llvm.abs.i32(i32 %4, i1 true)
br label %6
6: ; preds = %6, %0
%7 = phi i32 [ %10, %6 ], [ %5, %0 ]
%8 = phi i32 [ %9, %6 ], [ 0, %0 ]
%9 = add nuw nsw i32 %8, 1
%10 = sdiv i32 %7, 10
%11 = icmp sgt i32 %7, 9
br i1 %11, label %6, label %12
12: ; preds = %6
store i32 %10, i32* %1
%13 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%14 = call i32 (...) @getchar()
%15 = call i32 (...) @getchar()
ret void
}