#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*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *, int *, int *, int *, int *, int *,
                         int *, int *, int *, int *, int *, int *);
int main(void) {
  int d1, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5, first_sum, second_sum, d2,
      check_digit;
  printf("Enter the UPC as a 12 digit number, with no dashes or seperators: ");
  scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &d1, &i1, &i2, &i3, &i4, &i5,
        &j1, &j2, &j3, &j4, &j5, &d2);
  first_sum = d1 + i2 + i4 + j1 + j3 + j5;
  second_sum = i1 + i3 + i5 + j2 + j4;
  check_digit = 9 - (first_sum * 3 + second_sum - 1) % 10;
  if (check_digit == d2) {
    printf("VALID");
  } else {
    printf("NOT VALID");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
movl   $0x0,-0x24(%rbp)
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
lea    0xef7(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x34(%rbp),%r8
lea    -0x38(%rbp),%r9
lea    -0x3c(%rbp),%r12
lea    -0x40(%rbp),%r15
lea    -0x44(%rbp),%r14
lea    -0x48(%rbp),%rbx
lea    -0x4c(%rbp),%r11
lea    -0x50(%rbp),%r10
lea    -0x5c(%rbp),%rax
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1040 <scanf@plt>
mov    -0x28(%rbp),%eax
add    -0x30(%rbp),%eax
add    -0x38(%rbp),%eax
add    -0x40(%rbp),%eax
add    -0x48(%rbp),%eax
add    -0x50(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x34(%rbp),%eax
add    -0x3c(%rbp),%eax
add    -0x44(%rbp),%eax
add    -0x4c(%rbp),%eax
mov    %eax,-0x58(%rbp)
imul   $0x3,-0x54(%rbp),%eax
add    -0x58(%rbp),%eax
sub    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0x9,%eax
sub    %edx,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jne    1203 <main+0xe3>
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
jmp    120f <main+0xef>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
sub    $0x8,%rsp
lea    0x10(%rsp),%rax
lea    0x14(%rsp),%r10
lea    0x18(%rsp),%r11
lea    0x1c(%rsp),%rbx
lea    0x20(%rsp),%r14
lea    0x24(%rsp),%r15
lea    0x28(%rsp),%r12
lea    0xede(%rip),%rdi
lea    0x3c(%rsp),%rsi
lea    0x38(%rsp),%rdx
lea    0x34(%rsp),%rcx
lea    0x30(%rsp),%r8
lea    0x2c(%rsp),%r9
push   %rax
push   %r10
push   %r11
push   %rbx
push   %r14
push   %r15
push   %r12
call   1040 <scanf@plt>
add    $0x40,%rsp
mov    0x2c(%rsp),%eax
add    0x34(%rsp),%eax
add    0x24(%rsp),%eax
add    0x1c(%rsp),%eax
add    0x14(%rsp),%eax
add    0xc(%rsp),%eax
mov    0x30(%rsp),%ecx
mov    0x10(%rsp),%edx
lea    (%rax,%rax,2),%eax
add    0x28(%rsp),%ecx
add    %eax,%ecx
add    0x20(%rsp),%ecx
add    0x18(%rsp),%ecx
lea    (%rdx,%rcx,1),%eax
add    $0xffffffff,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %eax,%ecx
add    $0x9,%ecx
cmp    0x8(%rsp),%ecx
lea    0xe77(%rip),%rax
lea    0xe6c(%rip),%rdi
cmove  %rax,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [67 x i8] c"Enter the UPC as a 12 digit number, with no dashes or seperators: \00"
@.str.1 = [37 x i8] c"%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d\00"
@.str.2 = [6 x i8] c"VALID\00"
@.str.3 = [10 x i8] c"NOT VALID\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %1
%17 = call i32 @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %12, i32* %15)
%19 = load i32, i32* %2
%20 = load i32, i32* %4
%21 = add nsw i32 %19, %20
%22 = load i32, i32* %6
%23 = add nsw i32 %21, %22
%24 = load i32, i32* %8
%25 = add nsw i32 %23, %24
%26 = load i32, i32* %10
%27 = add nsw i32 %25, %26
%28 = load i32, i32* %12
%29 = add nsw i32 %27, %28
store i32 %29, i32* %13
%30 = load i32, i32* %3
%31 = load i32, i32* %5
%32 = add nsw i32 %30, %31
%33 = load i32, i32* %7
%34 = add nsw i32 %32, %33
%35 = load i32, i32* %9
%36 = add nsw i32 %34, %35
%37 = load i32, i32* %11
%38 = add nsw i32 %36, %37
store i32 %38, i32* %14
%39 = load i32, i32* %13
%40 = mul nsw i32 %39, 3
%41 = load i32, i32* %14
%42 = add nsw i32 %40, %41
%43 = sub nsw i32 %42, 1
%44 = srem i32 %43, 10
%45 = sub nsw i32 9, %44
store i32 %45, i32* %16
%46 = load i32, i32* %16
%47 = load i32, i32* %15
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %0
%50 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %53
51: ; preds = %0
%52 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51, %49
ret i32 0
}

LLVM IR (-O2):
@.str = [67 x i8] c"Enter the UPC as a 12 digit number, with no dashes or seperators: \00"
@.str.1 = [37 x i8] c"%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d\00"
@.str.2 = [6 x i8] c"VALID\00"
@.str.3 = [10 x i8] c"NOT VALID\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = bitcast i32* %1 to i8*
%14 = bitcast i32* %2 to i8*
%15 = bitcast i32* %3 to i8*
%16 = bitcast i32* %4 to i8*
%17 = bitcast i32* %5 to i8*
%18 = bitcast i32* %6 to i8*
%19 = bitcast i32* %7 to i8*
%20 = bitcast i32* %8 to i8*
%21 = bitcast i32* %9 to i8*
%22 = bitcast i32* %10 to i8*
%23 = bitcast i32* %11 to i8*
%24 = bitcast i32* %12 to i8*
%25 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %12)
%27 = load i32, i32* %1
%28 = load i32, i32* %3
%29 = add nsw i32 %28, %27
%30 = load i32, i32* %5
%31 = add nsw i32 %29, %30
%32 = load i32, i32* %7
%33 = add nsw i32 %31, %32
%34 = load i32, i32* %9
%35 = add nsw i32 %33, %34
%36 = load i32, i32* %11
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %2
%39 = load i32, i32* %4
%40 = load i32, i32* %6
%41 = load i32, i32* %8
%42 = load i32, i32* %10
%43 = mul nsw i32 %37, 3
%44 = add i32 %38, -1
%45 = add i32 %44, %39
%46 = add i32 %45, %43
%47 = add i32 %46, %40
%48 = add i32 %47, %41
%49 = add i32 %48, %42
%50 = srem i32 %49, 10
%51 = sub nsw i32 9, %50
%52 = load i32, i32* %12
%53 = icmp eq i32 %51, %52
%54 = select i1 %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0)
%55 = call i32 @printf(i8* dereferenceable(1) %54)
ret i32 0
}