#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int LegalInput(char p[]) {
  int i;
  printf("Please input you ID card\n>");
  fgets(p, (sizeof(char) + 1) * 18, stdin);
  if ((strlen(p) - 1) != 18) {
    printf("Error! You need input the '18' length ID card\n");
    return EXIT_FAILURE;
  }
  for (i = 0; i < 18 - 1; i++) {
    if (!isdigit(p[i])) {
      printf("Error! You need input the right num\n");
      return EXIT_FAILURE;
    }
  }
  if (!isdigit(p[18 - 1]) && (p[18 - 1] != 'x') && (p[18 - 1] != 'X')) {
    printf("Error! You need input the right num\n");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<LegalInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cmp    $0x12,%eax
je     11a1 <LegalInput+0x61>
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <LegalInput+0x11d>
movl   $0x0,-0x14(%rbp)
cmpl   $0x11,-0x14(%rbp)
jge    11fc <LegalInput+0xbc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11e9 <LegalInput+0xa9>
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <LegalInput+0x11d>
jmp    11ee <LegalInput+0xae>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <LegalInput+0x68>
mov    -0x10(%rbp),%rax
movsbl 0x11(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1251 <LegalInput+0x111>
mov    -0x10(%rbp),%rax
movsbl 0x11(%rax),%eax
cmp    $0x78,%eax
je     1251 <LegalInput+0x111>
mov    -0x10(%rbp),%rax
movsbl 0x11(%rax),%eax
cmp    $0x58,%eax
je     1251 <LegalInput+0x111>
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <LegalInput+0x11d>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LegalInput>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea2(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x24,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x13,%eax
jne    12b4 <LegalInput+0x164>
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
lea    0xe82(%rip),%r14
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x2(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x3(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x4(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x5(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x6(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x7(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x8(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x9(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0xa(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0xb(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0xc(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0xd(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0xe(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0xf(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x10(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     12bb <LegalInput+0x16b>
movsbl 0x11(%rbx),%edi
call   1030 <isdigit@plt>
mov    0x2d2b(%rip),%rcx
test   %eax,%eax
jne    12ca <LegalInput+0x17a>
mov    0x11(%rbx),%al
or     $0x20,%al
cmp    $0x78,%al
je     12ca <LegalInput+0x17a>
jmp    12bb <LegalInput+0x16b>
lea    0xd84(%rip),%r14
mov    %r14,%rdi
call   1040 <puts@plt>
mov    0x2d0e(%rip),%rcx
mov    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Please input you ID card\0A>\00"
@stdin = global i32 0
@.str.1 = [47 x i8] c"Error! You need input the '18' length ID card\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [37 x i8] c"Error! You need input the right num\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @LegalInput(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %3
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 36, i32 %7)
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 1
%12 = icmp ne i32 %11, 18
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %2
br label %58
16: ; preds = %1
store i32 0, i32* %4
br label %17
17: ; preds = %32, %16
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 17
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @isdigit(i8 signext %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %20
%29 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %2
br label %58
31: ; preds = %20
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %17
35: ; preds = %17
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 17
%38 = load i8, i8* %37
%39 = call i32 @isdigit(i8 signext %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %56, label %41
41: ; preds = %35
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 17
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 120
br i1 %46, label %47, label %56
47: ; preds = %41
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 17
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 88
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
store i32 %55, i32* %2
br label %58
56: ; preds = %47, %41, %35
%57 = load i32, i32* @EXIT_SUCCESS
store i32 %57, i32* %2
br label %58
58: ; preds = %56, %53, %28, %13
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@.str = [27 x i8] c"Please input you ID card\0A>\00"
@stdin = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str.3 = [36 x i8] c"Error! You need input the right num\00"
@str.4 = [46 x i8] c"Error! You need input the '18' length ID card\00"
define i32 @LegalInput(i8* %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %0, i32 36, i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 19
br i1 %6, label %7, label %98
7: ; preds = %1
%8 = load i8, i8* %0
%9 = tail call i32 @isdigit(i8 signext %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %98, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = tail call i32 @isdigit(i8 signext %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %98, label %16
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %0, i64 2
%18 = load i8, i8* %17
%19 = tail call i32 @isdigit(i8 signext %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %98, label %21
21: ; preds = %16
%22 = getelementptr inbounds i8, i8* %0, i64 3
%23 = load i8, i8* %22
%24 = tail call i32 @isdigit(i8 signext %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %98, label %26
26: ; preds = %21
%27 = getelementptr inbounds i8, i8* %0, i64 4
%28 = load i8, i8* %27
%29 = tail call i32 @isdigit(i8 signext %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %98, label %31
31: ; preds = %26
%32 = getelementptr inbounds i8, i8* %0, i64 5
%33 = load i8, i8* %32
%34 = tail call i32 @isdigit(i8 signext %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %98, label %36
36: ; preds = %31
%37 = getelementptr inbounds i8, i8* %0, i64 6
%38 = load i8, i8* %37
%39 = tail call i32 @isdigit(i8 signext %38)
%40 = icmp eq i32 %39, 0
br i1 %40, label %98, label %41
41: ; preds = %36
%42 = getelementptr inbounds i8, i8* %0, i64 7
%43 = load i8, i8* %42
%44 = tail call i32 @isdigit(i8 signext %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %98, label %46
46: ; preds = %41
%47 = getelementptr inbounds i8, i8* %0, i64 8
%48 = load i8, i8* %47
%49 = tail call i32 @isdigit(i8 signext %48)
%50 = icmp eq i32 %49, 0
br i1 %50, label %98, label %51
51: ; preds = %46
%52 = getelementptr inbounds i8, i8* %0, i64 9
%53 = load i8, i8* %52
%54 = tail call i32 @isdigit(i8 signext %53)
%55 = icmp eq i32 %54, 0
br i1 %55, label %98, label %56
56: ; preds = %51
%57 = getelementptr inbounds i8, i8* %0, i64 10
%58 = load i8, i8* %57
%59 = tail call i32 @isdigit(i8 signext %58)
%60 = icmp eq i32 %59, 0
br i1 %60, label %98, label %61
61: ; preds = %56
%62 = getelementptr inbounds i8, i8* %0, i64 11
%63 = load i8, i8* %62
%64 = tail call i32 @isdigit(i8 signext %63)
%65 = icmp eq i32 %64, 0
br i1 %65, label %98, label %66
66: ; preds = %61
%67 = getelementptr inbounds i8, i8* %0, i64 12
%68 = load i8, i8* %67
%69 = tail call i32 @isdigit(i8 signext %68)
%70 = icmp eq i32 %69, 0
br i1 %70, label %98, label %71
71: ; preds = %66
%72 = getelementptr inbounds i8, i8* %0, i64 13
%73 = load i8, i8* %72
%74 = tail call i32 @isdigit(i8 signext %73)
%75 = icmp eq i32 %74, 0
br i1 %75, label %98, label %76
76: ; preds = %71
%77 = getelementptr inbounds i8, i8* %0, i64 14
%78 = load i8, i8* %77
%79 = tail call i32 @isdigit(i8 signext %78)
%80 = icmp eq i32 %79, 0
br i1 %80, label %98, label %81
81: ; preds = %76
%82 = getelementptr inbounds i8, i8* %0, i64 15
%83 = load i8, i8* %82
%84 = tail call i32 @isdigit(i8 signext %83)
%85 = icmp eq i32 %84, 0
br i1 %85, label %98, label %86
86: ; preds = %81
%87 = getelementptr inbounds i8, i8* %0, i64 16
%88 = load i8, i8* %87
%89 = tail call i32 @isdigit(i8 signext %88)
%90 = icmp eq i32 %89, 0
br i1 %90, label %98, label %91
91: ; preds = %86
%92 = getelementptr inbounds i8, i8* %0, i64 17
%93 = load i8, i8* %92
%94 = tail call i32 @isdigit(i8 signext %93)
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %101
96: ; preds = %91
%97 = load i8, i8* %92
switch i8 %97, label %98 [
i8 120, label %101
i8 88, label %101
]
98: ; preds = %96, %7, %11, %16, %21, %26, %31, %36, %41, %46, %51, %56, %61, %66, %71, %76, %81, %86, %1
%99 = phi i8* [ getelementptr inbounds ([46 x i8], [46 x i8]* @str.4, i64 0, i64 0), %1 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %86 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %81 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %76 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %71 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %66 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %61 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %56 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %51 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %46 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %41 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %36 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %31 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %26 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %21 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %16 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %7 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0), %96 ]
%100 = tail call i32 @puts(i8* dereferenceable(1) %99)
br label %101
101: ; preds = %98, %91, %96, %96
%102 = phi i32* [ @EXIT_SUCCESS, %96 ], [ @EXIT_SUCCESS, %96 ], [ @EXIT_SUCCESS, %91 ], [ @EXIT_FAILURE, %98 ]
%103 = load i32, i32* %102
ret i32 %103
}