#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 */
char *ask4str(char const *);
int /*<<< orphan*/ show_msg(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
scalar_t__ strcspn(char *, char *);
int get_int(const char *prompt) {
  char *line;
  int n;
  if (!(*(line = ask4str(prompt))))
    return -1;
  if (strcspn(line, "-1234567890")) {
    show_msg("\aNot valid");
    return -1;
  }
  sscanf(line, "%d", &n);
  return n;
}


x86 assembly (clang, -O0):
<get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ask4str@plt>
mov    %rax,-0x18(%rbp)
cmpb   $0x0,(%rax)
jne    116e <get_int+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <get_int+0x7a>
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <strcspn@plt>
cmp    $0x0,%rax
je     11a0 <get_int+0x60>
lea    0xe7d(%rip),%rdi
call   1040 <show_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ba <get_int+0x7a>
mov    -0x18(%rbp),%rdi
lea    0xe6c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_int>:
push   %rbp
push   %rbx
push   %rax
call   1050 <ask4str@plt>
mov    $0xffffffff,%ebp
cmpb   $0x0,(%rax)
je     118f <get_int+0x4f>
mov    %rax,%rbx
lea    0xea4(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcspn@plt>
test   %rax,%rax
je     1177 <get_int+0x37>
lea    0xe9c(%rip),%rdi
call   1040 <show_msg@plt>
jmp    118f <get_int+0x4f>
lea    0xe99(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"-1234567890\00"
@.str.1 = [11 x i8] c"\07Not valid\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @get_int(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @ask4str(i8* %6)
store i8* %7, i8** %4
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 -1, i32* %2
br label %21
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i64 @strcspn(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @show_msg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %21
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%20 = load i32, i32* %5
store i32 %20, i32* %2
br label %21
21: ; preds = %17, %15, %10
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [12 x i8] c"-1234567890\00"
@.str.1 = [11 x i8] c"\07Not valid\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @get_int(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i8* @ask4str(i8* %0)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = tail call i64 @strcspn(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @show_msg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %15
12: ; preds = %7
%13 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
br label %15
15: ; preds = %1, %12, %10
%16 = phi i32 [ -1, %10 ], [ %14, %12 ], [ -1, %1 ]
ret i32 %16
}