#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 sum_even_numbers(int *, int);
int sum_odd_numbers(int *, int);
int main(void) {
  int barcode[12] = {0, 7, 9, 4, 0, 0, 8, 0, 4, 5, 0, 1};
  int sum1, sum2, last_digit, check_digit;
  sum1 = sum_odd_numbers(barcode, 12);
  sum2 = sum_even_numbers(barcode, 12);
  last_digit = (sum1 * 3 + sum2) % 10;
  check_digit = (last_digit == 0 ? 0 : 10 - last_digit);
  if (check_digit == barcode[11]) {
    printf("Barcode validated!\n");
  } else {
    printf("Barcode invalid!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x30,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   1040 <sum_odd_numbers@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   1060 <sum_even_numbers@plt>
mov    %eax,-0x48(%rbp)
imul   $0x3,-0x44(%rbp),%eax
add    -0x48(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    11ac <main+0x6c>
xor    %eax,%eax
mov    %eax,-0x54(%rbp)
jmp    11b7 <main+0x77>
mov    $0xa,%eax
sub    -0x4c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11da <main+0x9a>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
jmp    11e6 <main+0xa6>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xee2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeaa(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1040 <sum_odd_numbers@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0xc,%esi
call   1050 <sum_even_numbers@plt>
lea    (%rbx,%rbx,2),%ecx
add    %eax,%ecx
movslq %ecx,%rax
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    %ecx,%eax
mov    $0xa,%ecx
sub    %eax,%ecx
test   %eax,%eax
cmove  %eax,%ecx
cmp    0x2c(%rsp),%ecx
lea    0xe8e(%rip),%rax
lea    0xe76(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.barcode = [12 x i32] [i32 0, i32 7, i32 9, i32 4, i32 0, i32 0, i32 8, i32 0, i32 4, i32 5, i32 0, i32 1]
@.str = [20 x i8] c"Barcode validated!\0A\00"
@.str.1 = [18 x i8] c"Barcode invalid!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [12 x i32]* %2 to i8*
%8 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%9 = call i32 @sum_odd_numbers(i32* %8, i32 12)
store i32 %9, i32* %3
%10 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%11 = call i32 @sum_even_numbers(i32* %10, i32 12)
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = mul nsw i32 %12, 3
%14 = load i32, i32* %4
%15 = add nsw i32 %13, %14
%16 = srem i32 %15, 10
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %0
br label %23
20: ; preds = %0
%21 = load i32, i32* %5
%22 = sub nsw i32 10, %21
br label %23
23: ; preds = %20, %19
%24 = phi i32 [ 0, %19 ], [ %22, %20 ]
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 11
%27 = load i32, i32* %26
%28 = icmp eq i32 %25, %27
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %33
31: ; preds = %23
%32 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
ret i32 0
}

LLVM IR (-O2):
@__const.main.barcode = [12 x i32] [i32 0, i32 7, i32 9, i32 4, i32 0, i32 0, i32 8, i32 0, i32 4, i32 5, i32 0, i32 1]
@str = [17 x i8] c"Barcode invalid!\00"
@str.2 = [19 x i8] c"Barcode validated!\00"
define i32 @main() {
%1 = alloca [12 x i32]
%2 = bitcast [12 x i32]* %1 to i8*
%3 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 0
%4 = call i32 @sum_odd_numbers(i32* %3, i32 12)
%5 = call i32 @sum_even_numbers(i32* %3, i32 12)
%6 = mul nsw i32 %4, 3
%7 = add nsw i32 %6, %5
%8 = srem i32 %7, 10
%9 = icmp eq i32 %8, 0
%10 = sub nsw i32 10, %8
%11 = select i1 %9, i32 0, i32 %10
%12 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 11
%13 = load i32, i32* %12
%14 = icmp eq i32 %11, %13
%15 = select i1 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0)
%16 = call i32 @puts(i8* dereferenceable(1) %15)
ret i32 0
}