#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 ascii_to_integer(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  char string[10];
  int x = 0;
  printf("\nEnter 1-10 or more digits to be converted to integers:\n\t");
  fgets(string, 10, stdin);
  while (string[x] != '\n') {
    if (string[x] < 48 || string[x] > 57) {
      printf("**Character #%d is %c (not a digit)**\n", x + 1, string[x]);
      puts("Naughty! :-P\n\n");
      return 0;
    } else
      ++x;
  }
  printf("\n\nCool! So that would be..\n");
  printf("\t%d\n\n", ascii_to_integer(string));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <fgets@plt>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     11f4 <main+0xb4>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jl     11b1 <main+0x71>
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%eax
cmp    $0x39,%eax
jle    11e6 <main+0xa6>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
movslq -0x14(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    1222 <main+0xe2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <main+0x3b>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
call   1060 <ascii_to_integer@plt>
mov    %eax,%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
call   1050 <fgets@plt>
mov    0xe(%rsp),%al
cmp    $0xa,%al
je     1195 <main+0x55>
mov    $0x1,%esi
nopw   0x0(%rax,%rax,1)
lea    -0x3a(%rax),%ecx
cmp    $0xf5,%cl
jbe    11bd <main+0x7d>
movzbl 0xe(%rsp,%rsi,1),%eax
add    $0x1,%rsi
cmp    $0xa,%al
jne    1180 <main+0x40>
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
lea    0xe(%rsp),%rdi
call   1060 <ascii_to_integer@plt>
lea    0xebe(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11da <main+0x9a>
movsbl %al,%edx
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [58 x i8] c"\0AEnter 1-10 or more digits to be converted to integers:\0A\09\00"
@stdin = global i32 0
@.str.1 = [39 x i8] c"**Character #%d is %c (not a digit)**\0A\00"
@.str.2 = [15 x i8] c"Naughty! :-P\0A\0A\00"
@.str.3 = [28 x i8] c"\0A\0ACool! So that would be..\0A\00"
@.str.4 = [6 x i8] c"\09%d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 10, i32 %6)
br label %8
8: ; preds = %42, %0
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %43
15: ; preds = %8
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp slt i32 %20, 48
br i1 %21, label %29, label %22
22: ; preds = %15
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp sgt i32 %27, 57
br i1 %28, label %29, label %39
29: ; preds = %22, %15
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %36)
%38 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %48
39: ; preds = %22
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %42
42: ; preds = %39
br label %8
43: ; preds = %8
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%46 = call i32 @ascii_to_integer(i8* %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %46)
store i32 0, i32* %1
br label %48
48: ; preds = %43, %29
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [58 x i8] c"\0AEnter 1-10 or more digits to be converted to integers:\0A\09\00"
@stdin = global i32 0
@.str.1 = [39 x i8] c"**Character #%d is %c (not a digit)**\0A\00"
@.str.2 = [15 x i8] c"Naughty! :-P\0A\0A\00"
@.str.4 = [6 x i8] c"\09%d\0A\0A\00"
@str = [27 x i8] c"\0A\0ACool! So that would be..\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 10, i32 %4)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 10
br i1 %7, label %24, label %8
8: ; preds = %0, %19
%9 = phi i64 [ %20, %19 ], [ 0, %0 ]
%10 = phi i8 [ %22, %19 ], [ %6, %0 ]
%11 = add i8 %10, -58
%12 = icmp ult i8 %11, -10
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = trunc i64 %9 to i32
%15 = add nuw nsw i32 %14, 1
%16 = sext i8 %10 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %28
19: ; preds = %8
%20 = add nuw i64 %9, 1
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 10
br i1 %23, label %24, label %8
24: ; preds = %19, %0
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%26 = call i32 @ascii_to_integer(i8* %2)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %13
ret i32 0
}