#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 *, char *);
int main(void) {
  char cardNumber[17];
  int i, result, cardDigits[16];
  int validate(int cardDigits[]);
  printf("Please enter a card number: ");
  scanf("%s", cardNumber);
  for (i = 0; cardNumber[i] >= '0' && cardNumber[i] <= '9'; ++i)
    cardDigits[i] = cardNumber[i] - '0';
  result = validate(cardDigits);
  printf(result == 1 ? "Card number is valid\n" : "Card number is not valid\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xec4(%rip),%rdi
call   1050 <scanf@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x71(%rbp)
jl     118e <main+0x5e>
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    119e <main+0x6e>
jmp    11c0 <main+0x90>
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%ecx
sub    $0x30,%ecx
movslq -0x24(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <main+0x35>
lea    -0x70(%rbp),%rdi
call   1040 <validate@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
lea    0xe60(%rip),%rdi
lea    0xe43(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%al
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     117b <main+0x4b>
xor    %ecx,%ecx
nopl   0x0(%rax)
movzbl %al,%eax
add    $0xffffffd0,%eax
mov    %eax,0x20(%rsp,%rcx,4)
movzbl 0x1(%rsp,%rcx,1),%eax
add    $0x1,%rcx
lea    -0x30(%rax),%edx
cmp    $0xa,%dl
jb     1160 <main+0x30>
lea    0x20(%rsp),%rdi
call   1040 <validate@plt>
cmp    $0x1,%eax
lea    0xe91(%rip),%rax
lea    0xea0(%rip),%rdi
cmove  %rax,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Please enter a card number: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [22 x i8] c"Card number is valid\0A\00"
@.str.3 = [26 x i8] c"Card number is not valid\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [17 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i32]
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
store i32 0, i32* %3
br label %9
9: ; preds = %35, %0
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp sge i32 %14, 48
br i1 %15, label %16, label %23
16: ; preds = %9
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp sle i32 %21, 57
br label %23
23: ; preds = %16, %9
%24 = phi i1 [ false, %9 ], [ %22, %16 ]
br i1 %24, label %25, label %38
25: ; preds = %23
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 48
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 %33
store i32 %31, i32* %34
br label %35
35: ; preds = %25
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %9
38: ; preds = %23
%39 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%40 = call i32 @validate(i32* %39)
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 1
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0)
%45 = call i32 @printf(i8* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"Please enter a card number: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [22 x i8] c"Card number is valid\0A\00"
@.str.3 = [26 x i8] c"Card number is not valid\0A\00"
define i32 @main() {
%1 = alloca [17 x i8]
%2 = alloca [16 x i32]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%4 = bitcast [16 x i32]* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = load i8, i8* %3
%8 = add i8 %7, -48
%9 = icmp ult i8 %8, 10
br i1 %9, label %10, label %21
10: ; preds = %0, %10
%11 = phi i64 [ %16, %10 ], [ 0, %0 ]
%12 = phi i8 [ %18, %10 ], [ %7, %0 ]
%13 = zext i8 %12 to i32
%14 = add nsw i32 %13, -48
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %11
store i32 %14, i32* %15
%16 = add nuw nsw i64 %11, 1
%17 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = add i8 %18, -48
%20 = icmp ult i8 %19, 10
br i1 %20, label %10, label %21
21: ; preds = %10, %0
%22 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%23 = call i32 @validate(i32* %22)
%24 = icmp eq i32 %23, 1
%25 = select i1 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0)
%26 = call i32 @printf(i8* dereferenceable(1) %25)
ret i32 0
}