#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 ValidateUPC(char *, int);
char getchar();
scalar_t__ isdigit(char);
scalar_t__ isspace(char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
int main(void) {
  char upcDigitsArray[12] = {0};
  int isInputValid = 0;
  int isUPCValid = 0;
  printf("Please enter the UPC to check it for validity: ");
  while (!isInputValid) {
    isInputValid = 1;
    int i = 0;
    char c = '\0';
    while ((c = getchar()) && isspace(c))
      continue;
    ungetc(c, stdin);
    while ((c = getchar()) != '\n' && c != EOF) {
      if (isdigit(c) && i < 12) {
        upcDigitsArray[i] = c;
        ++i;
      } else {
        isInputValid = 0;
      }
    }
    if (i != 12) {
      isInputValid = 0;
    }
    if (!isInputValid) {
      puts("Input invalid. Please try again.");
    }
  }
  isUPCValid = ValidateUPC(upcDigitsArray, 12);
  if (isUPCValid) {
    puts("VALID");
  } else {
    puts("INVALID");
  }
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cf <main+0x4f>
jmp    12e7 <main+0x167>
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    $0x0,%ecx
mov    %al,-0x1e(%rbp)
je     120f <main+0x8f>
movsbl -0x1d(%rbp),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    121f <main+0x9f>
jmp    1224 <main+0xa4>
jmp    11e1 <main+0x61>
mov    -0x1d(%rbp),%al
mov    0x2dba(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   10a0 <ungetc@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1f(%rbp)
je     1269 <main+0xe9>
movsbl -0x1d(%rbp),%eax
mov    0x2d82(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1f(%rbp)
mov    -0x1f(%rbp),%al
test   $0x1,%al
jne    1279 <main+0xf9>
jmp    12bb <main+0x13b>
movsbl -0x1d(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     12af <main+0x12f>
cmpl   $0xc,-0x1c(%rbp)
jge    12af <main+0x12f>
mov    -0x1d(%rbp),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x10(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b6 <main+0x136>
movl   $0x0,-0x14(%rbp)
jmp    1238 <main+0xb8>
cmpl   $0xc,-0x1c(%rbp)
je     12cc <main+0x14c>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    12e2 <main+0x162>
lea    0xd53(%rip),%rdi
call   1040 <puts@plt>
jmp    11b9 <main+0x39>
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   1090 <ValidateUPC@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1313 <main+0x193>
lea    0xd4a(%rip),%rdi
call   1040 <puts@plt>
jmp    131f <main+0x19f>
lea    0xd37(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e46(%rip),%r15
mov    0x2e37(%rip),%r12
lea    0xe80(%rip),%r14
jmp    11c8 <main+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
movsbl %al,%ebx
test   %al,%al
je     11e2 <main+0x72>
mov    %ebx,%edi
call   1060 <isspace@plt>
test   %rax,%rax
jne    11c8 <main+0x58>
mov    (%r15),%esi
mov    %ebx,%edi
call   1090 <ungetc@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     11c0 <main+0x50>
mov    %eax,%ebx
cmp    (%r12),%al
je     11c0 <main+0x50>
mov    $0x1,%r13d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl %bl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1230 <main+0xc0>
cmp    $0xb,%ebp
jg     1230 <main+0xc0>
movslq %ebp,%rax
mov    %bl,0x8(%rsp,%rax,1)
add    $0x1,%ebp
jmp    1233 <main+0xc3>
xchg   %ax,%ax
xor    %r13d,%r13d
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     1246 <main+0xd6>
mov    %eax,%ebx
cmp    (%r12),%al
jne    1210 <main+0xa0>
cmp    $0xc,%ebp
jne    11c0 <main+0x50>
test   %r13d,%r13d
je     11c0 <main+0x50>
lea    0x8(%rsp),%rdi
mov    $0xc,%esi
call   1080 <ValidateUPC@plt>
test   %eax,%eax
lea    0xde1(%rip),%rax
lea    0xddc(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"Please enter the UPC to check it for validity: \00"
@stdin = global i32 0
@EOF = global i8 0
@.str.1 = [33 x i8] c"Input invalid. Please try again.\00"
@.str.2 = [6 x i8] c"VALID\00"
@.str.3 = [8 x i8] c"INVALID\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
%7 = bitcast [12 x i8]* %2 to i8*
store i32 0, i32* %3
store i32 0, i32* %4
%8 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %66, %0
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %67
13: ; preds = %9
store i32 1, i32* %3
store i32 0, i32* %5
store i8 0, i8* %6
br label %14
14: ; preds = %24, %13
%15 = call signext i8 (...) @getchar()
store i8 %15, i8* %6
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i8, i8* %6
%20 = call i64 @isspace(i8 signext %19)
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %18, %14
%23 = phi i1 [ false, %14 ], [ %21, %18 ]
br i1 %23, label %24, label %25
24: ; preds = %22
br label %14
25: ; preds = %22
%26 = load i8, i8* %6
%27 = load i32, i32* @stdin
%28 = call i32 @ungetc(i8 signext %26, i32 %27)
br label %29
29: ; preds = %56, %25
%30 = call signext i8 (...) @getchar()
store i8 %30, i8* %6
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i8, i8* %6
%35 = sext i8 %34 to i32
%36 = load i8, i8* @EOF
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %35, %37
br label %39
39: ; preds = %33, %29
%40 = phi i1 [ false, %29 ], [ %38, %33 ]
br i1 %40, label %41, label %57
41: ; preds = %39
%42 = load i8, i8* %6
%43 = call i64 @isdigit(i8 signext %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %55
45: ; preds = %41
%46 = load i32, i32* %5
%47 = icmp slt i32 %46, 12
br i1 %47, label %48, label %55
48: ; preds = %45
%49 = load i8, i8* %6
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 %51
store i8 %49, i8* %52
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %56
55: ; preds = %45, %41
store i32 0, i32* %3
br label %56
56: ; preds = %55, %48
br label %29
57: ; preds = %39
%58 = load i32, i32* %5
%59 = icmp ne i32 %58, 12
br i1 %59, label %60, label %61
60: ; preds = %57
store i32 0, i32* %3
br label %61
61: ; preds = %60, %57
%62 = load i32, i32* %3
%63 = icmp ne i32 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %61
%65 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %66
66: ; preds = %64, %61
br label %9
67: ; preds = %9
%68 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%69 = call i32 @ValidateUPC(i8* %68, i32 12)
store i32 %69, i32* %4
%70 = load i32, i32* %4
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %76
74: ; preds = %67
%75 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %76
76: ; preds = %74, %72
%77 = call signext i8 (...) @getchar()
%78 = load i32, i32* @EXIT_SUCCESS
ret i32 %78
}

LLVM IR (-O2):
@.str = [48 x i8] c"Please enter the UPC to check it for validity: \00"
@stdin = global i32 0
@EOF = global i8 0
@.str.1 = [33 x i8] c"Input invalid. Please try again.\00"
@.str.2 = [6 x i8] c"VALID\00"
@.str.3 = [8 x i8] c"INVALID\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %10, %0
%5 = tail call signext i8 (...) @getchar()
%6 = icmp eq i8 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i64 @isspace(i8 signext %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %7, %43
br label %4
11: ; preds = %4, %7
%12 = load i32, i32* @stdin
%13 = tail call i32 @ungetc(i8 signext %5, i32 %12)
%14 = tail call signext i8 (...) @getchar()
%15 = icmp ne i8 %14, 10
%16 = load i8, i8* @EOF
%17 = icmp ne i8 %14, %16
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %19, label %43
19: ; preds = %11, %31
%20 = phi i8 [ %34, %31 ], [ %14, %11 ]
%21 = phi i32 [ %33, %31 ], [ 0, %11 ]
%22 = phi i32 [ %32, %31 ], [ 1, %11 ]
%23 = tail call i64 @isdigit(i8 signext %20)
%24 = icmp ne i64 %23, 0
%25 = icmp slt i32 %21, 12
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %31
27: ; preds = %19
%28 = sext i32 %21 to i64
%29 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %28
store i8 %20, i8* %29
%30 = add nsw i32 %21, 1
br label %31
31: ; preds = %19, %27
%32 = phi i32 [ %22, %27 ], [ 0, %19 ]
%33 = phi i32 [ %30, %27 ], [ %21, %19 ]
%34 = tail call signext i8 (...) @getchar()
%35 = icmp ne i8 %34, 10
%36 = load i8, i8* @EOF
%37 = icmp ne i8 %34, %36
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %19, label %39
39: ; preds = %31
%40 = icmp ne i32 %33, 12
%41 = icmp eq i32 %32, 0
%42 = select i1 %40, i1 true, i1 %41
br i1 %42, label %43, label %45
43: ; preds = %11, %39
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %10
45: ; preds = %39
%46 = call i32 @ValidateUPC(i8* %2, i32 12)
%47 = icmp eq i32 %46, 0
%48 = select i1 %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%49 = call i32 @puts(i8* dereferenceable(1) %48)
%50 = call signext i8 (...) @getchar()
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}