#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 getchar();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int strtol(char *, char **, int /*<<< orphan*/);
int main(void) {
  int c;
  char sentence[50];
  int i = 0;
  puts("Inserisci una riga di testo:");
  while (i < 50 - 1 && (c = getchar()) != '\n') {
    sentence[i++] = c;
  }
  sentence[i] = '\0';
  puts("\nLa Riga immessa e':");
  puts(sentence);
  int valoreTemp;
  int intero;
  char frase[50];
  char *tempPtr;
  memset(frase, 0, 50);
  fgets(frase, 50, stdin);
  valoreTemp = strtol(frase, &tempPtr, 0);
  if (strlen(tempPtr) > 1) {
    printf("Errore");
  } else {
    intero = valoreTemp;
    printf("%d", intero);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
cmpl   $0x31,-0x44(%rbp)
mov    %al,-0x89(%rbp)
jge    11bd <main+0x4d>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xa,%eax
setne  %al
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
test   $0x1,%al
jne    11d0 <main+0x60>
jmp    11eb <main+0x7b>
mov    -0x8(%rbp),%eax
mov    %al,%cl
mov    -0x44(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x44(%rbp)
cltq
mov    %cl,-0x40(%rbp,%rax,1)
jmp    1195 <main+0x25>
movslq -0x44(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
lea    -0x40(%rbp),%rdi
call   1030 <puts@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%esi
call   1070 <fgets@plt>
lea    -0x80(%rbp),%rdi
lea    -0x88(%rbp),%rsi
xor    %edx,%edx
call   1090 <strtol@plt>
mov    %eax,-0x48(%rbp)
mov    -0x88(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jle    126d <main+0xfd>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1284 <main+0x114>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%esi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x90,%rsp
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%eax
je     11af <main+0x3f>
mov    %al,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x31,%rbx
jne    1190 <main+0x20>
mov    $0x31,%ebx
mov    %ebx,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1060 <memset@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1070 <fgets@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1090 <strtol@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     1226 <main+0xb6>
lea    0xe15(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1236 <main+0xc6>
lea    0xe0c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Inserisci una riga di testo:\00"
@.str.1 = [21 x i8] c"\0ALa Riga immessa e':\00"
@stdin = global i32 0
@.str.2 = [7 x i8] c"Errore\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [50 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [50 x i8]
%8 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %4
%9 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %18, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 49
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 (...) @getchar()
store i32 %14, i32* %2
%15 = icmp ne i32 %14, 10
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
br i1 %17, label %18, label %25
18: ; preds = %16
%19 = load i32, i32* %2
%20 = trunc i32 %19 to i8
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %23
store i8 %20, i8* %24
br label %10
25: ; preds = %16
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%31 = call i32 @puts(i8* %30)
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%33 = call i32 @memset(i8* %32, i32 0, i32 50)
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i32 @fgets(i8* %34, i32 50, i32 %35)
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%38 = call i32 @strtol(i8* %37, i8** %8, i32 0)
store i32 %38, i32* %5
%39 = load i8*, i8** %8
%40 = call i32 @strlen(i8* %39)
%41 = icmp sgt i32 %40, 1
br i1 %41, label %42, label %44
42: ; preds = %25
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %48
44: ; preds = %25
%45 = load i32, i32* %5
store i32 %45, i32* %6
%46 = load i32, i32* %6
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %44, %42
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"Inserisci una riga di testo:\00"
@.str.1 = [21 x i8] c"\0ALa Riga immessa e':\00"
@stdin = global i32 0
@.str.2 = [7 x i8] c"Errore\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %0, %10
%7 = phi i64 [ 0, %0 ], [ %12, %10 ]
%8 = tail call i32 (...) @getchar()
%9 = icmp eq i32 %8, 10
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = trunc i32 %8 to i8
%12 = add nuw nsw i64 %7, 1
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %7
store i8 %11, i8* %13
%14 = icmp eq i64 %12, 49
br i1 %14, label %15, label %6
15: ; preds = %10, %6
%16 = phi i64 [ 49, %10 ], [ %7, %6 ]
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @puts(i8* %4)
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%22 = bitcast i8** %3 to i8*
%23 = call i32 @memset(i8* %21, i32 0, i32 50)
%24 = load i32, i32* @stdin
%25 = call i32 @fgets(i8* %21, i32 50, i32 %24)
%26 = call i32 @strtol(i8* %21, i8** %3, i32 0)
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %15
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %34
32: ; preds = %15
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %34
34: ; preds = %32, %30
ret i32 0
}