#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 */
double atof(char *);
int strlen(char *);
double atofp(char *s) {
  char last;
  int len;
  double suff = 1.0;
  len = strlen(s);
  last = s[len - 1];
  s[len - 1] = '\0';
  switch (last) {
  case '%':
    suff *= 0.01;
    suff *= atof(s);
    s[len - 1] = last;
    return suff;
  }
  s[len - 1] = last;
  return atof(s);
}


x86 assembly (clang, -O0):
<atofp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movabs $0x3ff0000000000000,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x11(%rbp),%al
sub    $0x25,%al
jne    11c1 <atofp+0xa1>
jmp    117a <atofp+0x5a>
movsd  0xe7e(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <atof@plt>
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e2 <atofp+0xc2>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atofp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
movslq %eax,%r14
mov    -0x1(%r14,%rbx,1),%al
movb   $0x0,-0x1(%r14,%rbx,1)
cmp    $0x25,%al
jne    115c <atofp+0x3c>
mov    %rbx,%rdi
call   1030 <atof@plt>
mulsd  0xeb2(%rip),%xmm0
movb   $0x25,-0x1(%rbx,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %al,-0x1(%rbx,%r14,1)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <atof@plt>

LLVM IR (-O0):
define double @atofp(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca double
store i8* %0, i8** %3
store double 1.000000e+00, double* %6
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i8*, i8** %3
%10 = load i32, i32* %5
%11 = sub nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* %4
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
store i8 0, i8* %19
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
switch i32 %21, label %36 [
i32 37, label %22
]
22: ; preds = %1
%23 = load double, double* %6
%24 = fmul double %23, 1.000000e-02
store double %24, double* %6
%25 = load i8*, i8** %3
%26 = call double @atof(i8* %25)
%27 = load double, double* %6
%28 = fmul double %27, %26
store double %28, double* %6
%29 = load i8, i8* %4
%30 = load i8*, i8** %3
%31 = load i32, i32* %5
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
%35 = load double, double* %6
store double %35, double* %2
br label %45
36: ; preds = %1
%37 = load i8, i8* %4
%38 = load i8*, i8** %3
%39 = load i32, i32* %5
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8 %37, i8* %42
%43 = load i8*, i8** %3
%44 = call double @atof(i8* %43)
store double %44, double* %2
br label %45
45: ; preds = %36, %22
%46 = load double, double* %2
ret double %46
}

LLVM IR (-O2):
define double @atofp(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
store i8 0, i8* %5
%7 = icmp eq i8 %6, 37
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call double @atof(i8* %0)
%10 = fmul double %9, 1.000000e-02
store i8 37, i8* %5
br label %13
11: ; preds = %1
store i8 %6, i8* %5
%12 = tail call double @atof(i8* %0)
br label %13
13: ; preds = %11, %8
%14 = phi double [ %10, %8 ], [ %12, %11 ]
ret double %14
}