#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 */
scalar_t__ EINVAL;
scalar_t__ ERANGE;
int /*<<< orphan*/ EXIT_FAILURE;
double HUGE_VAL;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *);
double strtod(char const *, char **);
double getnum(const char *s) {
  double d;
  char *end;
  errno = 0;
  d = strtod(s, &end);
  if (end && *end != '\0')
    errx(EXIT_FAILURE, ("expected a number, but got '%s'"), s);
  if ((d == HUGE_VAL || d == -HUGE_VAL) && ERANGE == errno)
    err(EXIT_FAILURE, ("divisor '%s'"), s);
  if (!(d == d)) {
    errno = EINVAL;
    err(EXIT_FAILURE, ("divisor '%s'"), s);
  }
  return d;
}


x86 assembly (clang, -O0):
<getnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1190 <getnum+0x60>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1190 <getnum+0x60>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1040 <errx@plt>
movsd  -0x10(%rbp),%xmm0
mov    0x2e4c(%rip),%rax
ucomisd (%rax),%xmm0
jne    11b1 <getnum+0x81>
jp     11b1 <getnum+0x81>
jmp    11e8 <getnum+0xb8>
movsd  -0x10(%rbp),%xmm0
mov    0x2e2b(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    121b <getnum+0xeb>
jp     121b <getnum+0xeb>
mov    0x2df1(%rip),%rax
mov    (%rax),%rax
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%rax
jne    121b <getnum+0xeb>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe0a(%rip),%rsi
call   1050 <err@plt>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1236 <getnum+0x106>
jp     1236 <getnum+0x106>
jmp    1263 <getnum+0x133>
mov    0x2d83(%rip),%rax
mov    (%rax),%rcx
mov    0x2d89(%rip),%rax
mov    %rcx,(%rax)
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdc2(%rip),%rsi
call   1050 <err@plt>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnum>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e8f(%rip),%r14
movq   $0x0,(%r14)
lea    0x10(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     1185 <getnum+0x55>
cmpb   $0x0,(%rax)
je     1185 <getnum+0x55>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdx
movsd  %xmm0,0x8(%rsp)
call   1040 <errx@plt>
movsd  0x8(%rsp),%xmm0
mov    0x2e5c(%rip),%rax
movsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jne    1198 <getnum+0x68>
jnp    11a8 <getnum+0x78>
xorpd  0xe60(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11db <getnum+0xab>
jp     11db <getnum+0xab>
mov    0x2e31(%rip),%rax
mov    (%rax),%rax
cmp    (%r14),%rax
jne    11db <getnum+0xab>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    %rbx,%rdx
movsd  %xmm0,0x8(%rsp)
call   1050 <err@plt>
movsd  0x8(%rsp),%xmm0
ucomisd %xmm0,%xmm0
jp     11e9 <getnum+0xb9>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd0(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdx
movsd  %xmm0,0x8(%rsp)
call   1050 <err@plt>
movsd  0x8(%rsp),%xmm0
jmp    11e1 <getnum+0xb1>

LLVM IR (-O0):
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str = [32 x i8] c"expected a number, but got '%s'\00"
@HUGE_VAL = global double 0.000000e+00
@ERANGE = global i64 0
@.str.1 = [13 x i8] c"divisor '%s'\00"
@EINVAL = global i64 0
define double @getnum(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call double @strtod(i8* %5, i8** %4)
store double %6, double* %3
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* @EXIT_FAILURE
%16 = load i8*, i8** %2
%17 = call i32 @errx(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %14, %9, %1
%19 = load double, double* %3
%20 = load double, double* @HUGE_VAL
%21 = fcmp oeq double %19, %20
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = load double, double* %3
%24 = load double, double* @HUGE_VAL
%25 = fneg double %24
%26 = fcmp oeq double %23, %25
br i1 %26, label %27, label %35
27: ; preds = %22, %18
%28 = load i64, i64* @ERANGE
%29 = load i64, i64* @errno
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* @EXIT_FAILURE
%33 = load i8*, i8** %2
%34 = call i32 @err(i32 %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %31, %27, %22
%36 = load double, double* %3
%37 = load double, double* %3
%38 = fcmp oeq double %36, %37
br i1 %38, label %44, label %39
39: ; preds = %35
%40 = load i64, i64* @EINVAL
store i64 %40, i64* @errno
%41 = load i32, i32* @EXIT_FAILURE
%42 = load i8*, i8** %2
%43 = call i32 @err(i32 %41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %39, %35
%45 = load double, double* %3
ret double %45
}

LLVM IR (-O2):
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str = [32 x i8] c"expected a number, but got '%s'\00"
@HUGE_VAL = global double 0.000000e+00
@ERANGE = global i64 0
@.str.1 = [13 x i8] c"divisor '%s'\00"
@EINVAL = global i64 0
define double @getnum(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call double @strtod(i8* %0, i8** %2)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @errx(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %10, %7, %1
%14 = load double, double* @HUGE_VAL
%15 = fcmp oeq double %4, %14
%16 = fneg double %14
%17 = fcmp oeq double %4, %16
%18 = or i1 %15, %17
br i1 %18, label %19, label %26
19: ; preds = %13
%20 = load i64, i64* @ERANGE
%21 = load i64, i64* @errno
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @err(i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %26
26: ; preds = %13, %23, %19
%27 = fcmp ord double %4, 0.000000e+00
br i1 %27, label %32, label %28
28: ; preds = %26
%29 = load i64, i64* @EINVAL
store i64 %29, i64* @errno
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @err(i32 %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %32
32: ; preds = %28, %26
ret double %4
}