#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[12];
  int i, cardDigits[13];
  int result;
  int validate(int cardDigits[]);
  printf("Please enter a 12 digit 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 ? "Valid card number" : "Not a valid card number");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rsi
lea    0xed0(%rip),%rdi
call   1050 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x55(%rbp)
jl     118b <main+0x5b>
movslq -0x14(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%eax
cmp    $0x39,%eax
setge  %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    119b <main+0x6b>
jmp    11bd <main+0x8d>
movslq -0x14(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%ecx
sub    $0x30,%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x50(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1162 <main+0x32>
lea    -0x50(%rbp),%rdi
call   1040 <validate@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%ecx
lea    0xe68(%rip),%rdi
lea    0xe4f(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%al
cmp    $0x39,%al
jl     1177 <main+0x47>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movzbl %al,%eax
add    $0xffffffd0,%eax
mov    %eax,0x10(%rsp,%rcx,4)
movzbl 0x5(%rsp,%rcx,1),%eax
add    $0x1,%rcx
cmp    $0x38,%al
jg     1160 <main+0x30>
lea    0x10(%rsp),%rdi
call   1040 <validate@plt>
cmp    $0x1,%eax
lea    0xe9e(%rip),%rax
lea    0xea9(%rip),%rdi
cmove  %rax,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Please enter a 12 digit card number: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [18 x i8] c"Valid card number\00"
@.str.3 = [24 x i8] c"Not a valid card number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca i32
%4 = alloca [13 x i32]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [12 x i8], [12 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 [12 x i8], [12 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 [12 x i8], [12 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp sge 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 [12 x i8], [12 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 [13 x i32], [13 x i32]* %4, 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 [13 x i32], [13 x i32]* %4, i64 0, i64 0
%40 = call i32 @validate(i32* %39)
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 1
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0)
%45 = call i32 @printf(i8* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"Please enter a 12 digit card number: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [18 x i8] c"Valid card number\00"
@.str.3 = [24 x i8] c"Not a valid card number\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [13 x i32]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%4 = bitcast [13 x i32]* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 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 = icmp sgt i8 %7, 56
br i1 %8, label %9, label %19
9: ; preds = %0, %9
%10 = phi i64 [ %15, %9 ], [ 0, %0 ]
%11 = phi i8 [ %17, %9 ], [ %7, %0 ]
%12 = zext i8 %11 to i32
%13 = add nsw i32 %12, -48
%14 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 %10
store i32 %13, i32* %14
%15 = add nuw nsw i64 %10, 1
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp sgt i8 %17, 56
br i1 %18, label %9, label %19
19: ; preds = %9, %0
%20 = getelementptr inbounds [13 x i32], [13 x i32]* %2, i64 0, i64 0
%21 = call i32 @validate(i32* %20)
%22 = icmp eq i32 %21, 1
%23 = select i1 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0)
%24 = call i32 @printf(i8* dereferenceable(1) %23)
ret i32 0
}