#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("#undef CONFIGURE_SOUNDCARD\n");
    printf("#undef KERNEL_SOUNDCARD\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    11d7 <ask_value+0x77>
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>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
cmpl   $0x2,-0x224(%rbp)
jge    11ef <ask_value+0x8f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1245 <ask_value+0xe5>
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     123c <ask_value+0xdc>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%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    11f3 <ask_value+0x93>
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     123b <ask_value+0xdb>
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     1236 <ask_value+0xd6>
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    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
lea    0xe32(%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 = [28 x i8] c"#undef CONFIGURE_SOUNDCARD\0A\00"
@.str.3 = [25 x i8] c"#undef KERNEL_SOUNDCARD\0A\00"
@.str.4 = [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 = %34, %2
%10 = bitcast [512 x i8]* %6 to i8**
%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 %20
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 ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %9
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 2
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32, i32* %5
store i32 %24, i32* %3
br label %39
25: ; preds = %20
%26 = load i32, i32* %7
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%31 = load i8*, i8** %4
%32 = call i32 @sscanf(i8* %30, i8* %31, i32* %8)
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %9
37: ; preds = %25
%38 = load i32, i32* %8
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %23
%40 = load i32, i32* %3
ret i32 %40
}

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.4 = [28 x i8] c"Illegal format. Try again: \00"
@str = [27 x i8] c"#undef CONFIGURE_SOUNDCARD\00"
@str.5 = [24 x i8] c"#undef KERNEL_SOUNDCARD\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 = bitcast [512 x i8]* %3 to i8**
%8 = call i32 @read(i32 0, i8** %7, i32 512)
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %17
10: ; preds = %26, %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2, %26
%18 = phi i32 [ %29, %26 ], [ %8, %2 ]
%19 = icmp eq i32 %18, 1
br i1 %19, label %33, label %20
20: ; preds = %17
%21 = add nsw i32 %18, -1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
%24 = call i32 @sscanf(i8* %5, i8* %0, i32* %4)
%25 = icmp eq i32 %24, 1
br i1 %25, label %31, label %26
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @read(i32 0, i8** %7, i32 512)
%30 = icmp slt i32 %29, 1
br i1 %30, label %10, label %17
31: ; preds = %20
%32 = load i32, i32* %4
br label %33
33: ; preds = %17, %31
%34 = phi i32 [ %32, %31 ], [ %1, %17 ]
ret i32 %34
}