#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*/ getLine(char *, int);
int isValidIntegerString(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int getValidInteger() {
  char str[9];
  int result = 0;
  int validInt = 0;
  getLine(str, 9);
  while (validInt == 0) {
    validInt = isValidIntegerString(str);
    if (validInt == 0) {
      printf("Error - Please enter a valid number: ");
      getLine(str, 9);
    }
  }
  sscanf(str, "%d", &result);
  return result;
}


x86 assembly (clang, -O0):
<getValidInteger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x9(%rbp),%rdi
mov    $0x9,%esi
call   1060 <getLine@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11a3 <getValidInteger+0x63>
lea    -0x9(%rbp),%rdi
call   1040 <isValidIntegerString@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    119e <getValidInteger+0x5e>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
lea    -0x9(%rbp),%rdi
mov    $0x9,%esi
call   1060 <getLine@plt>
jmp    1164 <getValidInteger+0x24>
lea    -0x9(%rbp),%rdi
lea    0xe78(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getValidInteger>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x8(%rsp)
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1060 <getLine@plt>
mov    %rbx,%rdi
call   1040 <isValidIntegerString@plt>
test   %eax,%eax
jne    11a1 <getValidInteger+0x61>
lea    0xe8c(%rip),%r14
lea    0xf(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
call   1060 <getLine@plt>
mov    %rbx,%rdi
call   1040 <isValidIntegerString@plt>
test   %eax,%eax
je     1180 <getValidInteger+0x40>
lea    0xe7e(%rip),%rsi
lea    0xf(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1050 <sscanf@plt>
mov    0x8(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Error - Please enter a valid number: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @getValidInteger() {
%1 = alloca [9 x i8]
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %3
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%5 = call i32 @getLine(i8* %4, i32 9)
br label %6
6: ; preds = %18, %0
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%11 = call i32 @isValidIntegerString(i8* %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%17 = call i32 @getLine(i8* %16, i32 9)
br label %18
18: ; preds = %14, %9
br label %6
19: ; preds = %6
%20 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [38 x i8] c"Error - Please enter a valid number: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @getValidInteger() {
%1 = alloca [9 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = call i32 @getLine(i8* %3, i32 9)
%6 = call i32 @isValidIntegerString(i8* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0, %8
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @getLine(i8* %3, i32 9)
%11 = call i32 @isValidIntegerString(i8* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %8, label %13
13: ; preds = %8, %0
%14 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
ret i32 %15
}