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

/* Variables and functions */
int DBL_MAX_10_EXP;
int EOF;
int /*<<< orphan*/ chomp();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int);
int getchar();
scalar_t__ isspace(int);
int log(int);
scalar_t__ match(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
double strtod(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/);
int getnum(double *d, char *dptr, regex_t *numre, FILE *errlog) {
  int c;
  unsigned e;
  chomp();
  for (e = 0; e < (DBL_MAX_10_EXP * (log(10) / log(2)) + 1) &&
              (c = getchar()) != EOF && !isspace(c);
       ++e)
    dptr[e] = c;
  dptr[e] = '\0';
  if ((c == EOF || isspace(c)) && match(dptr, numre, errlog)) {
    ungetc(c, stdin);
    *d = strtod(dptr, NULL);
    return 1;
  } else if (c == EOF)
    return 0;
  else {
    if (e == (DBL_MAX_10_EXP * (log(10) / log(2)) + 1))
      fprintf(errlog, "getnum(): input string exceeds maxstr: [%s%c]\n", dptr,
              c);
    else
      fprintf(errlog, "getnum(): bad number: [%s%c]\n", dptr, c);
    while (!isspace(c) && (c = getchar()) != EOF)
      ;
    ungetc(c, stdin);
    return 0;
  }
}


x86 assembly (clang, -O0):
<getnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x0,%al
call   1090 <chomp@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0xa,%edi
call   10a0 <log@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x2,%edi
call   10a0 <log@plt>
mov    -0x40(%rbp),%ecx
mov    %eax,%esi
mov    -0x3c(%rbp),%eax
cltd
idiv   %esi
mov    -0x38(%rbp),%edx
imul   %eax,%edx
add    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x31(%rbp)
jae    1224 <getnum+0xa4>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
xor    %eax,%eax
mov    0x2dd3(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x31(%rbp)
je     1224 <getnum+0xa4>
mov    -0x2c(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1234 <getnum+0xb4>
jmp    1251 <getnum+0xd1>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a6 <getnum+0x26>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
mov    0x2d72(%rip),%rcx
cmp    (%rcx),%eax
je     1280 <getnum+0x100>
mov    -0x2c(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     12cd <getnum+0x14d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <match@plt>
cmp    $0x0,%rax
je     12cd <getnum+0x14d>
mov    -0x2c(%rbp),%edi
mov    0x2d3b(%rip),%rax
mov    (%rax),%esi
call   1070 <ungetc@plt>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    13ca <getnum+0x24a>
mov    -0x2c(%rbp),%eax
mov    0x2d01(%rip),%rcx
cmp    (%rcx),%eax
jne    12eb <getnum+0x16b>
movl   $0x0,-0x4(%rbp)
jmp    13ca <getnum+0x24a>
mov    -0x30(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2cf8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    $0xa,%edi
call   10a0 <log@plt>
mov    %eax,-0x48(%rbp)
mov    $0x2,%edi
call   10a0 <log@plt>
mov    -0x4c(%rbp),%ecx
mov    %eax,%esi
mov    -0x48(%rbp),%eax
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x44(%rbp),%eax
imul   %edx,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    134e <getnum+0x1ce>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    0xcbc(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1365 <getnum+0x1e5>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    0xccf(%rip),%rsi
call   1060 <fprintf@plt>
jmp    136a <getnum+0x1ea>
mov    -0x2c(%rbp),%edi
call   1040 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x4d(%rbp)
jne    139d <getnum+0x21d>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2c43(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    13ad <getnum+0x22d>
jmp    13b2 <getnum+0x232>
jmp    136a <getnum+0x1ea>
mov    -0x2c(%rbp),%edi
mov    0x2c24(%rip),%rax
mov    (%rax),%esi
call   1070 <ungetc@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
mov    %rdi,0x8(%rsp)
xor    %eax,%eax
call   1090 <chomp@plt>
mov    $0xa,%edi
call   10a0 <log@plt>
mov    $0x2,%edi
call   10a0 <log@plt>
mov    0x2e2f(%rip),%r12
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
mov    0x2df8(%rip),%rax
cmp    (%rax),%ebp
je     1226 <getnum+0xa6>
mov    %ebp,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1226 <getnum+0xa6>
mov    %bpl,0x0(%r13,%r14,1)
add    $0x1,%r14
mov    (%r12),%r15d
mov    $0xa,%edi
call   10a0 <log@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   10a0 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
imul   %r15d,%eax
add    $0x1,%eax
cmp    %rax,%r14
jb     11d0 <getnum+0x50>
mov    %r14d,%eax
movb   $0x0,0x0(%r13,%rax,1)
mov    0x2da2(%rip),%rax
cmp    (%rax),%ebp
je     1246 <getnum+0xc6>
mov    %ebp,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1289 <getnum+0x109>
mov    %r13,%rdi
mov    0x10(%rsp),%rsi
mov    (%rsp),%rdx
call   1080 <match@plt>
test   %rax,%rax
je     1289 <getnum+0x109>
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <ungetc@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
mov    0x8(%rsp),%rax
movsd  %xmm0,(%rax)
mov    $0x1,%eax
jmp    1322 <getnum+0x1a2>
xor    %eax,%eax
mov    0x2d46(%rip),%rcx
cmp    (%rcx),%ebp
je     1322 <getnum+0x1a2>
mov    (%r12),%r15d
mov    $0xa,%edi
call   10a0 <log@plt>
mov    %eax,%ebx
mov    $0x2,%edi
call   10a0 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
imul   %r15d,%eax
add    $0x1,%eax
cmp    %r14d,%eax
lea    0xd34(%rip),%rax
lea    0xd5c(%rip),%rsi
cmove  %rax,%rsi
mov    (%rsp),%rdi
mov    %r13,%rdx
mov    %ebp,%ecx
call   1060 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1310 <getnum+0x190>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
mov    0x2ccc(%rip),%rax
cmp    (%rax),%ebp
jne    12f0 <getnum+0x170>
mov    0x2cc9(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <ungetc@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DBL_MAX_10_EXP = global i32 0
@EOF = global i32 0
@stdin = global i32 0
@.str = [47 x i8] c"getnum(): input string exceeds maxstr: [%s%c]\0A\00"
@.str.1 = [30 x i8] c"getnum(): bad number: [%s%c]\0A\00"
define i32 @getnum(double* %0, i8* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store double* %0, double** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%12 = call i32 (...) @chomp()
store i32 0, i32* %11
br label %13
13: ; preds = %40, %4
%14 = load i32, i32* %11
%15 = load i32, i32* @DBL_MAX_10_EXP
%16 = call i32 @log(i32 10)
%17 = call i32 @log(i32 2)
%18 = sdiv i32 %16, %17
%19 = mul nsw i32 %15, %18
%20 = add nsw i32 %19, 1
%21 = icmp ult i32 %14, %20
br i1 %21, label %22, label %31
22: ; preds = %13
%23 = call i32 (...) @getchar()
store i32 %23, i32* %10
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* %10
%28 = call i64 @isspace(i32 %27)
%29 = icmp ne i64 %28, 0
%30 = xor i1 %29, true
br label %31
31: ; preds = %26, %22, %13
%32 = phi i1 [ false, %22 ], [ false, %13 ], [ %30, %26 ]
br i1 %32, label %33, label %43
33: ; preds = %31
%34 = load i32, i32* %10
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %7
%37 = load i32, i32* %11
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 %35, i8* %39
br label %40
40: ; preds = %33
%41 = load i32, i32* %11
%42 = add i32 %41, 1
store i32 %42, i32* %11
br label %13
43: ; preds = %31
%44 = load i8*, i8** %7
%45 = load i32, i32* %11
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
%48 = load i32, i32* %10
%49 = load i32, i32* @EOF
%50 = icmp eq i32 %48, %49
br i1 %50, label %55, label %51
51: ; preds = %43
%52 = load i32, i32* %10
%53 = call i64 @isspace(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %68
55: ; preds = %51, %43
%56 = load i8*, i8** %7
%57 = load i32*, i32** %8
%58 = load i32*, i32** %9
%59 = call i64 @match(i8* %56, i32* %57, i32* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %55
%62 = load i32, i32* %10
%63 = load i32, i32* @stdin
%64 = call i32 @ungetc(i32 %62, i32 %63)
%65 = load i8*, i8** %7
%66 = call double @strtod(i8* %65, i32* null)
%67 = load double*, double** %6
store double %66, double* %67
store i32 1, i32* %5
br label %108
68: ; preds = %55, %51
%69 = load i32, i32* %10
%70 = load i32, i32* @EOF
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %73
72: ; preds = %68
store i32 0, i32* %5
br label %108
73: ; preds = %68
%74 = load i32, i32* %11
%75 = load i32, i32* @DBL_MAX_10_EXP
%76 = call i32 @log(i32 10)
%77 = call i32 @log(i32 2)
%78 = sdiv i32 %76, %77
%79 = mul nsw i32 %75, %78
%80 = add nsw i32 %79, 1
%81 = icmp eq i32 %74, %80
br i1 %81, label %82, label %87
82: ; preds = %73
%83 = load i32*, i32** %9
%84 = load i8*, i8** %7
%85 = load i32, i32* %10
%86 = call i32 @fprintf(i32* %83, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %84, i32 %85)
br label %92
87: ; preds = %73
%88 = load i32*, i32** %9
%89 = load i8*, i8** %7
%90 = load i32, i32* %10
%91 = call i32 @fprintf(i32* %88, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %89, i32 %90)
br label %92
92: ; preds = %87, %82
br label %93
93: ; preds = %103, %92
%94 = load i32, i32* %10
%95 = call i64 @isspace(i32 %94)
%96 = icmp ne i64 %95, 0
br i1 %96, label %101, label %97
97: ; preds = %93
%98 = call i32 (...) @getchar()
store i32 %98, i32* %10
%99 = load i32, i32* @EOF
%100 = icmp ne i32 %98, %99
br label %101
101: ; preds = %97, %93
%102 = phi i1 [ false, %93 ], [ %100, %97 ]
br i1 %102, label %103, label %104
103: ; preds = %101
br label %93
104: ; preds = %101
%105 = load i32, i32* %10
%106 = load i32, i32* @stdin
%107 = call i32 @ungetc(i32 %105, i32 %106)
store i32 0, i32* %5
br label %108
108: ; preds = %104, %72, %61
%109 = load i32, i32* %5
ret i32 %109
}

LLVM IR (-O2):
@DBL_MAX_10_EXP = global i32 0
@EOF = global i32 0
@stdin = global i32 0
@.str = [47 x i8] c"getnum(): input string exceeds maxstr: [%s%c]\0A\00"
@.str.1 = [30 x i8] c"getnum(): bad number: [%s%c]\0A\00"
define i32 @getnum(double* nocapture writeonly %0, i8* %1, i32* %2, i32* %3) {
%5 = tail call i32 (...) @chomp()
%6 = load i32, i32* @DBL_MAX_10_EXP
%7 = tail call i32 @log(i32 10)
%8 = tail call i32 @log(i32 2)
%9 = sdiv i32 %7, %8
%10 = mul nsw i32 %9, %6
%11 = icmp ne i32 %10, -1
br label %12
12: ; preds = %4, %20
%13 = phi i64 [ %23, %20 ], [ 0, %4 ]
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %32, label %17
17: ; preds = %12
%18 = tail call i64 @isspace(i32 %14)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %17
%21 = trunc i32 %14 to i8
%22 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %21, i8* %22
%23 = add nuw nsw i64 %13, 1
%24 = load i32, i32* @DBL_MAX_10_EXP
%25 = tail call i32 @log(i32 10)
%26 = tail call i32 @log(i32 2)
%27 = sdiv i32 %25, %26
%28 = mul nsw i32 %27, %24
%29 = add nsw i32 %28, 1
%30 = zext i32 %29 to i64
%31 = icmp ult i64 %23, %30
br i1 %31, label %12, label %32
32: ; preds = %17, %12, %20
%33 = phi i64 [ %13, %17 ], [ %13, %12 ], [ %23, %20 ]
%34 = trunc i64 %33 to i32
%35 = and i64 %33, 4294967295
%36 = getelementptr inbounds i8, i8* %1, i64 %35
store i8 0, i8* %36
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %14, %37
br i1 %38, label %42, label %39
39: ; preds = %32
%40 = tail call i64 @isspace(i32 %14)
%41 = icmp eq i64 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %39, %32
%43 = tail call i64 @match(i8* %1, i32* %2, i32* %3)
%44 = icmp eq i64 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %42
%46 = load i32, i32* @stdin
%47 = tail call i32 @ungetc(i32 %14, i32 %46)
%48 = tail call double @strtod(i8* nocapture %1, i32* null)
store double %48, double* %0
br label %74
49: ; preds = %42, %39
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %14, %50
br i1 %51, label %74, label %52
52: ; preds = %49
%53 = load i32, i32* @DBL_MAX_10_EXP
%54 = tail call i32 @log(i32 10)
%55 = tail call i32 @log(i32 2)
%56 = sdiv i32 %54, %55
%57 = mul nsw i32 %56, %53
%58 = add nsw i32 %57, 1
%59 = icmp eq i32 %58, %34
%60 = select i1 %59, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0)
%61 = tail call i32 @fprintf(i32* %3, i8* %60, i8* %1, i32 %14)
br label %62
62: ; preds = %66, %52
%63 = phi i32 [ %14, %52 ], [ %67, %66 ]
%64 = tail call i64 @isspace(i32 %63)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = tail call i32 (...) @getchar()
%68 = load i32, i32* @EOF
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %62
70: ; preds = %62, %66
%71 = phi i32 [ %63, %62 ], [ %67, %66 ]
%72 = load i32, i32* @stdin
%73 = tail call i32 @ungetc(i32 %71, i32 %72)
br label %74
74: ; preds = %49, %70, %45
%75 = phi i32 [ 1, %45 ], [ 0, %70 ], [ 0, %49 ]
ret i32 %75
}