#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 INT_MAX;
int /*<<< orphan*/ back(int);
int /*<<< orphan*/ error(char *);
int input();
scalar_t__ isdigit(int);
int getnum(void) {
  int ln, n, c;
  for (ln = 0; isdigit(c = input()); ln += n) {
    if (ln > INT_MAX / 10)
      goto invalid;
    n = c - '0';
    ln *= 10;
    if (INT_MAX - ln < n)
      goto invalid;
  }
  back(c);
  return ln;
invalid:
  error("invalid address");
  return -1;
}


x86 assembly (clang, -O0):
<getnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <input@plt>
mov    %eax,%edi
mov    %edi,-0x10(%rbp)
call   1050 <isdigit@plt>
cmp    $0x0,%rax
je     11d0 <getnum+0x90>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jle    1193 <getnum+0x53>
jmp    11e3 <getnum+0xa3>
mov    -0x10(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
sub    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bd <getnum+0x7d>
jmp    11e3 <getnum+0xa3>
jmp    11c2 <getnum+0x82>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    114f <getnum+0xf>
mov    -0x10(%rbp),%edi
call   1030 <back@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f6 <getnum+0xb6>
lea    0xe16(%rip),%rdi
call   1060 <error@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnum>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <input@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1050 <isdigit@plt>
test   %rax,%rax
je     11b7 <getnum+0x77>
mov    0x2e84(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movslq (%r15),%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
cmp    %ecx,%ebx
jg     11c1 <getnum+0x81>
lea    -0x30(%r14),%edx
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ecx
sub    %ecx,%eax
cmp    %edx,%eax
jl     11c1 <getnum+0x81>
lea    (%r14,%rcx,1),%ebx
add    $0xffffffd0,%ebx
xor    %eax,%eax
call   1040 <input@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1050 <isdigit@plt>
test   %rax,%rax
jne    1170 <getnum+0x30>
mov    %r14d,%edi
call   1030 <back@plt>
jmp    11d2 <getnum+0x92>
lea    0xe38(%rip),%rdi
call   1060 <error@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
@.str = [16 x i8] c"invalid address\00"
define i32 @getnum() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %2
br label %5
5: ; preds = %27, %0
%6 = call i32 (...) @input()
store i32 %6, i32* %4
%7 = call i64 @isdigit(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %31
9: ; preds = %5
%10 = load i32, i32* %2
%11 = load i32, i32* @INT_MAX
%12 = sdiv i32 %11, 10
%13 = icmp sgt i32 %10, %12
br i1 %13, label %14, label %15
14: ; preds = %9
br label %35
15: ; preds = %9
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 48
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = mul nsw i32 %18, 10
store i32 %19, i32* %2
%20 = load i32, i32* @INT_MAX
%21 = load i32, i32* %2
%22 = sub nsw i32 %20, %21
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %15
br label %35
26: ; preds = %15
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = load i32, i32* %2
%30 = add nsw i32 %29, %28
store i32 %30, i32* %2
br label %5
31: ; preds = %5
%32 = load i32, i32* %4
%33 = call i32 @back(i32 %32)
%34 = load i32, i32* %2
store i32 %34, i32* %1
br label %37
35: ; preds = %25, %14
%36 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@INT_MAX = global i32 0
@.str = [16 x i8] c"invalid address\00"
define i32 @getnum() {
%1 = tail call i32 (...) @input()
%2 = tail call i64 @isdigit(i32 %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %20, label %8
4: ; preds = %14
%5 = tail call i32 (...) @input()
%6 = tail call i64 @isdigit(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %0, %4
%9 = phi i32 [ %5, %4 ], [ %1, %0 ]
%10 = phi i32 [ %19, %4 ], [ 0, %0 ]
%11 = load i32, i32* @INT_MAX
%12 = sdiv i32 %11, 10
%13 = icmp sgt i32 %10, %12
br i1 %13, label %24, label %14
14: ; preds = %8
%15 = add nsw i32 %9, -48
%16 = mul nsw i32 %10, 10
%17 = sub nsw i32 %11, %16
%18 = icmp slt i32 %17, %15
%19 = add nsw i32 %15, %16
br i1 %18, label %24, label %4
20: ; preds = %4, %0
%21 = phi i32 [ 0, %0 ], [ %19, %4 ]
%22 = phi i32 [ %1, %0 ], [ %5, %4 ]
%23 = tail call i32 @back(i32 %22)
br label %26
24: ; preds = %14, %8
%25 = tail call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = phi i32 [ -1, %24 ], [ %21, %20 ]
ret i32 %27
}