#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int zenbatDig = 0, n, gainBorna = 1;
  char str[128];
  printf("Emaidazu zenbaki oso bat: ");
  fgets(str, 128, stdin);
  sscanf(str, "%d", &n);
  do {
    zenbatDig++;
    gainBorna *= 10;
  } while (gainBorna <= n);
  printf("%d zenbakia adierazteko %d digitu behar dira\n", n, zenbatDig);
  printf("Sakatu \"return\" amaitzeko .....");
  fgets(str, 128, stdin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1040 <fgets@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe8e(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1196 <main+0x66>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1040 <fgets@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
lea    0xebd(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e95(%rip),%r15
mov    (%r15),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x80,%esi
call   1040 <fgets@plt>
lea    0xeac(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1050 <sscanf@plt>
mov    $0x1,%eax
mov    0xc(%rsp),%esi
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
add    %eax,%eax
lea    (%rax,%rax,4),%eax
cmp    %esi,%eax
jle    1190 <main+0x60>
lea    0xe7b(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%edx
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
call   1040 <fgets@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Emaidazu zenbaki oso bat: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [46 x i8] c"%d zenbakia adierazteko %d digitu behar dira\0A\00"
@.str.3 = [32 x i8] c"Sakatu \22return\22 amaitzeko .....\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 128, i32 %12)
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
br label %16
16: ; preds = %21, %2
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
store i32 %18, i32* %6
%19 = load i32, i32* %8
%20 = mul nsw i32 %19, 10
store i32 %20, i32* %8
br label %21
21: ; preds = %16
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = icmp sle i32 %22, %23
br i1 %24, label %16, label %25
25: ; preds = %21
%26 = load i32, i32* %7
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %30, i32 128, i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Emaidazu zenbaki oso bat: \00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [46 x i8] c"%d zenbakia adierazteko %d digitu behar dira\0A\00"
@.str.3 = [32 x i8] c"Sakatu \22return\22 amaitzeko .....\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %6, i32 128, i32 %8)
%10 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
br label %12
12: ; preds = %12, %2
%13 = phi i32 [ 0, %2 ], [ %15, %12 ]
%14 = phi i32 [ 1, %2 ], [ %16, %12 ]
%15 = add nuw nsw i32 %13, 1
%16 = mul nsw i32 %14, 10
%17 = icmp sgt i32 %16, %11
br i1 %17, label %18, label %12
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %15)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %6, i32 128, i32 %21)
ret i32 0
}