#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*/ sedb_message(char *, char *);
int sedb_read_line_in(char *, int /*<<< orphan*/, char *, char *, ...);
int sedb_get_int(char *value_name, int default_value) {
  static char answer[512];
  int i, j;
  char c;
  int result;
  int again;
  do {
    again = 0;
    result = 0;
    if (default_value > 0) {
      i = sedb_read_line_in(answer, 0, "%s = [%d]", value_name, default_value);
    } else {
      i = sedb_read_line_in(answer, 0, "%s = ", value_name);
    }
    if (i == 0) {
      result = default_value;
    } else {
      for (j = 0; j < i; j++) {
        c = answer[j];
        if (('0' <= c) && (c <= '9')) {
          result = (result * 10) + (c - '0');
        } else {
          sedb_message("Bad integer natural value: \"%s\".\n", answer);
          again = 1;
        }
      }
    }
  } while (again);
  return result;
}


x86 assembly (clang, -O0):
<sedb_get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    116e <sedb_get_int+0x4e>
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%r8d
lea    0x2eea(%rip),%rdi
xor    %esi,%esi
lea    0xea1(%rip),%rdx
mov    $0x0,%al
call   1040 <sedb_read_line_in@plt>
mov    %eax,-0x10(%rbp)
jmp    118c <sedb_get_int+0x6c>
mov    -0x8(%rbp),%rcx
lea    0x2ec7(%rip),%rdi
xor    %esi,%esi
lea    0xe88(%rip),%rdx
mov    $0x0,%al
call   1040 <sedb_read_line_in@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11a1 <sedb_get_int+0x81>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    122a <sedb_get_int+0x10a>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1225 <sedb_get_int+0x105>
movslq -0x14(%rbp),%rcx
lea    0x2e81(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     11f8 <sedb_get_int+0xd8>
movsbl -0x15(%rbp),%eax
cmp    $0x39,%eax
jg     11f8 <sedb_get_int+0xd8>
imul   $0xa,-0x1c(%rbp),%eax
movsbl -0x15(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    1212 <sedb_get_int+0xf2>
lea    0xe11(%rip),%rdi
lea    0x2e3a(%rip),%rsi
call   1030 <sedb_message@plt>
movl   $0x1,-0x20(%rbp)
jmp    1217 <sedb_get_int+0xf7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <sedb_get_int+0x88>
jmp    122a <sedb_get_int+0x10a>
jmp    122f <sedb_get_int+0x10f>
cmpl   $0x0,-0x20(%rbp)
jne    112f <sedb_get_int+0xf>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sedb_get_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,(%rsp)
lea    0x2f07(%rip),%rbx
lea    0xed0(%rip),%rbp
jmp    1158 <sedb_get_int+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %eax,%eax
je     11ed <sedb_get_int+0xcd>
mov    %rbx,%rdi
xor    %esi,%esi
test   %r12d,%r12d
jle    1180 <sedb_get_int+0x60>
lea    0xe97(%rip),%rdx
mov    (%rsp),%rcx
mov    %r12d,%r8d
xor    %eax,%eax
call   1040 <sedb_read_line_in@plt>
test   %eax,%eax
jne    1196 <sedb_get_int+0x76>
jmp    11e5 <sedb_get_int+0xc5>
nopl   (%rax)
lea    0xe83(%rip),%rdx
mov    (%rsp),%rcx
xor    %eax,%eax
call   1040 <sedb_read_line_in@plt>
test   %eax,%eax
je     11e5 <sedb_get_int+0xc5>
jle    11ea <sedb_get_int+0xca>
mov    %eax,%r15d
xor    %r14d,%r14d
xor    %eax,%eax
xor    %r13d,%r13d
jmp    11c9 <sedb_get_int+0xa9>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <sedb_message@plt>
mov    $0x1,%eax
add    $0x1,%r14
cmp    %r14,%r15
je     1150 <sedb_get_int+0x30>
movzbl (%r14,%rbx,1),%ecx
lea    -0x30(%rcx),%edx
cmp    $0x9,%dl
ja     11b0 <sedb_get_int+0x90>
lea    0x0(%r13,%r13,4),%edx
lea    (%rcx,%rdx,2),%r13d
add    $0xffffffd0,%r13d
jmp    11c0 <sedb_get_int+0xa0>
mov    %r12d,%r13d
jmp    11ed <sedb_get_int+0xcd>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@sedb_get_int.answer = internal global [512 x i8] zeroinitializer
@.str = [10 x i8] c"%s = [%d]\00"
@.str.1 = [6 x i8] c"%s = \00"
@.str.2 = [34 x i8] c"Bad integer natural value: \22%s\22.\0A\00"
define i32 @sedb_get_int(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %10
10: ; preds = %57, %2
store i32 0, i32* %9
store i32 0, i32* %8
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = call i32 (i8*, i32, i8*, i8*, ...) @sedb_read_line_in(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @sedb_get_int.answer, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15)
store i32 %16, i32* %5
br label %20
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = call i32 (i8*, i32, i8*, i8*, ...) @sedb_read_line_in(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @sedb_get_int.answer, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i32 %19, i32* %5
br label %20
20: ; preds = %17, %13
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32, i32* %4
store i32 %24, i32* %8
br label %56
25: ; preds = %20
store i32 0, i32* %6
br label %26
26: ; preds = %52, %25
%27 = load i32, i32* %6
%28 = load i32, i32* %5
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %55
30: ; preds = %26
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [512 x i8], [512 x i8]* @sedb_get_int.answer, i64 0, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %7
%35 = load i8, i8* %7
%36 = sext i8 %35 to i32
%37 = icmp sle i32 48, %36
br i1 %37, label %38, label %49
38: ; preds = %30
%39 = load i8, i8* %7
%40 = sext i8 %39 to i32
%41 = icmp sle i32 %40, 57
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i32, i32* %8
%44 = mul nsw i32 %43, 10
%45 = load i8, i8* %7
%46 = sext i8 %45 to i32
%47 = sub nsw i32 %46, 48
%48 = add nsw i32 %44, %47
store i32 %48, i32* %8
br label %51
49: ; preds = %38, %30
%50 = call i32 @sedb_message(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @sedb_get_int.answer, i64 0, i64 0))
store i32 1, i32* %9
br label %51
51: ; preds = %49, %42
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %26
55: ; preds = %26
br label %56
56: ; preds = %55, %23
br label %57
57: ; preds = %56
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 0
br i1 %59, label %10, label %60
60: ; preds = %57
%61 = load i32, i32* %8
ret i32 %61
}

LLVM IR (-O2):
@sedb_get_int.answer = internal global [512 x i8] zeroinitializer
@.str = [10 x i8] c"%s = [%d]\00"
@.str.1 = [6 x i8] c"%s = \00"
@.str.2 = [34 x i8] c"Bad integer natural value: \22%s\22.\0A\00"
define i32 @sedb_get_int(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br label %4
4: ; preds = %36, %2
br i1 %3, label %5, label %7
5: ; preds = %4
%6 = tail call i32 (i8*, i32, i8*, i8*, ...) @sedb_read_line_in(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @sedb_get_int.answer, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
br label %9
7: ; preds = %4
%8 = tail call i32 (i8*, i32, i8*, i8*, ...) @sedb_read_line_in(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @sedb_get_int.answer, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %5
%10 = phi i32 [ %6, %5 ], [ %8, %7 ]
%11 = icmp eq i32 %10, 0
br i1 %11, label %38, label %12
12: ; preds = %9
%13 = icmp sgt i32 %10, 0
br i1 %13, label %14, label %38
14: ; preds = %12
%15 = zext i32 %10 to i64
br label %16
16: ; preds = %14, %31
%17 = phi i64 [ 0, %14 ], [ %34, %31 ]
%18 = phi i32 [ 0, %14 ], [ %33, %31 ]
%19 = phi i32 [ 0, %14 ], [ %32, %31 ]
%20 = getelementptr inbounds [512 x i8], [512 x i8]* @sedb_get_int.answer, i64 0, i64 %17
%21 = load i8, i8* %20
%22 = add i8 %21, -48
%23 = icmp ult i8 %22, 10
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = zext i8 %21 to i32
%26 = mul nsw i32 %19, 10
%27 = add i32 %26, -48
%28 = add i32 %27, %25
br label %31
29: ; preds = %16
%30 = tail call i32 @sedb_message(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([512 x i8], [512 x i8]* @sedb_get_int.answer, i64 0, i64 0))
br label %31
31: ; preds = %24, %29
%32 = phi i32 [ %28, %24 ], [ %19, %29 ]
%33 = phi i32 [ %18, %24 ], [ 1, %29 ]
%34 = add nuw nsw i64 %17, 1
%35 = icmp eq i64 %34, %15
br i1 %35, label %36, label %16
36: ; preds = %31
%37 = icmp eq i32 %33, 0
br i1 %37, label %38, label %4
38: ; preds = %12, %9, %36
%39 = phi i32 [ %32, %36 ], [ %1, %9 ], [ 0, %12 ]
ret i32 %39
}