#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*/ free(char *);
char *strdup(char const *);
int strlen(char *);
double strtod(char *, int /*<<< orphan*/ *);
void atodx(const char *s, double *d, int *hasx) {
  char *ss = strdup(s);
  int len = strlen(ss);
  if (ss[len - 1] == 'x' || ss[len - 1] == 'X') {
    *hasx = 1;
    ss[len - 1] = 0;
    len--;
  } else
    *hasx = 0;
  *d = strtod(ss, NULL);
  free(ss);
}


x86 assembly (clang, -O0):
<atodx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x78,%eax
je     11a1 <atodx+0x61>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x58,%eax
jne    11ca <atodx+0x8a>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11d4 <atodx+0x94>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atodx>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cltq
mov    -0x1(%rax,%rbx,1),%cl
or     $0x20,%cl
cmp    $0x78,%cl
jne    1177 <atodx+0x37>
movl   $0x1,(%r15)
movb   $0x0,-0x1(%rbx,%rax,1)
jmp    117e <atodx+0x3e>
movl   $0x0,(%r15)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <strtod@plt>
movsd  %xmm0,(%r14)
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @atodx(i8* %0, double* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store double* %1, double** %5
store i32* %2, i32** %6
%9 = load i8*, i8** %4
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %8
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 120
br i1 %20, label %30, label %21
21: ; preds = %3
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 88
br i1 %29, label %30, label %39
30: ; preds = %21, %3
%31 = load i32*, i32** %6
store i32 1, i32* %31
%32 = load i8*, i8** %7
%33 = load i32, i32* %8
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 0, i8* %36
%37 = load i32, i32* %8
%38 = add nsw i32 %37, -1
store i32 %38, i32* %8
br label %41
39: ; preds = %21
%40 = load i32*, i32** %6
store i32 0, i32* %40
br label %41
41: ; preds = %39, %30
%42 = load i8*, i8** %7
%43 = call double @strtod(i8* %42, i32* null)
%44 = load double*, double** %5
store double %43, double* %44
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
ret void
}

LLVM IR (-O2):
define void @atodx(i8* nocapture %0, double* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i32 @strlen(i8* %4)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %11 [
i8 120, label %10
i8 88, label %10
]
10: ; preds = %3, %3
store i32 1, i32* %2
store i8 0, i8* %8
br label %12
11: ; preds = %3
store i32 0, i32* %2
br label %12
12: ; preds = %11, %10
%13 = tail call double @strtod(i8* nocapture %4, i32* null)
store double %13, double* %1
%14 = tail call i32 @free(i8* %4)
ret void
}