#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*/ answ;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int /*<<< orphan*/, char *, int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int ask_value(char *format, int default_answer) {
  char answ[512];
  int len, num;
play_it_again_Sam:
  if ((len = read(0, answ, sizeof(answ))) < 1) {
    fprintf(stderr, "\n\nERROR! Cannot read stdin\n");
    perror("stdin");
    printf("invalid_configuration__run_make_config_again\n");
    exit(-1);
  }
  if (len < 2)
    return default_answer;
  answ[len - 1] = 0;
  if (sscanf(answ, format, &num) != 1) {
    fprintf(stderr, "Illegal format. Try again: ");
    goto play_it_again_Sam;
  }
  return num;
}


x86 assembly (clang, -O0):
<ask_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x220(%rbp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,-0x224(%rbp)
cmp    $0x1,%eax
jge    11cb <ask_value+0x6b>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe6c(%rip),%rdi
call   1070 <perror@plt>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
cmpl   $0x2,-0x224(%rbp)
jge    11e3 <ask_value+0x83>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1239 <ask_value+0xd9>
mov    -0x224(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x228(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1230 <ask_value+0xd0>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1172 <ask_value+0x12>
mov    -0x228(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x10(%rsp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11ef <ask_value+0x8f>
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%r15
mov    0x2e43(%rip),%r13
lea    0xe7e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x1,%eax
je     122b <ask_value+0xcb>
add    $0xffffffff,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1226 <ask_value+0xc6>
mov    0x0(%r13),%edi
mov    %r12,%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     11b0 <ask_value+0x50>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0xc(%rsp),%r14d
mov    %r14d,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"\0A\0AERROR! Cannot read stdin\0A\00"
@.str.1 = [6 x i8] c"stdin\00"
@.str.2 = [46 x i8] c"invalid_configuration__run_make_config_again\0A\00"
@.str.3 = [28 x i8] c"Illegal format. Try again: \00"
define i32 @ask_value(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
br label %9
9: ; preds = %33, %2
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%11 = call i32 @read(i32 0, i8* %10, i32 512)
store i32 %11, i32* %7
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %9
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i32, i32* %5
store i32 %23, i32* %3
br label %38
24: ; preds = %19
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%30 = load i8*, i8** %4
%31 = call i32 @sscanf(i8* %29, i8* %30, i32* %8)
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %9
36: ; preds = %24
%37 = load i32, i32* %8
store i32 %37, i32* %3
br label %38
38: ; preds = %36, %22
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"\0A\0AERROR! Cannot read stdin\0A\00"
@.str.1 = [6 x i8] c"stdin\00"
@.str.3 = [28 x i8] c"Illegal format. Try again: \00"
@str = [45 x i8] c"invalid_configuration__run_make_config_again\00"
define i32 @ask_value(i8* nocapture %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = call i32 @read(i32 0, i8* %5, i32 512)
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %15
9: ; preds = %24, %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2, %24
%16 = phi i32 [ %27, %24 ], [ %7, %2 ]
%17 = icmp eq i32 %16, 1
br i1 %17, label %31, label %18
18: ; preds = %15
%19 = add nsw i32 %16, -1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 @sscanf(i8* %5, i8* %0, i32* %4)
%23 = icmp eq i32 %22, 1
br i1 %23, label %29, label %24
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @read(i32 0, i8* %5, i32 512)
%28 = icmp slt i32 %27, 1
br i1 %28, label %9, label %15
29: ; preds = %18
%30 = load i32, i32* %4
br label %31
31: ; preds = %15, %29
%32 = phi i32 [ %30, %29 ], [ %1, %15 ]
ret i32 %32
}