#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 */
short CHAR_MAX;
short calculate(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ is_digit(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ more_then(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(void) {
  short num;
  static char input[5];
  while (1) {
    memset(input, 0, 5);
    printf("pls input an ASCII value(0-127): ");
    fgets(input, 5, stdin);
    if (input[0] == '\n')
      continue;
    if (more_then(input, 4)) {
      printf("invalid input!\n");
      while (getchar() != '\n')
        ;
      continue;
    }
    if (!is_digit(input)) {
      printf("invalid input!\n");
      continue;
    }
    num = calculate(input);
    if (num > CHAR_MAX || num < 0) {
      printf("out of range!\n");
      continue;
    }
    break;
  }
  printf("character: '%c'\n", num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x2ed6(%rip),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
lea    0x2eac(%rip),%rdi
mov    $0x5,%esi
call   1060 <fgets@plt>
movsbl 0x2e9b(%rip),%eax
cmp    $0xa,%eax
jne    11cf <main+0x5f>
jmp    117f <main+0xf>
lea    0x2e86(%rip),%rdi
mov    $0x4,%esi
call   1090 <more_then@plt>
cmp    $0x0,%rax
je     1215 <main+0xa5>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1210 <main+0xa0>
jmp    11f8 <main+0x88>
jmp    117f <main+0xf>
lea    0x2e40(%rip),%rdi
call   1080 <is_digit@plt>
cmp    $0x0,%eax
jne    123d <main+0xcd>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117f <main+0xf>
lea    0x2e18(%rip),%rdi
call   1040 <calculate@plt>
mov    %ax,-0x6(%rbp)
movswl -0x6(%rbp),%eax
mov    0x2d90(%rip),%rcx
movswl (%rcx),%ecx
cmp    %ecx,%eax
jg     1270 <main+0x100>
movswl -0x6(%rbp),%eax
cmp    $0x0,%eax
jge    1283 <main+0x113>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117f <main+0xf>
jmp    1288 <main+0x118>
movswl -0x6(%rbp),%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x2ed2(%rip),%rbx
lea    0xe67(%rip),%r14
mov    0x2e40(%rip),%r12
lea    0xe9a(%rip),%r15
mov    0x2e3a(%rip),%r13
lea    0xe7e(%rip),%rbp
jmp    11c0 <main+0x40>
call   1030 <puts@plt>
nopl   0x0(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1070 <fgets@plt>
cmpb   $0xa,0x2e73(%rip)
je     11c0 <main+0x40>
mov    %rbx,%rdi
mov    $0x4,%esi
call   10a0 <more_then@plt>
test   %rax,%rax
je     121d <main+0x9d>
mov    %r15,%rdi
call   1030 <puts@plt>
nopl   (%rax)
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
jne    1210 <main+0x90>
jmp    11c0 <main+0x40>
mov    %rbx,%rdi
call   1090 <is_digit@plt>
mov    %r15,%rdi
test   %eax,%eax
je     11b7 <main+0x37>
mov    %rbx,%rdi
call   1050 <calculate@plt>
mov    %rbp,%rdi
test   %ax,%ax
js     11b7 <main+0x37>
mov    %rbp,%rdi
cmp    0x0(%r13),%ax
jg     11b7 <main+0x37>
movzwl %ax,%esi
lea    0xdca(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.input = internal global [5 x i8] zeroinitializer
@.str = [34 x i8] c"pls input an ASCII value(0-127): \00"
@stdin = global i32 0
@.str.1 = [16 x i8] c"invalid input!\0A\00"
@CHAR_MAX = global i16 0
@.str.2 = [15 x i8] c"out of range!\0A\00"
@.str.3 = [17 x i8] c"character: '%c'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
store i32 0, i32* %1
br label %3
3: ; preds = %0, %11, %22, %26, %39
%4 = call i32 @memset(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0), i32 0, i32 5)
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0), i32 5, i32 %6)
%8 = load i8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0)
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 10
br i1 %10, label %11, label %12
11: ; preds = %3
br label %3
12: ; preds = %3
%13 = call i64 @more_then(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0), i32 4)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %21, %15
%18 = call signext i8 (...) @getchar()
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %17
br label %17
22: ; preds = %17
br label %3
23: ; preds = %12
%24 = call i32 @is_digit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %3
28: ; preds = %23
%29 = call signext i16 @calculate(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0))
store i16 %29, i16* %2
%30 = load i16, i16* %2
%31 = sext i16 %30 to i32
%32 = load i16, i16* @CHAR_MAX
%33 = sext i16 %32 to i32
%34 = icmp sgt i32 %31, %33
br i1 %34, label %39, label %35
35: ; preds = %28
%36 = load i16, i16* %2
%37 = sext i16 %36 to i32
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35, %28
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %3
41: ; preds = %35
br label %42
42: ; preds = %41
%43 = load i16, i16* %2
%44 = sext i16 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %44)
ret i32 0
}

LLVM IR (-O2):
@main.input = internal global [5 x i8] zeroinitializer
@.str = [34 x i8] c"pls input an ASCII value(0-127): \00"
@stdin = global i32 0
@CHAR_MAX = global i16 0
@.str.3 = [17 x i8] c"character: '%c'\0A\00"
@str.4 = [14 x i8] c"out of range!\00"
@str.5 = [15 x i8] c"invalid input!\00"
define i32 @main() {
br label %1
1: ; preds = %22, %0
%2 = tail call i32 @memset(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0), i32 0, i32 5)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = tail call i32 @fgets(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0), i32 5, i32 %4)
%6 = load i8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0)
%7 = icmp eq i8 %6, 10
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = tail call i64 @more_then(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0), i32 4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
br label %13
13: ; preds = %13, %11
%14 = tail call signext i8 (...) @getchar()
%15 = icmp eq i8 %14, 10
br i1 %15, label %22, label %13
16: ; preds = %8
%17 = tail call i32 @is_digit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16, %23
%20 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0), %23 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0), %16 ]
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
br label %22
22: ; preds = %13, %19, %1
br label %1
23: ; preds = %16
%24 = tail call signext i16 @calculate(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.input, i64 0, i64 0))
%25 = load i16, i16* @CHAR_MAX
%26 = icmp sgt i16 %24, %25
%27 = icmp slt i16 %24, 0
%28 = or i1 %27, %26
br i1 %28, label %19, label %29
29: ; preds = %23
%30 = zext i16 %24 to i32
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %30)
ret i32 0
}