#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 */
char EOF;
int EXIT_SUCCESS;
int UpcComputeCheckDigit(char *, int);
char getchar();
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int main(void) {
  char upcDigitsArray[11] = {0};
  int isInputValid = 0;
  int checkDigit = -1;
  printf("Please enter the first %d digits of a UPC: ", 11);
  while (!isInputValid) {
    isInputValid = 1;
    int i = 0;
    char c = '\0';
    while ((c = getchar()) != '\n' && c != EOF) {
      if (isdigit(c) && i < 11) {
        upcDigitsArray[i] = c;
        ++i;
      } else {
        isInputValid = 0;
      }
    }
    if (i != 11) {
      isInputValid = 0;
    }
    if (!isInputValid) {
      puts("Input invalid. Please try again.");
    }
  }
  checkDigit = UpcComputeCheckDigit(upcDigitsArray, 11);
  printf("Check digit: %d\n", checkDigit);
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xf(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1070 <memset@plt>
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
lea    0xe6c(%rip),%rdi
mov    $0xb,%esi
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b4 <main+0x54>
jmp    1275 <main+0x115>
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1e(%rbp)
je     11f7 <main+0x97>
movsbl -0x1d(%rbp),%eax
mov    0x2dfc(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    1207 <main+0xa7>
jmp    1249 <main+0xe9>
movsbl -0x1d(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     123d <main+0xdd>
cmpl   $0xb,-0x1c(%rbp)
jge    123d <main+0xdd>
mov    -0x1d(%rbp),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0xf(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1244 <main+0xe4>
movl   $0x0,-0x14(%rbp)
jmp    11c6 <main+0x66>
cmpl   $0xb,-0x1c(%rbp)
je     125a <main+0xfa>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1270 <main+0x110>
lea    0xdc1(%rip),%rdi
call   1040 <puts@plt>
jmp    119e <main+0x3e>
lea    -0xf(%rbp),%rdi
mov    $0xb,%esi
call   1060 <UpcComputeCheckDigit@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdbd(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x7(%rsp)
movq   $0x0,(%rsp)
lea    0xe8d(%rip),%rdi
mov    $0xb,%esi
call   1050 <printf@plt>
mov    0x2e64(%rip),%r15
lea    0xea1(%rip),%r14
jmp    1198 <main+0x48>
nopl   (%rax)
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     1190 <main+0x40>
mov    %eax,%ebx
cmp    (%r15),%al
je     1190 <main+0x40>
mov    $0x1,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %bl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11e0 <main+0x90>
cmp    $0xa,%ebp
jg     11e0 <main+0x90>
movslq %ebp,%rax
mov    %bl,(%rsp,%rax,1)
add    $0x1,%ebp
jmp    11e3 <main+0x93>
nopl   (%rax)
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     11f5 <main+0xa5>
mov    %eax,%ebx
cmp    (%r15),%al
jne    11c0 <main+0x70>
cmp    $0xb,%ebp
jne    1190 <main+0x40>
test   %r12d,%r12d
je     1190 <main+0x40>
mov    %rsp,%rdi
mov    $0xb,%esi
call   1060 <UpcComputeCheckDigit@plt>
lea    0xe3a(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Please enter the first %d digits of a UPC: \00"
@EOF = global i8 0
@.str.1 = [33 x i8] c"Input invalid. Please try again.\00"
@.str.2 = [17 x i8] c"Check digit: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
%7 = bitcast [11 x i8]* %2 to i8*
store i32 0, i32* %3
store i32 -1, i32* %4
%8 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 11)
br label %9
9: ; preds = %51, %0
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %52
13: ; preds = %9
store i32 1, i32* %3
store i32 0, i32* %5
store i8 0, i8* %6
br label %14
14: ; preds = %41, %13
%15 = call signext i8 (...) @getchar()
store i8 %15, i8* %6
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br label %24
24: ; preds = %18, %14
%25 = phi i1 [ false, %14 ], [ %23, %18 ]
br i1 %25, label %26, label %42
26: ; preds = %24
%27 = load i8, i8* %6
%28 = call i64 @isdigit(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %26
%31 = load i32, i32* %5
%32 = icmp slt i32 %31, 11
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i8, i8* %6
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %36
store i8 %34, i8* %37
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %41
40: ; preds = %30, %26
store i32 0, i32* %3
br label %41
41: ; preds = %40, %33
br label %14
42: ; preds = %24
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 11
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 0, i32* %3
br label %46
46: ; preds = %45, %42
%47 = load i32, i32* %3
%48 = icmp ne i32 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %46
%50 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
br label %9
52: ; preds = %9
%53 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%54 = call i32 @UpcComputeCheckDigit(i8* %53, i32 11)
store i32 %54, i32* %4
%55 = load i32, i32* %4
%56 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = call signext i8 (...) @getchar()
%58 = load i32, i32* @EXIT_SUCCESS
ret i32 %58
}

LLVM IR (-O2):
@.str = [44 x i8] c"Please enter the first %d digits of a UPC: \00"
@EOF = global i8 0
@.str.1 = [33 x i8] c"Input invalid. Please try again.\00"
@.str.2 = [17 x i8] c"Check digit: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [11 x i8]
%2 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 11)
br label %4
4: ; preds = %34, %0
%5 = tail call signext i8 (...) @getchar()
%6 = icmp ne i8 %5, 10
%7 = load i8, i8* @EOF
%8 = icmp ne i8 %5, %7
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %34
10: ; preds = %4, %22
%11 = phi i8 [ %25, %22 ], [ %5, %4 ]
%12 = phi i32 [ %24, %22 ], [ 0, %4 ]
%13 = phi i32 [ %23, %22 ], [ 1, %4 ]
%14 = tail call i64 @isdigit(i8 signext %11)
%15 = icmp ne i64 %14, 0
%16 = icmp slt i32 %12, 11
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 %19
store i8 %11, i8* %20
%21 = add nsw i32 %12, 1
br label %22
22: ; preds = %10, %18
%23 = phi i32 [ %13, %18 ], [ 0, %10 ]
%24 = phi i32 [ %21, %18 ], [ %12, %10 ]
%25 = tail call signext i8 (...) @getchar()
%26 = icmp ne i8 %25, 10
%27 = load i8, i8* @EOF
%28 = icmp ne i8 %25, %27
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %10, label %30
30: ; preds = %22
%31 = icmp ne i32 %24, 11
%32 = icmp eq i32 %23, 0
%33 = select i1 %31, i1 true, i1 %32
br i1 %33, label %34, label %36
34: ; preds = %4, %30
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %4
36: ; preds = %30
%37 = call i32 @UpcComputeCheckDigit(i8* %2, i32 11)
%38 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = call signext i8 (...) @getchar()
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}