#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 sscanf(char const *, char *, double *, char *, char *);
int /*<<< orphan*/ suicidef(char *, char const *);
double pct_string_to_double(const char *s) {
  double v;
  char pct, extra;
  if ((sscanf(s, "%lf%c%c", &v, &pct, &extra) != 2) || (pct != '%'))
    suicidef("\"%s\" is not a percentage", s);
  return v / 100.0;
}


x86 assembly (clang, -O0):
<pct_string_to_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed1(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x11(%rbp),%rcx
lea    -0x12(%rbp),%r8
call   1040 <sscanf@plt>
cmp    $0x2,%eax
jne    115e <pct_string_to_double+0x3e>
movsbl -0x11(%rbp),%eax
cmp    $0x25,%eax
je     116e <pct_string_to_double+0x4e>
mov    -0x8(%rbp),%rsi
lea    0xea7(%rip),%rdi
call   1030 <suicidef@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe85(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pct_string_to_double>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xed9(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x6(%rsp),%rcx
lea    0x7(%rsp),%r8
call   1040 <sscanf@plt>
cmp    $0x2,%eax
jne    114f <pct_string_to_double+0x2f>
cmpb   $0x25,0x6(%rsp)
je     115e <pct_string_to_double+0x3e>
lea    0xeba(%rip),%rdi
mov    %rbx,%rsi
call   1030 <suicidef@plt>
movsd  0x8(%rsp),%xmm0
divsd  0xe94(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%lf%c%c\00"
@.str.1 = [25 x i8] c"\22%s\22 is not a percentage\00"
define double @pct_string_to_double(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca i8
%5 = alloca i8
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double* %3, i8* %4, i8* %5)
%8 = icmp ne i32 %7, 2
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i8, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 37
br i1 %12, label %13, label %16
13: ; preds = %9, %1
%14 = load i8*, i8** %2
%15 = call i32 @suicidef(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %9
%17 = load double, double* %3
%18 = fdiv double %17, 1.000000e+02
ret double %18
}

LLVM IR (-O2):
@.str = [8 x i8] c"%lf%c%c\00"
@.str.1 = [25 x i8] c"\22%s\22 is not a percentage\00"
define double @pct_string_to_double(i8* %0) {
%2 = alloca double
%3 = alloca i8
%4 = alloca i8
%5 = bitcast double* %2 to i8*
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double* %2, i8* %3, i8* %4)
%7 = icmp ne i32 %6, 2
%8 = load i8, i8* %3
%9 = icmp ne i8 %8, 37
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @suicidef(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %1, %11
%14 = load double, double* %2
%15 = fdiv double %14, 1.000000e+02
ret double %15
}