#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*/ lprcat(char *);
int /*<<< orphan*/ scbr();
int /*<<< orphan*/ sncbr();
int ttgetch();
unsigned long readnum(long mx) {
  int i;
  unsigned long amt = 0;
  sncbr();
  if ((i = ttgetch()) == '*')
    amt = mx;
  else
    while (i != '\n') {
      if (i == '\033') {
        scbr();
        lprcat(" aborted");
        return (0);
      }
      if ((i <= '9') && (i >= '0') && (amt < 99999999))
        amt = amt * 10 + i - '0';
      i = ttgetch();
    }
  scbr();
  return (amt);
}


x86 assembly (clang, -O0):
<readnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <sncbr@plt>
mov    $0x0,%al
call   1050 <ttgetch@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x2a,%eax
jne    117b <readnum+0x3b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11fe <readnum+0xbe>
jmp    1180 <readnum+0x40>
cmpl   $0xa,-0x14(%rbp)
je     11f9 <readnum+0xb9>
cmpl   $0x1b,-0x14(%rbp)
jne    11b4 <readnum+0x74>
mov    $0x0,%al
call   1060 <scbr@plt>
lea    0xe5e(%rip),%rdi
call   1040 <lprcat@plt>
movq   $0x0,-0x8(%rbp)
jmp    120d <readnum+0xcd>
cmpl   $0x39,-0x14(%rbp)
jg     11ea <readnum+0xaa>
cmpl   $0x30,-0x14(%rbp)
jl     11ea <readnum+0xaa>
cmpq   $0x5f5e0ff,-0x20(%rbp)
05
jae    11ea <readnum+0xaa>
imul   $0xa,-0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
sub    $0x30,%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <ttgetch@plt>
mov    %eax,-0x14(%rbp)
jmp    1180 <readnum+0x40>
jmp    11fe <readnum+0xbe>
mov    $0x0,%al
call   1060 <scbr@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readnum>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <sncbr@plt>
xor    %eax,%eax
call   1050 <ttgetch@plt>
cmp    $0x2a,%eax
jne    1160 <readnum+0x20>
xor    %eax,%eax
call   1060 <scbr@plt>
jmp    11b9 <readnum+0x79>
xor    %ebx,%ebx
cmp    $0xa,%eax
je     1157 <readnum+0x17>
nopw   0x0(%rax,%rax,1)
cmp    $0x1b,%eax
je     11a4 <readnum+0x64>
cmp    $0x5f5e0ff,%rbx
lea    (%rbx,%rbx,4),%rcx
movslq %eax,%rdx
lea    -0x30(%rdx,%rcx,2),%rcx
cmovae %rbx,%rcx
add    $0xffffffd0,%eax
cmp    $0xa,%eax
cmovb  %rcx,%rbx
xor    %eax,%eax
call   1050 <ttgetch@plt>
cmp    $0xa,%eax
jne    1170 <readnum+0x30>
jmp    1157 <readnum+0x17>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <scbr@plt>
lea    0xe4c(%rip),%rdi
call   1040 <lprcat@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c" aborted\00"
define i64 @readnum(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
store i64 %0, i64* %3
store i64 0, i64* %5
%6 = call i32 (...) @sncbr()
%7 = call i32 (...) @ttgetch()
store i32 %7, i32* %4
%8 = icmp eq i32 %7, 42
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i64, i64* %3
store i64 %10, i64* %5
br label %40
11: ; preds = %1
br label %12
12: ; preds = %37, %11
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %39
15: ; preds = %12
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 27
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 (...) @scbr()
%20 = call i32 @lprcat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %2
br label %43
21: ; preds = %15
%22 = load i32, i32* %4
%23 = icmp sle i32 %22, 57
br i1 %23, label %24, label %37
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp sge i32 %25, 48
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i64, i64* %5
%29 = icmp ult i64 %28, 99999999
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i64, i64* %5
%32 = mul i64 %31, 10
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = add i64 %32, %34
%36 = sub i64 %35, 48
store i64 %36, i64* %5
br label %37
37: ; preds = %30, %27, %24, %21
%38 = call i32 (...) @ttgetch()
store i32 %38, i32* %4
br label %12
39: ; preds = %12
br label %40
40: ; preds = %39, %9
%41 = call i32 (...) @scbr()
%42 = load i64, i64* %5
store i64 %42, i64* %2
br label %43
43: ; preds = %40, %18
%44 = load i64, i64* %2
ret i64 %44
}

LLVM IR (-O2):
@.str = [9 x i8] c" aborted\00"
define i64 @readnum(i64 %0) {
%2 = tail call i32 (...) @sncbr()
%3 = tail call i32 (...) @ttgetch()
%4 = icmp eq i32 %3, 42
br i1 %4, label %22, label %5
5: ; preds = %1, %11
%6 = phi i32 [ %21, %11 ], [ %3, %1 ]
%7 = phi i64 [ %20, %11 ], [ 0, %1 ]
switch i32 %6, label %11 [
i32 10, label %22
i32 27, label %8
]
8: ; preds = %5
%9 = tail call i32 (...) @scbr()
%10 = tail call i32 @lprcat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %25
11: ; preds = %5
%12 = add i32 %6, -48
%13 = icmp ult i32 %12, 10
%14 = icmp ult i64 %7, 99999999
%15 = select i1 %13, i1 %14, i1 false
%16 = mul i64 %7, 10
%17 = sext i32 %6 to i64
%18 = add nsw i64 %17, -48
%19 = add i64 %18, %16
%20 = select i1 %15, i64 %19, i64 %7
%21 = tail call i32 (...) @ttgetch()
br label %5
22: ; preds = %5, %1
%23 = phi i64 [ %0, %1 ], [ %7, %5 ]
%24 = tail call i32 (...) @scbr()
br label %25
25: ; preds = %22, %8
%26 = phi i64 [ %23, %22 ], [ 0, %8 ]
ret i64 %26
}