#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*/ chop(char *);
scalar_t__ errno;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
double strtod(char *, char **);
double readd(char *prompt) {
  char str[20];
  double d;
  char *ep;
  while (true) {
    printf("%s: ", prompt);
    fgets(str, 20, stdin);
    chop(str);
    errno = 0;
    d = strtod(str, &ep);
    if (strlen(str) < 1 || errno || *ep) {
      printf("Sorry, '%s' is not valid. Try again.\n", str);
    } else {
      break;
    }
  }
  return d;
}


x86 assembly (clang, -O0):
<readd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1070 <fgets@plt>
lea    -0x20(%rbp),%rdi
call   1060 <chop@plt>
mov    0x2e45(%rip),%rax
movq   $0x0,(%rax)
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jl     11df <readd+0x8f>
mov    0x2e13(%rip),%rax
cmpq   $0x0,(%rax)
jne    11df <readd+0x8f>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f4 <readd+0xa4>
lea    -0x20(%rbp),%rsi
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
jmp    11f9 <readd+0xa9>
jmp    11fe <readd+0xae>
jmp    115c <readd+0xc>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r15
mov    0x2e80(%rip),%rbp
lea    0x10(%rsp),%rbx
mov    0x2e64(%rip),%r14
lea    0x8(%rsp),%r12
lea    0xe85(%rip),%r13
jmp    119b <readd+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1060 <chop@plt>
movq   $0x0,(%r14)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strtod@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1190 <readd+0x40>
cmpq   $0x0,(%r14)
jne    1190 <readd+0x40>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1190 <readd+0x40>
movsd  (%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@stdin = global i32 0
@errno = global i64 0
@.str.1 = [38 x i8] c"Sorry, '%s' is not valid. Try again.\0A\00"
define double @readd(i8* %0) {
%2 = alloca i8*
%3 = alloca [20 x i8]
%4 = alloca double
%5 = alloca i8*
store i8* %0, i8** %2
br label %6
6: ; preds = %1, %31
%7 = load i8*, i8** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 20, i32 %10)
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = call i32 @chop(i8* %12)
store i64 0, i64* @errno
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%15 = call double @strtod(i8* %14, i8** %5)
store double %15, double* %4
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %17, 1
br i1 %18, label %27, label %19
19: ; preds = %6
%20 = load i64, i64* @errno
%21 = icmp ne i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22, %19, %6
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %31
30: ; preds = %22
br label %32
31: ; preds = %27
br label %6
32: ; preds = %30
%33 = load double, double* %4
ret double %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s: \00"
@stdin = global i32 0
@errno = global i64 0
@.str.1 = [38 x i8] c"Sorry, '%s' is not valid. Try again.\0A\00"
define double @readd(i8* %0) {
%2 = alloca [20 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = bitcast i8** %3 to i8*
br label %6
6: ; preds = %21, %1
%7 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %4, i32 20, i32 %8)
%10 = call i32 @chop(i8* %4)
store i64 0, i64* @errno
%11 = call double @strtod(i8* %4, i8** %3)
%12 = call i32 @strlen(i8* %4)
%13 = icmp slt i32 %12, 1
%14 = load i64, i64* @errno
%15 = icmp ne i64 %14, 0
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %21, label %17
17: ; preds = %6
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17, %6
%22 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %6
23: ; preds = %17
ret double %11
}