#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*/ exit(int);
scalar_t__ isascii(char);
scalar_t__ isdigit(char);
int read(int /*<<< orphan*/, char *, int);
int getint(void) {
  int port = 0;
  char c;
  do {
    if (read(0, &c, 1) != 1)
      exit(1);
    if (isascii(c) && isdigit(c))
      port = port * 10 + c - '0';
  } while (c != 0);
  return port;
}


x86 assembly (clang, -O0):
<getint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     1172 <getint+0x32>
mov    $0x1,%edi
call   1050 <exit@plt>
movsbl -0x5(%rbp),%edi
call   1060 <isascii@plt>
cmp    $0x0,%rax
je     11a8 <getint+0x68>
movsbl -0x5(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11a8 <getint+0x68>
imul   $0xa,-0x4(%rbp),%eax
movsbl -0x5(%rbp),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <getint+0x6d>
movsbl -0x5(%rbp),%eax
cmp    $0x0,%eax
jne    114f <getint+0xf>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getint>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r15d,%r15d
lea    0xf(%rsp),%r14
jmp    1164 <getint+0x24>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %bl,%bl
je     11a3 <getint+0x63>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    11b0 <getint+0x70>
movsbl 0xf(%rsp),%ebx
mov    %ebx,%edi
call   1060 <isascii@plt>
test   %rax,%rax
je     1160 <getint+0x20>
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1160 <getint+0x20>
lea    (%r15,%r15,4),%eax
lea    (%rbx,%rax,2),%r15d
add    $0xffffffd0,%r15d
jmp    1160 <getint+0x20>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define i32 @getint() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
br label %3
3: ; preds = %24, %0
%4 = call i32 @read(i32 0, i8* %2, i32 1)
%5 = icmp ne i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %3
%9 = load i8, i8* %2
%10 = call i64 @isascii(i8 signext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i8, i8* %2
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* %1
%18 = mul nsw i32 %17, 10
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = add nsw i32 %18, %20
%22 = sub nsw i32 %21, 48
store i32 %22, i32* %1
br label %23
23: ; preds = %16, %12, %8
br label %24
24: ; preds = %23
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %3, label %28
28: ; preds = %24
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
define i32 @getint() {
%1 = alloca i8
br label %2
2: ; preds = %20, %0
%3 = phi i32 [ 0, %0 ], [ %21, %20 ]
%4 = call i32 @read(i32 0, i8* %1, i32 1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = load i8, i8* %1
%10 = tail call i64 @isascii(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %8
%13 = tail call i64 @isdigit(i8 signext %9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = mul nsw i32 %3, 10
%17 = sext i8 %9 to i32
%18 = add i32 %16, -48
%19 = add i32 %18, %17
br label %20
20: ; preds = %8, %12, %15
%21 = phi i32 [ %19, %15 ], [ %3, %12 ], [ %3, %8 ]
%22 = icmp eq i8 %9, 0
br i1 %22, label %23, label %2
23: ; preds = %20
ret i32 %21
}