#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 *, long long *);
int main(void) {
  long long UPC;
  int done = 0;
  int i;
  int comCode;
  int proCode;
  printf("UPC Validator\n");
  printf("==============\n");
  while (done != 1) {
    int value = 0;
    int even = 0;
    int odd = 0;
    int check = 0;
    int total = 0;
    printf("UPC (0 to quit): ");
    scanf("%lld", &UPC);
    comCode = UPC / 1000000;
    proCode = (UPC / 10) % 100000;
    if (UPC == 0) {
      done = 1;
    } else {
      for (i = 12; i >= 1; i--) {
        value = UPC % 10;
        if (i % 2 == 0 && i != 12) {
          even += value;
        } else if (i <= 11) {
          odd += value;
        } else {
          check = value;
        }
        UPC = UPC / 10;
      }
      total = (odd * 3) + even + check;
      if (total % 10 == 0) {
        printf("This is a valid UPC.\n");
        printf("The company code is %06d.\n", comCode);
        printf("The product code is %05d.\n", proCode);
      } else {
        printf("This is not a valid UPC.\n");
      }
    }
  }
  printf("Have a Nice Day!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x14(%rbp)
je     12e3 <main+0x1c3>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    $0x186a0,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e2 <main+0xc2>
movl   $0x1,-0x14(%rbp)
jmp    12de <main+0x1be>
movl   $0xc,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jl     1275 <main+0x155>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1232 <main+0x112>
cmpl   $0xc,-0x18(%rbp)
je     1232 <main+0x112>
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1255 <main+0x135>
cmpl   $0xb,-0x18(%rbp)
jg     124a <main+0x12a>
mov    -0x24(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1250 <main+0x130>
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1255 <main+0x135>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11e9 <main+0xc9>
imul   $0x3,-0x2c(%rbp),%eax
add    -0x28(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12cb <main+0x1ab>
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d9 <main+0x1b9>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12de <main+0x1be>
jmp    1152 <main+0x32>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf0b(%rip),%rdi
call   1030 <puts@plt>
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
movabs $0x6666666666666667,%r14
66 66 66
movabs $0x29f16b11c6d1e109,%r15
6b f1 29
jmp    117c <main+0x4c>
nopl   0x0(%rax)
lea    0xf04(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe81(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%rcx
mov    %rcx,%rax
movabs $0x431bde82d7b634db,%rdx
de 1b 43
imul   %rdx
mov    %rdx,%r12
mov    %rcx,%rax
imul   %r14
mov    %rdx,%r13
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%r13
add    %rax,%r13
mov    %r13,%rax
imul   %r15
test   %rcx,%rcx
je     12b5 <main+0x185>
mov    %r12,%rax
shr    $0x3f,%rax
shr    $0x12,%r12
add    %eax,%r12d
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0xe,%rdx
add    %eax,%edx
imul   $0x186a0,%edx,%eax
sub    %eax,%r13d
xor    %r8d,%r8d
mov    $0xd,%eax
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1226 <main+0xf6>
nopl   0x0(%rax,%rax,1)
cmp    $0xc,%eax
mov    $0x0,%edx
cmovb  %esi,%edx
cmovae %esi,%r8d
add    %edx,%ebp
cmp    $0x1,%eax
jbe    125d <main+0x12d>
mov    %rcx,%rsi
mov    %eax,%edi
mov    %rcx,%rax
imul   %r14
lea    -0x1(%rdi),%eax
mov    %rdx,%rcx
shr    $0x3f,%rdx
sar    $0x2,%rcx
add    %rdx,%rcx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%esi
cmp    $0xd,%edi
je     1210 <main+0xe0>
mov    %eax,%edx
and    $0x1,%edx
jne    1210 <main+0xe0>
add    %esi,%ebx
cmp    $0x1,%eax
ja     1226 <main+0xf6>
mov    %rcx,(%rsp)
lea    0x0(%rbp,%rbp,2),%eax
add    %ebx,%eax
add    %r8d,%eax
imul   $0xcccccccd,%eax,%eax
add    $0x19999998,%eax
ror    %eax
cmp    $0x19999998,%eax
ja     1170 <main+0x40>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
lea    0xd82(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd8c(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    117c <main+0x4c>
lea    0xdae(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"UPC Validator\0A\00"
@.str.1 = [16 x i8] c"==============\0A\00"
@.str.2 = [18 x i8] c"UPC (0 to quit): \00"
@.str.3 = [5 x i8] c"%lld\00"
@.str.4 = [22 x i8] c"This is a valid UPC.\0A\00"
@.str.5 = [27 x i8] c"The company code is %06d.\0A\00"
@.str.6 = [27 x i8] c"The product code is %05d.\0A\00"
@.str.7 = [26 x i8] c"This is not a valid UPC.\0A\00"
@.str.8 = [18 x i8] c"Have a Nice Day!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%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
store i32 0, i32* %1
store i32 0, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %83, %0
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %84
17: ; preds = %14
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64* %2)
%20 = load i64, i64* %2
%21 = sdiv i64 %20, 1000000
%22 = trunc i64 %21 to i32
store i32 %22, i32* %5
%23 = load i64, i64* %2
%24 = sdiv i64 %23, 10
%25 = srem i64 %24, 100000
%26 = trunc i64 %25 to i32
store i32 %26, i32* %6
%27 = load i64, i64* %2
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %17
store i32 1, i32* %3
br label %83
30: ; preds = %17
store i32 12, i32* %4
br label %31
31: ; preds = %61, %30
%32 = load i32, i32* %4
%33 = icmp sge i32 %32, 1
br i1 %33, label %34, label %64
34: ; preds = %31
%35 = load i64, i64* %2
%36 = srem i64 %35, 10
%37 = trunc i64 %36 to i32
store i32 %37, i32* %7
%38 = load i32, i32* %4
%39 = srem i32 %38, 2
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %34
%42 = load i32, i32* %4
%43 = icmp ne i32 %42, 12
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = add nsw i32 %46, %45
store i32 %47, i32* %8
br label %58
48: ; preds = %41, %34
%49 = load i32, i32* %4
%50 = icmp sle i32 %49, 11
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = load i32, i32* %7
%53 = load i32, i32* %9
%54 = add nsw i32 %53, %52
store i32 %54, i32* %9
br label %57
55: ; preds = %48
%56 = load i32, i32* %7
store i32 %56, i32* %10
br label %57
57: ; preds = %55, %51
br label %58
58: ; preds = %57, %44
%59 = load i64, i64* %2
%60 = sdiv i64 %59, 10
store i64 %60, i64* %2
br label %61
61: ; preds = %58
%62 = load i32, i32* %4
%63 = add nsw i32 %62, -1
store i32 %63, i32* %4
br label %31
64: ; preds = %31
%65 = load i32, i32* %9
%66 = mul nsw i32 %65, 3
%67 = load i32, i32* %8
%68 = add nsw i32 %66, %67
%69 = load i32, i32* %10
%70 = add nsw i32 %68, %69
store i32 %70, i32* %11
%71 = load i32, i32* %11
%72 = srem i32 %71, 10
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %80
74: ; preds = %64
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%76 = load i32, i32* %5
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %76)
%78 = load i32, i32* %6
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %78)
br label %82
80: ; preds = %64
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
br label %82
82: ; preds = %80, %74
br label %83
83: ; preds = %82, %29
br label %14
84: ; preds = %14
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [18 x i8] c"UPC (0 to quit): \00"
@.str.3 = [5 x i8] c"%lld\00"
@.str.5 = [27 x i8] c"The company code is %06d.\0A\00"
@.str.6 = [27 x i8] c"The product code is %05d.\0A\00"
@str = [14 x i8] c"UPC Validator\00"
@str.9 = [15 x i8] c"==============\00"
@str.10 = [17 x i8] c"Have a Nice Day!\00"
@str.11 = [25 x i8] c"This is not a valid UPC.\00"
@str.12 = [21 x i8] c"This is a valid UPC.\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.9, i64 0, i64 0))
br label %5
5: ; preds = %51, %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%8 = load i64, i64* %1
%9 = sdiv i64 %8, 1000000
%10 = trunc i64 %9 to i32
%11 = sdiv i64 %8, 10
%12 = srem i64 %11, 100000
%13 = trunc i64 %12 to i32
%14 = icmp eq i64 %8, 0
br i1 %14, label %54, label %15
15: ; preds = %5, %35
%16 = phi i32 [ %38, %35 ], [ 0, %5 ]
%17 = phi i32 [ %37, %35 ], [ 0, %5 ]
%18 = phi i32 [ %36, %35 ], [ 0, %5 ]
%19 = phi i32 [ %39, %35 ], [ 12, %5 ]
%20 = phi i64 [ %22, %35 ], [ %8, %5 ]
%21 = srem i64 %20, 10
%22 = sdiv i64 %20, 10
%23 = trunc i64 %21 to i32
%24 = and i32 %19, 1
%25 = icmp eq i32 %24, 0
%26 = icmp ne i32 %19, 12
%27 = and i1 %26, %25
br i1 %27, label %28, label %30
28: ; preds = %15
%29 = add nsw i32 %18, %23
br label %35
30: ; preds = %15
%31 = icmp ult i32 %19, 12
%32 = select i1 %31, i32 %23, i32 0
%33 = add nsw i32 %32, %17
%34 = select i1 %31, i32 %16, i32 %23
br label %35
35: ; preds = %30, %28
%36 = phi i32 [ %29, %28 ], [ %18, %30 ]
%37 = phi i32 [ %17, %28 ], [ %33, %30 ]
%38 = phi i32 [ %16, %28 ], [ %34, %30 ]
%39 = add nsw i32 %19, -1
%40 = icmp ugt i32 %19, 1
br i1 %40, label %15, label %41
41: ; preds = %35
store i64 %22, i64* %1
%42 = mul nsw i32 %37, 3
%43 = add nsw i32 %42, %36
%44 = add nsw i32 %43, %38
%45 = srem i32 %44, 10
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %41
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.12, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %10)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %13)
br label %51
51: ; preds = %47, %52
br label %5
52: ; preds = %41
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
br label %51
54: ; preds = %5
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0))
ret i32 0
}