#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*/ fgets(char *, int, int /*<<< orphan*/);
int getAccountBalance(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stdin;
int validateAtmCardNumber(char *);
int validateCardAndPin(char *, int);
int main() {
  char atmCardNumber[20];
  printf("Welcome to ATM Reference Implementation.\n");
  printf("Please enter the ATM card number: ");
  fgets(atmCardNumber, 20, stdin);
  scanf("%[^\n]%*c", atmCardNumber);
  printf("\nEntered ATM card number : %s", atmCardNumber);
  int isValidAndExists = validateAtmCardNumber(atmCardNumber);
  if (isValidAndExists == 0) {
    printf("\nInvalid Card Number, Please Enter a valid 16 digit card number.");
    return 0;
  } else if (isValidAndExists == 1) {
    printf("\nCard Number doesn't exists, Please Enter a valid 16 digit card "
           "number.");
    return 0;
  }
  printf("\nEnter the ATM Pin: ");
  int atmPin;
  scanf("%d", atmPin);
  int isValidPin = validateCardAndPin(atmCardNumber, atmPin);
  if (isValidPin == 0) {
    printf("\nPlease Enter the valid Pin:");
    return 0;
  }
  int accountBalance = getAccountBalance(atmCardNumber);
  printf("\nYour account balance is : %d", accountBalance);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1050 <fgets@plt>
lea    -0x20(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1030 <validateAtmCardNumber@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11f6 <main+0x96>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1295 <main+0x135>
cmpl   $0x1,-0x24(%rbp)
jne    121a <main+0xba>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1295 <main+0x135>
jmp    121f <main+0xbf>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xf13(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1060 <validateCardAndPin@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1271 <main+0x111>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1295 <main+0x135>
lea    -0x20(%rbp),%rdi
call   1080 <getAccountBalance@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xfa7(%rip),%rdi
call   1030 <puts@plt>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <fgets@plt>
lea    0xe74(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe6c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <validateAtmCardNumber@plt>
cmp    $0x1,%eax
je     11e4 <main+0x74>
test   %eax,%eax
jne    11ed <main+0x7d>
lea    0xe68(%rip),%rdi
jmp    1236 <main+0xc6>
lea    0xea0(%rip),%rdi
jmp    1236 <main+0xc6>
lea    0xedf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf1e(%rip),%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    %rsp,%rdi
call   1070 <validateCardAndPin@plt>
test   %eax,%eax
je     122f <main+0xbf>
mov    %rsp,%rdi
call   1090 <getAccountBalance@plt>
lea    0xee1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    123d <main+0xcd>
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Welcome to ATM Reference Implementation.\0A\00"
@.str.1 = [35 x i8] c"Please enter the ATM card number: \00"
@stdin = global i32 0
@.str.2 = [9 x i8] c"%[^\0A]%*c\00"
@.str.3 = [30 x i8] c"\0AEntered ATM card number : %s\00"
@.str.4 = [65 x i8] c"\0AInvalid Card Number, Please Enter a valid 16 digit card number.\00"
@.str.5 = [72 x i8] c"\0ACard Number doesn't exists, Please Enter a valid 16 digit card number.\00"
@.str.6 = [21 x i8] c"\0AEnter the ATM Pin: \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [29 x i8] c"\0APlease Enter the valid Pin:\00"
@.str.9 = [30 x i8] c"\0AYour account balance is : %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 20, i32 %10)
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%17 = call i32 @validateAtmCardNumber(i8* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %44
22: ; preds = %0
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %44
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%30 = load i32, i32* %4
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%33 = load i32, i32* %4
%34 = call i32 @validateCardAndPin(i8* %32, i32 %33)
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %1
br label %44
39: ; preds = %28
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%41 = call i32 @getAccountBalance(i8* %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i32 %42)
store i32 0, i32* %1
br label %44
44: ; preds = %39, %37, %25, %20
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str.1 = [35 x i8] c"Please enter the ATM card number: \00"
@stdin = global i32 0
@.str.2 = [9 x i8] c"%[^\0A]%*c\00"
@.str.3 = [30 x i8] c"\0AEntered ATM card number : %s\00"
@.str.4 = [65 x i8] c"\0AInvalid Card Number, Please Enter a valid 16 digit card number.\00"
@.str.5 = [72 x i8] c"\0ACard Number doesn't exists, Please Enter a valid 16 digit card number.\00"
@.str.6 = [21 x i8] c"\0AEnter the ATM Pin: \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [29 x i8] c"\0APlease Enter the valid Pin:\00"
@.str.9 = [30 x i8] c"\0AYour account balance is : %d\00"
@str = [41 x i8] c"Welcome to ATM Reference Implementation.\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 20, i32 %5)
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%9 = call i32 @validateAtmCardNumber(i8* %2)
switch i32 %9, label %14 [
i32 0, label %10
i32 1, label %12
]
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0))
br label %24
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.5, i64 0, i64 0))
br label %24
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 undef)
%17 = call i32 @validateCardAndPin(i8* %2, i32 undef)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
br label %24
21: ; preds = %14
%22 = call i32 @getAccountBalance(i8* %2)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %19, %21, %12, %10
ret i32 0
}