#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*/ isdigit(char);
int /*<<< orphan*/ strip_non_digits(char *, char *);
int strlen(char *);
int cc_chk_digit(char *cc_string) {
  char cc_number[80] = {0};
  int cc_number_size;
  int index;
  int weight = 2;
  int product;
  int current_number;
  int accummulator = 0;
  strip_non_digits(cc_number, cc_string);
  cc_number_size = strlen(cc_number);
  index = cc_number_size - 2;
  if (cc_number_size < 10 || cc_number_size > 16)
    return 0;
  for (; index >= 0; index--) {
    if (!isdigit(cc_number[index]))
      continue;
    current_number = cc_number[index] - 48;
    product = current_number * weight;
    accummulator += product / 10;
    accummulator += product % 10;
    if (weight == 2)
      weight = 1;
    else
      weight = 2;
  }
  accummulator %= 10;
  accummulator = 10 - accummulator;
  if (accummulator == 10)
    accummulator = 0;
  if (accummulator == (cc_number[cc_number_size - 1] - 48))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<cc_chk_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
movl   $0x2,-0x6c(%rbp)
movl   $0x0,-0x78(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strip_non_digits@plt>
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x68(%rbp)
cmpl   $0xa,-0x64(%rbp)
jl     11a3 <cc_chk_digit+0x63>
cmpl   $0x10,-0x64(%rbp)
jle    11af <cc_chk_digit+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    129e <cc_chk_digit+0x15e>
jmp    11b4 <cc_chk_digit+0x74>
cmpl   $0x0,-0x68(%rbp)
jl     1245 <cc_chk_digit+0x105>
movslq -0x68(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    11da <cc_chk_digit+0x9a>
jmp    1237 <cc_chk_digit+0xf7>
movslq -0x68(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
sub    $0x30,%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
imul   -0x6c(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0x78(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x70(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0x78(%rbp),%edx
mov    %edx,-0x78(%rbp)
cmpl   $0x2,-0x6c(%rbp)
jne    122b <cc_chk_digit+0xeb>
movl   $0x1,-0x6c(%rbp)
jmp    1232 <cc_chk_digit+0xf2>
movl   $0x2,-0x6c(%rbp)
jmp    1237 <cc_chk_digit+0xf7>
mov    -0x68(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x68(%rbp)
jmp    11b4 <cc_chk_digit+0x74>
mov    -0x78(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x78(%rbp)
mov    $0xa,%eax
sub    -0x78(%rbp),%eax
mov    %eax,-0x78(%rbp)
cmpl   $0xa,-0x78(%rbp)
jne    126f <cc_chk_digit+0x12f>
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    -0x64(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl -0x60(%rbp,%rcx,1),%ecx
sub    $0x30,%ecx
cmp    %ecx,%eax
jne    1297 <cc_chk_digit+0x157>
movl   $0x1,-0x4(%rbp)
jmp    129e <cc_chk_digit+0x15e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_chk_digit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rsi
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strip_non_digits@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    -0x11(%r15),%ecx
xor    %eax,%eax
cmp    $0xfffffff9,%ecx
jb     1233 <cc_chk_digit+0x103>
lea    -0x2(%r15),%ebx
add    $0x1,%rbx
mov    $0x2,%ebp
xor    %r12d,%r12d
jmp    11a6 <cc_chk_digit+0x76>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbx
jle    11f6 <cc_chk_digit+0xc6>
movsbl -0x1(%rsp,%rbx,1),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     11a0 <cc_chk_digit+0x70>
movsbl -0x1(%rsp,%rbx,1),%eax
add    $0xffffffd0,%eax
imul   %ebp,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%r12d
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    %r12d,%eax
xor    %ecx,%ecx
cmp    $0x2,%ebp
sete   %cl
mov    $0x2,%ebp
sub    %ecx,%ebp
mov    %eax,%r12d
jmp    11a0 <cc_chk_digit+0x70>
movslq %r12d,%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
movslq %r15d,%rax
movsbl -0x1(%rax,%r14,1),%edx
add    $0xffffffd0,%edx
xor    %eax,%eax
cmp    %edx,%ecx
sete   %al
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cc_chk_digit(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [80 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = bitcast [80 x i8]* %4 to i8*
store i32 2, i32* %7
store i32 0, i32* %10
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 @strip_non_digits(i8* %12, i8* %13)
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 2
store i32 %18, i32* %6
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 10
br i1 %20, label %24, label %21
21: ; preds = %1
%22 = load i32, i32* %5
%23 = icmp sgt i32 %22, 16
br i1 %23, label %24, label %25
24: ; preds = %21, %1
store i32 0, i32* %2
br label %83
25: ; preds = %21
br label %26
26: ; preds = %60, %25
%27 = load i32, i32* %6
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %63
29: ; preds = %26
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @isdigit(i8 signext %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %29
br label %60
37: ; preds = %29
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = sub nsw i32 %42, 48
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = load i32, i32* %7
%46 = mul nsw i32 %44, %45
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = sdiv i32 %47, 10
%49 = load i32, i32* %10
%50 = add nsw i32 %49, %48
store i32 %50, i32* %10
%51 = load i32, i32* %8
%52 = srem i32 %51, 10
%53 = load i32, i32* %10
%54 = add nsw i32 %53, %52
store i32 %54, i32* %10
%55 = load i32, i32* %7
%56 = icmp eq i32 %55, 2
br i1 %56, label %57, label %58
57: ; preds = %37
store i32 1, i32* %7
br label %59
58: ; preds = %37
store i32 2, i32* %7
br label %59
59: ; preds = %58, %57
br label %60
60: ; preds = %59, %36
%61 = load i32, i32* %6
%62 = add nsw i32 %61, -1
store i32 %62, i32* %6
br label %26
63: ; preds = %26
%64 = load i32, i32* %10
%65 = srem i32 %64, 10
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = sub nsw i32 10, %66
store i32 %67, i32* %10
%68 = load i32, i32* %10
%69 = icmp eq i32 %68, 10
br i1 %69, label %70, label %71
70: ; preds = %63
store i32 0, i32* %10
br label %71
71: ; preds = %70, %63
%72 = load i32, i32* %10
%73 = load i32, i32* %5
%74 = sub nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %75
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = sub nsw i32 %78, 48
%80 = icmp eq i32 %72, %79
br i1 %80, label %81, label %82
81: ; preds = %71
store i32 1, i32* %2
br label %83
82: ; preds = %71
store i32 0, i32* %2
br label %83
83: ; preds = %82, %81, %24
%84 = load i32, i32* %2
ret i32 %84
}

LLVM IR (-O2):
define i32 @cc_chk_digit(i8* %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = call i32 @strip_non_digits(i8* %3, i8* %0)
%5 = call i32 @strlen(i8* %3)
%6 = add i32 %5, -17
%7 = icmp ult i32 %6, -7
br i1 %7, label %48, label %8
8: ; preds = %1
%9 = add nsw i32 %5, -2
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %30
%12 = phi i64 [ %10, %8 ], [ %33, %30 ]
%13 = phi i32 [ 0, %8 ], [ %32, %30 ]
%14 = phi i32 [ 2, %8 ], [ %31, %30 ]
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %12
%16 = load i8, i8* %15
%17 = call i32 @isdigit(i8 signext %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %30, label %19
19: ; preds = %11
%20 = load i8, i8* %15
%21 = sext i8 %20 to i32
%22 = add nsw i32 %21, -48
%23 = mul nsw i32 %22, %14
%24 = sdiv i32 %23, 10
%25 = add nsw i32 %24, %13
%26 = srem i32 %23, 10
%27 = add nsw i32 %25, %26
%28 = icmp eq i32 %14, 2
%29 = select i1 %28, i32 1, i32 2
br label %30
30: ; preds = %19, %11
%31 = phi i32 [ %14, %11 ], [ %29, %19 ]
%32 = phi i32 [ %13, %11 ], [ %27, %19 ]
%33 = add nsw i64 %12, -1
%34 = icmp sgt i64 %12, 0
br i1 %34, label %11, label %35
35: ; preds = %30
%36 = srem i32 %32, 10
%37 = sub nsw i32 10, %36
%38 = icmp eq i32 %36, 0
%39 = select i1 %38, i32 0, i32 %37
%40 = add nsw i32 %5, -1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = add nsw i32 %44, -48
%46 = icmp eq i32 %39, %45
%47 = zext i1 %46 to i32
br label %48
48: ; preds = %35, %1
%49 = phi i32 [ 0, %1 ], [ %47, %35 ]
ret i32 %49
}