#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*/ clear();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *, char *);
void inputQuantity(const char *prompt, int qty[], int i) {
  char endInput;
  int result = 0;
  int read;
  do {
    printf("%s", prompt);
    read = scanf("%d%c", &qty[i], &endInput);
    if (read != 2) {
      printf("ERROR! Try Again!\n");
      result = 0;
      clear();
    } else if (endInput != '\n') {
      printf("ERROR! Try Again!\n");
      result = 0;
      clear();
    } else if (qty[i] <= 0) {
      printf("ERROR! Try Again!\n");
      result = 0;
    } else
      result = 1;
  } while (result == 0);
}


x86 assembly (clang, -O0):
<inputQuantity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe91(%rip),%rdi
lea    -0x15(%rbp),%rdx
call   1040 <scanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
je     11a9 <inputQuantity+0x79>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <clear@plt>
jmp    1214 <inputQuantity+0xe4>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     11d7 <inputQuantity+0xa7>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <clear@plt>
jmp    120f <inputQuantity+0xdf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jg     1203 <inputQuantity+0xd3>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
jmp    120a <inputQuantity+0xda>
movl   $0x1,-0x1c(%rbp)
jmp    120f <inputQuantity+0xdf>
jmp    1214 <inputQuantity+0xe4>
jmp    1219 <inputQuantity+0xe9>
cmpl   $0x0,-0x1c(%rbp)
je     114a <inputQuantity+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputQuantity>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movslq %edx,%rax
lea    (%rsi,%rax,4),%rbx
lea    0xea4(%rip),%r15
lea    0xea0(%rip),%r12
lea    0x7(%rsp),%r13
lea    0xe99(%rip),%rbp
jmp    118f <inputQuantity+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <clear@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1050 <scanf@plt>
cmp    $0x2,%eax
jne    1180 <inputQuantity+0x40>
cmpb   $0xa,0x7(%rsp)
jne    1180 <inputQuantity+0x40>
cmpl   $0x0,(%rbx)
jg     11c5 <inputQuantity+0x85>
mov    %rbp,%rdi
call   1030 <puts@plt>
jmp    118f <inputQuantity+0x4f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%d%c\00"
@.str.2 = [19 x i8] c"ERROR! Try Again!\0A\00"
define void @inputQuantity(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %10
10: ; preds = %43, %3
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %5
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %16, i8* %7)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %10
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
%22 = call i32 (...) @clear()
br label %42
23: ; preds = %10
%24 = load i8, i8* %7
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
%29 = call i32 (...) @clear()
br label %41
30: ; preds = %23
%31 = load i32*, i32** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = icmp sle i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
br label %40
39: ; preds = %30
store i32 1, i32* %8
br label %40
40: ; preds = %39, %37
br label %41
41: ; preds = %40, %27
br label %42
42: ; preds = %41, %20
br label %43
43: ; preds = %42
%44 = load i32, i32* %8
%45 = icmp eq i32 %44, 0
br i1 %45, label %10, label %46
46: ; preds = %43
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"%d%c\00"
@str.4 = [18 x i8] c"ERROR! Try Again!\00"
define void @inputQuantity(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i32, i32* %1, i64 %5
br label %7
7: ; preds = %14, %3
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6, i8* %4)
%10 = icmp eq i32 %9, 2
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
%13 = call i32 (...) @clear()
br label %14
14: ; preds = %11, %24, %18
br label %7
15: ; preds = %7
%16 = load i8, i8* %4
%17 = icmp eq i8 %16, 10
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
%20 = call i32 (...) @clear()
br label %14
21: ; preds = %15
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
br label %14
26: ; preds = %21
ret void
}