#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ badinput(char const *);
int getc(int /*<<< orphan*/ *);
int getnum(FILE *f, unsigned *np, const char *fn) {
  unsigned n;
  int c = getc(f);
  if (c < '0' || c > '9')
    badinput(fn);
  n = c - '0';
  while ((c = getc(f)) >= '0' && c <= '9') {
    c -= '0';
    if (0xffffffff / 10 - c < n)
      badinput(fn);
    n = n * 10 + c;
  }
  *np = n;
  return c;
}


x86 assembly (clang, -O0):
<getnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x30,-0x20(%rbp)
jl     1154 <getnum+0x34>
cmpl   $0x39,-0x20(%rbp)
jle    115d <getnum+0x3d>
mov    -0x18(%rbp),%rdi
call   1040 <badinput@plt>
mov    -0x20(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x21(%rbp)
jl     118c <getnum+0x6c>
cmpl   $0x39,-0x20(%rbp)
setle  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    119c <getnum+0x7c>
jmp    11ce <getnum+0xae>
mov    -0x20(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x20(%rbp)
mov    $0x19999999,%eax
sub    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11bf <getnum+0x9f>
mov    -0x18(%rbp),%rdi
call   1040 <badinput@plt>
imul   $0xa,-0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <getnum+0x46>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnum>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <getc@plt>
mov    %eax,%r13d
lea    -0x3a(%r13),%eax
cmp    $0xfffffff5,%eax
ja     114b <getnum+0x2b>
mov    %r15,%rdi
call   1040 <badinput@plt>
add    $0xffffffd0,%r13d
mov    %r12,%rdi
call   1030 <getc@plt>
mov    %eax,%ebx
add    $0xffffffd0,%ebx
cmp    $0x9,%ebx
jbe    118b <getnum+0x6b>
mov    %r13d,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xchg   %ax,%ax
lea    0x0(%r13,%r13,4),%eax
lea    (%rbx,%rax,2),%r13d
mov    %r12,%rdi
call   1030 <getc@plt>
mov    %eax,%ebx
add    $0xffffffd0,%ebx
cmp    $0xa,%ebx
jae    1161 <getnum+0x41>
mov    $0x199999c9,%ecx
sub    %eax,%ecx
cmp    %r13d,%ecx
jae    1170 <getnum+0x50>
mov    %r15,%rdi
call   1040 <badinput@plt>
jmp    1170 <getnum+0x50>

LLVM IR (-O0):
define i32 @getnum(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%9 = load i32*, i32** %4
%10 = call i32 @getc(i32* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 48
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i32, i32* %8
%15 = icmp sgt i32 %14, 57
br i1 %15, label %16, label %19
16: ; preds = %13, %3
%17 = load i8*, i8** %6
%18 = call i32 @badinput(i8* %17)
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* %8
%21 = sub nsw i32 %20, 48
store i32 %21, i32* %7
br label %22
22: ; preds = %41, %19
%23 = load i32*, i32** %4
%24 = call i32 @getc(i32* %23)
store i32 %24, i32* %8
%25 = icmp sge i32 %24, 48
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* %8
%28 = icmp sle i32 %27, 57
br label %29
29: ; preds = %26, %22
%30 = phi i1 [ false, %22 ], [ %28, %26 ]
br i1 %30, label %31, label %46
31: ; preds = %29
%32 = load i32, i32* %8
%33 = sub nsw i32 %32, 48
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = sub i32 429496729, %34
%36 = load i32, i32* %7
%37 = icmp ult i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %31
%39 = load i8*, i8** %6
%40 = call i32 @badinput(i8* %39)
br label %41
41: ; preds = %38, %31
%42 = load i32, i32* %7
%43 = mul i32 %42, 10
%44 = load i32, i32* %8
%45 = add i32 %43, %44
store i32 %45, i32* %7
br label %22
46: ; preds = %29
%47 = load i32, i32* %7
%48 = load i32*, i32** %5
store i32 %47, i32* %48
%49 = load i32, i32* %8
ret i32 %49
}

LLVM IR (-O2):
define i32 @getnum(i32* nocapture %0, i32* nocapture writeonly %1, i8* %2) {
%4 = tail call i32 @getc(i32* %0)
%5 = add i32 %4, -58
%6 = icmp ult i32 %5, -10
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @badinput(i8* %2)
br label %9
9: ; preds = %3, %7
%10 = add nsw i32 %4, -48
%11 = tail call i32 @getc(i32* %0)
%12 = add i32 %11, -48
%13 = icmp ult i32 %12, 10
br i1 %13, label %14, label %28
14: ; preds = %9, %22
%15 = phi i32 [ %26, %22 ], [ %12, %9 ]
%16 = phi i32 [ %25, %22 ], [ %11, %9 ]
%17 = phi i32 [ %24, %22 ], [ %10, %9 ]
%18 = sub nuw nsw i32 429496777, %16
%19 = icmp ult i32 %18, %17
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 @badinput(i8* %2)
br label %22
22: ; preds = %20, %14
%23 = mul i32 %17, 10
%24 = add i32 %15, %23
%25 = tail call i32 @getc(i32* %0)
%26 = add i32 %25, -48
%27 = icmp ult i32 %26, 10
br i1 %27, label %14, label %28
28: ; preds = %22, %9
%29 = phi i32 [ %10, %9 ], [ %24, %22 ]
%30 = phi i32 [ %11, %9 ], [ %25, %22 ]
store i32 %29, i32* %1
ret i32 %30
}