#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 */
scalar_t__ checkdigit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int strlen(char const *);
int /*<<< orphan*/ strtol(char const *, int /*<<< orphan*/ *, int);
int main(int argc, char const *argv[]) {
  if (argc != 2) {
    printf("You must provide one card number to check.\n");
    return 2;
  }
  if (strlen(argv[1]) != 16) {
    printf("Invalid credit card number.\n");
    return 2;
  }
  if (checkdigit(strtol(argv[1], NULL, 10))) {
    printf("The provided credit card number is valid.\n");
    return 0;
  } else {
    printf("The provided credit card number is invalid.\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1178 <main+0x38>
lea    0xe99(%rip),%rdi
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11f8 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x10,%eax
je     11a6 <main+0x66>
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11f8 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%edi
call   1030 <checkdigit@plt>
cmp    $0x0,%rax
je     11e5 <main+0xa5>
lea    0xe75(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f8 <main+0xb8>
lea    0xe88(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x2,%ebp
cmp    $0x2,%edi
jne    1192 <main+0x52>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <strlen@plt>
cmp    $0x10,%eax
jne    119b <main+0x5b>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%edi
call   1040 <checkdigit@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
lea    0xe7b(%rip),%rax
lea    0xea0(%rip),%rdi
cmove  %rax,%rdi
jmp    11a2 <main+0x62>
lea    0xed9(%rip),%rdi
jmp    11a2 <main+0x62>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"You must provide one card number to check.\0A\00"
@.str.1 = [29 x i8] c"Invalid credit card number.\0A\00"
@.str.2 = [43 x i8] c"The provided credit card number is valid.\0A\00"
@.str.3 = [45 x i8] c"The provided credit card number is invalid.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %29
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strlen(i8* %13)
%15 = icmp ne i32 %14, 16
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %29
18: ; preds = %10
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strtol(i8* %21, i32* null, i32 10)
%23 = call i64 @checkdigit(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %29
27: ; preds = %18
%28 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %29
29: ; preds = %27, %25, %16, %8
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@str = [44 x i8] c"The provided credit card number is invalid.\00"
@str.4 = [42 x i8] c"The provided credit card number is valid.\00"
@str.5 = [28 x i8] c"Invalid credit card number.\00"
@str.6 = [43 x i8] c"You must provide one card number to check.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strlen(i8* %6)
%8 = icmp eq i32 %7, 16
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i32 @strtol(i8* nocapture %10, i32* null, i32 10)
%12 = tail call i64 @checkdigit(i32 %11)
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @str.4, i64 0, i64 0)
%15 = zext i1 %13 to i32
br label %16
16: ; preds = %9, %4, %2
%17 = phi i8* [ getelementptr inbounds ([43 x i8], [43 x i8]* @str.6, i64 0, i64 0), %2 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.5, i64 0, i64 0), %4 ], [ %14, %9 ]
%18 = phi i32 [ 2, %2 ], [ 2, %4 ], [ %15, %9 ]
%19 = tail call i32 @puts(i8* dereferenceable(1) %17)
ret i32 %18
}