#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() {
  int ean1 = 0;
  int ean2 = 0;
  int ean3 = 0;
  int ean4 = 0;
  int ean5 = 0;
  int ean6 = 0;
  int ean7 = 0;
  int ean8 = 0;
  int ean9 = 0;
  int ean10 = 0;
  int ean11 = 0;
  int ean12 = 0;
  int checkdigit = 0;
  int oddsum = 0;
  int evensum = 0;
  printf("Enter the first 12 digits of an EAN: ");
  scanf("%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d", &ean1, &ean2, &ean3,
        &ean4, &ean5, &ean6, &ean7, &ean8, &ean9, &ean10, &ean11, &ean12);
  evensum = ean2 + ean4 + ean6 + ean8 + ean10 + ean12;
  oddsum = ean1 + ean3 + ean5 + ean7 + ean9 + ean11;
  checkdigit = 9 - (((evensum * 3 + oddsum) - 1) % 10);
  printf("Check digit: %d\n", checkdigit);
  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)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6f(%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    -0x54(%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    -0x2c(%rbp),%eax
add    -0x34(%rbp),%eax
add    -0x3c(%rbp),%eax
add    -0x44(%rbp),%eax
add    -0x4c(%rbp),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x60(%rbp)
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,-0x5c(%rbp)
imul   $0x3,-0x60(%rbp),%eax
add    -0x5c(%rbp),%eax
sub    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    $0x9,%eax
sub    %edx,%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
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
movl   $0x0,0x34(%rsp)
movl   $0x0,0x30(%rsp)
movl   $0x0,0x2c(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0x0,0x24(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
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    0xe5f(%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    0x28(%rsp),%eax
add    0x30(%rsp),%eax
add    0x20(%rsp),%eax
add    0x18(%rsp),%eax
add    0x10(%rsp),%eax
add    0x8(%rsp),%eax
mov    0x34(%rsp),%ecx
mov    0xc(%rsp),%edx
lea    (%rax,%rax,2),%eax
add    0x2c(%rsp),%ecx
add    %eax,%ecx
add    0x24(%rsp),%ecx
add    0x1c(%rsp),%ecx
add    0x14(%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),%esi
sub    %eax,%esi
add    $0x9,%esi
lea    0xe00(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Enter the first 12 digits of an EAN: \00"
@.str.1 = [49 x i8] c"%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d\00"
@.str.2 = [17 x i8] c"Check digit: %d\0A\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
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
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
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([49 x i8], [49 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* %13)
%19 = load i32, i32* %3
%20 = load i32, i32* %5
%21 = add nsw i32 %19, %20
%22 = load i32, i32* %7
%23 = add nsw i32 %21, %22
%24 = load i32, i32* %9
%25 = add nsw i32 %23, %24
%26 = load i32, i32* %11
%27 = add nsw i32 %25, %26
%28 = load i32, i32* %13
%29 = add nsw i32 %27, %28
store i32 %29, i32* %16
%30 = load i32, i32* %2
%31 = load i32, i32* %4
%32 = add nsw i32 %30, %31
%33 = load i32, i32* %6
%34 = add nsw i32 %32, %33
%35 = load i32, i32* %8
%36 = add nsw i32 %34, %35
%37 = load i32, i32* %10
%38 = add nsw i32 %36, %37
%39 = load i32, i32* %12
%40 = add nsw i32 %38, %39
store i32 %40, i32* %15
%41 = load i32, i32* %16
%42 = mul nsw i32 %41, 3
%43 = load i32, i32* %15
%44 = add nsw i32 %42, %43
%45 = sub nsw i32 %44, 1
%46 = srem i32 %45, 10
%47 = sub nsw i32 9, %46
store i32 %47, i32* %14
%48 = load i32, i32* %14
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"Enter the first 12 digits of an EAN: \00"
@.str.1 = [49 x i8] c"%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d%01d\00"
@.str.2 = [17 x i8] c"Check digit: %d\0A\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*
store i32 0, i32* %1
%14 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%15 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%16 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%17 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%18 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%19 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%20 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%21 = bitcast i32* %9 to i8*
store i32 0, i32* %9
%22 = bitcast i32* %10 to i8*
store i32 0, i32* %10
%23 = bitcast i32* %11 to i8*
store i32 0, i32* %11
%24 = bitcast i32* %12 to i8*
store i32 0, i32* %12
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([49 x i8], [49 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* %2
%28 = load i32, i32* %4
%29 = add nsw i32 %28, %27
%30 = load i32, i32* %6
%31 = add nsw i32 %29, %30
%32 = load i32, i32* %8
%33 = add nsw i32 %31, %32
%34 = load i32, i32* %10
%35 = add nsw i32 %33, %34
%36 = load i32, i32* %12
%37 = add nsw i32 %35, %36
%38 = load i32, i32* %1
%39 = load i32, i32* %3
%40 = load i32, i32* %5
%41 = load i32, i32* %7
%42 = load i32, i32* %9
%43 = load i32, i32* %11
%44 = mul nsw i32 %37, 3
%45 = add i32 %38, -1
%46 = add i32 %45, %39
%47 = add i32 %46, %44
%48 = add i32 %47, %40
%49 = add i32 %48, %41
%50 = add i32 %49, %42
%51 = add i32 %50, %43
%52 = srem i32 %51, 10
%53 = sub nsw i32 9, %52
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %53)
ret i32 0
}