#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ chop(char *);
scalar_t__ errno;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
double strtod(char *, char **);
double get_length(char *name, char *arg) {
  char buf[128];
  double length;
  char *ep;
  while (true) {
    if (!arg) {
      printf("Enter the %s: ", name);
      fgets(buf, sizeof(buf), stdin);
      chop(buf);
    } else {
      strcpy(buf, arg);
    }
    arg = NULL;
    errno = 0;
    length = strtod(buf, &ep);
    if (strlen(buf) < 1 || errno || *ep) {
      printf("'%s' is not a valid length. Try again.\n", buf);
    } else if (length < 0) {
      printf("The length cannot be negative. Try again.\n");
    } else {
      break;
    }
  }
  return length;
}


x86 assembly (clang, -O0):
<get_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bb <get_length+0x5b>
mov    -0x8(%rbp),%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1080 <fgets@plt>
lea    -0x90(%rbp),%rdi
call   1070 <chop@plt>
jmp    11cb <get_length+0x6b>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movq   $0x0,-0x10(%rbp)
mov    0x2dfe(%rip),%rax
movq   $0x0,(%rax)
lea    -0x90(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1040 <strtod@plt>
movsd  %xmm0,-0x98(%rbp)
ff
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jl     1235 <get_length+0xd5>
mov    0x2dc0(%rip),%rax
cmpq   $0x0,(%rax)
jne    1235 <get_length+0xd5>
mov    -0xa0(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124f <get_length+0xef>
lea    -0x90(%rbp),%rsi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    127d <get_length+0x11d>
xorps  %xmm0,%xmm0
ucomisd -0x98(%rbp),%xmm0
ff
jbe    1273 <get_length+0x113>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1278 <get_length+0x118>
jmp    1282 <get_length+0x122>
jmp    127d <get_length+0x11d>
jmp    1173 <get_length+0x13>
movsd  -0x98(%rbp),%xmm0
ff
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_length>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rdi,%r15
mov    0x2e5d(%rip),%rbp
lea    0x10(%rsp),%rbx
mov    0x2e41(%rip),%r14
lea    0x8(%rsp),%r12
lea    0xe74(%rip),%r13
test   %rsi,%rsi
je     11c0 <get_length+0x50>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    11e9 <get_length+0x79>
nopw   0x0(%rax,%rax,1)
lea    0xe41(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   1080 <chop@plt>
movq   $0x0,(%r14)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strtod@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    121c <get_length+0xac>
cmpq   $0x0,(%r14)
jne    121c <get_length+0xac>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1240 <get_length+0xd0>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %esi,%esi
test   %rsi,%rsi
jne    11b0 <get_length+0x40>
jmp    11c0 <get_length+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorpd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
jbe    125d <get_length+0xed>
lea    0xde9(%rip),%rdi
call   1040 <puts@plt>
jmp    1229 <get_length+0xb9>
movapd %xmm1,%xmm0
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Enter the %s: \00"
@stdin = global i32 0
@errno = global i64 0
@.str.1 = [40 x i8] c"'%s' is not a valid length. Try again.\0A\00"
@.str.2 = [43 x i8] c"The length cannot be negative. Try again.\0A\00"
define double @get_length(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca double
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %8
8: ; preds = %2, %47
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %19, label %11
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %14, i32 128, i32 %15)
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%18 = call i32 @chop(i8* %17)
br label %23
19: ; preds = %8
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = call i32 @strcpy(i8* %20, i8* %21)
br label %23
23: ; preds = %19, %11
store i8* null, i8** %4
store i64 0, i64* @errno
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%25 = call double @strtod(i8* %24, i8** %7)
store double %25, double* %6
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = icmp slt i32 %27, 1
br i1 %28, label %37, label %29
29: ; preds = %23
%30 = load i64, i64* @errno
%31 = icmp ne i64 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32, %29, %23
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %47
40: ; preds = %32
%41 = load double, double* %6
%42 = fcmp olt double %41, 0.000000e+00
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %46
45: ; preds = %40
br label %48
46: ; preds = %43
br label %47
47: ; preds = %46, %37
br label %8
48: ; preds = %45
%49 = load double, double* %6
ret double %49
}

LLVM IR (-O2):
@.str = [15 x i8] c"Enter the %s: \00"
@stdin = global i32 0
@errno = global i64 0
@.str.1 = [40 x i8] c"'%s' is not a valid length. Try again.\0A\00"
@str = [42 x i8] c"The length cannot be negative. Try again.\00"
define double @get_length(i8* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
br label %7
7: ; preds = %34, %2
%8 = phi i8* [ %1, %2 ], [ null, %34 ]
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %5, i32 128, i32 %12)
%14 = call i32 @chop(i8* %5)
br label %17
15: ; preds = %7
%16 = call i32 @strcpy(i8* %5, i8* %8)
br label %17
17: ; preds = %15, %10
store i64 0, i64* @errno
%18 = call double @strtod(i8* %5, i8** %4)
%19 = call i32 @strlen(i8* %5)
%20 = icmp slt i32 %19, 1
%21 = load i64, i64* @errno
%22 = icmp ne i64 %21, 0
%23 = select i1 %20, i1 true, i1 %22
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24, %17
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %34
30: ; preds = %24
%31 = fcmp olt double %18, 0.000000e+00
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
br label %7
35: ; preds = %30
ret double %18
}