#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__ EOF;
int /*<<< orphan*/ isspace(char);
int /*<<< orphan*/ printf(char *);
scalar_t__ scanf(char *, char *);
int convert(void) {
  printf("Enter a digit followed by a space to submit the number: ");
  char part;
  int result = 0;
  while (scanf("%c", &part) != EOF && !isspace(part)) {
    if (part >= '0' && part <= '9') {
      result *= 10;
      result += (part - '0');
    } else {
      break;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
lea    0xee7(%rip),%rdi
lea    -0x1(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e81(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x9(%rbp)
je     1187 <convert+0x57>
movsbl -0x1(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1197 <convert+0x67>
jmp    11d4 <convert+0xa4>
movsbl -0x1(%rbp),%eax
cmp    $0x30,%eax
jl     11ca <convert+0x9a>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
jg     11ca <convert+0x9a>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11cf <convert+0x9f>
jmp    11d4 <convert+0xa4>
jmp    114b <convert+0x1b>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x2e8c(%rip),%r12
xor    %ebx,%ebx
cmp    (%r12),%rax
je     11b5 <convert+0x85>
xor    %ebx,%ebx
lea    0xecc(%rip),%r14
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x7(%rsp),%edi
call   1040 <isspace@plt>
test   %eax,%eax
jne    11b5 <convert+0x85>
movzbl 0x7(%rsp),%eax
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     11b5 <convert+0x85>
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%ebx
add    $0xffffffd0,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
cmp    (%r12),%rax
jne    1180 <convert+0x50>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Enter a digit followed by a space to submit the number: \00"
@.str.1 = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @convert() {
%1 = alloca i8
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %4
4: ; preds = %32, %0
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%6 = load i64, i64* @EOF
%7 = icmp ne i64 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = load i8, i8* %1
%10 = call i32 @isspace(i8 signext %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br label %13
13: ; preds = %8, %4
%14 = phi i1 [ false, %4 ], [ %12, %8 ]
br i1 %14, label %15, label %33
15: ; preds = %13
%16 = load i8, i8* %1
%17 = sext i8 %16 to i32
%18 = icmp sge i32 %17, 48
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i8, i8* %1
%21 = sext i8 %20 to i32
%22 = icmp sle i32 %21, 57
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i32, i32* %2
%25 = mul nsw i32 %24, 10
store i32 %25, i32* %2
%26 = load i8, i8* %1
%27 = sext i8 %26 to i32
%28 = sub nsw i32 %27, 48
%29 = load i32, i32* %2
%30 = add nsw i32 %29, %28
store i32 %30, i32* %2
br label %32
31: ; preds = %19, %15
br label %33
32: ; preds = %23
br label %4
33: ; preds = %31, %13
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [57 x i8] c"Enter a digit followed by a space to submit the number: \00"
@.str.1 = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @convert() {
%1 = alloca i8
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%3 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%4 = load i64, i64* @EOF
%5 = icmp eq i64 %3, %4
br i1 %5, label %23, label %6
6: ; preds = %0, %15
%7 = phi i32 [ %19, %15 ], [ 0, %0 ]
%8 = load i8, i8* %1
%9 = call i32 @isspace(i8 signext %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %6
%12 = load i8, i8* %1
%13 = add i8 %12, -48
%14 = icmp ult i8 %13, 10
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = zext i8 %12 to i32
%17 = mul nsw i32 %7, 10
%18 = add i32 %17, -48
%19 = add i32 %18, %16
%20 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %6
23: ; preds = %6, %11, %15, %0
%24 = phi i32 [ 0, %0 ], [ %19, %15 ], [ %7, %11 ], [ %7, %6 ]
ret i32 %24
}