#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
char *trim(char *);
int getValue() {
  int value;
  int validSyntax = 0;
  char buffer[100];
  do {
    if (fgets(buffer, sizeof(buffer), stdin) == NULL) {
      return -1;
    }
    char *bufferTrimmed = trim(buffer);
    if (bufferTrimmed == NULL)
      return 0;
    else {
      validSyntax =
          sscanf(bufferTrimmed, "%d", &value) && bufferTrimmed[0] != ' ';
    }
    if (validSyntax != 1)
      printf("Input sintatticamente non valido. Riprovare: ");
  } while (!validSyntax);
  return value == 0 ? -1 : value;
}


x86 assembly (clang, -O0):
<getValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0xc(%rbp)
lea    -0x70(%rbp),%rdi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    117f <getValue+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <getValue+0xf3>
lea    -0x70(%rbp),%rdi
call   1040 <trim@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11a3 <getValue+0x63>
movl   $0x0,-0x4(%rbp)
jmp    1233 <getValue+0xf3>
mov    -0x78(%rbp),%rdi
lea    0xe52(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x79(%rbp)
je     11d9 <getValue+0x99>
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     11fa <getValue+0xba>
lea    0xe0e(%rip),%rdi
call   1030 <printf@plt>
jmp    11ff <getValue+0xbf>
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1152 <getValue+0x12>
cmpl   $0x0,-0x8(%rbp)
jne    1227 <getValue+0xe7>
mov    $0xffffffff,%eax
mov    %eax,-0x80(%rbp)
jmp    122d <getValue+0xed>
mov    -0x8(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getValue>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2e93(%rip),%r14
mov    (%r14),%edx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    $0xffffffff,%ecx
test   %rax,%rax
je     11ec <getValue+0xac>
lea    0x10(%rsp),%rbx
lea    0xe83(%rip),%r15
lea    0xc(%rsp),%r13
lea    0xe7a(%rip),%r12
jmp    11ad <getValue+0x6d>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <printf@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11e7 <getValue+0xa7>
mov    %rbx,%rdi
call   1040 <trim@plt>
test   %rax,%rax
je     11e3 <getValue+0xa3>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1060 <sscanf@plt>
test   %rax,%rax
je     1190 <getValue+0x50>
cmpb   $0x20,0x0(%rbp)
je     1190 <getValue+0x50>
mov    0xc(%rsp),%eax
cmp    $0x1,%eax
sbb    %ecx,%ecx
or     %eax,%ecx
jmp    11ec <getValue+0xac>
xor    %ecx,%ecx
jmp    11ec <getValue+0xac>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [46 x i8] c"Input sintatticamente non valido. Riprovare: \00"
define i32 @getValue() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca i8*
store i32 0, i32* %3
br label %6
6: ; preds = %37, %0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32* @fgets(i8* %7, i32 100, i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %6
store i32 -1, i32* %1
br label %49
12: ; preds = %6
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = call i8* @trim(i8* %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 0, i32* %1
br label %49
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i64 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 32
br label %28
28: ; preds = %22, %18
%29 = phi i1 [ false, %18 ], [ %27, %22 ]
%30 = zext i1 %29 to i32
store i32 %30, i32* %3
br label %31
31: ; preds = %28
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
br label %37
37: ; preds = %36
%38 = load i32, i32* %3
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
br i1 %40, label %6, label %41
41: ; preds = %37
%42 = load i32, i32* %2
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
br label %47
45: ; preds = %41
%46 = load i32, i32* %2
br label %47
47: ; preds = %45, %44
%48 = phi i32 [ -1, %44 ], [ %46, %45 ]
store i32 %48, i32* %1
br label %49
49: ; preds = %47, %17, %11
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [46 x i8] c"Input sintatticamente non valido. Riprovare: \00"
define i32 @getValue() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %4, i32 100, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %26, label %8
8: ; preds = %0, %17
%9 = call i8* @trim(i8* %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %26, label %11
11: ; preds = %8
%12 = call i64 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i8, i8* %9
%16 = icmp eq i8 %15, 32
br i1 %16, label %17, label %22
17: ; preds = %11, %14
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @stdin
%20 = call i32* @fgets(i8* %4, i32 100, i32 %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %26, label %8
22: ; preds = %14
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 -1, i32 %23
br label %26
26: ; preds = %17, %8, %0, %22
%27 = phi i32 [ %25, %22 ], [ -1, %0 ], [ -1, %17 ], [ 0, %8 ]
ret i32 %27
}