#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*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int strtod(char *, int /*<<< orphan*/ *);
double fraction_to_double(char *fraction) {
  double fraction_as_db;
  char denominator[9];
  char *ptr = strstr(fraction, "/");
  if (ptr) {
    strncpy(denominator, fraction + 2, 5);
    fraction_as_db = 1 / strtod(denominator, NULL);
  } else {
    fraction_as_db = strtod(fraction, NULL);
  }
  return fraction_as_db;
}


x86 assembly (clang, -O0):
<fraction_to_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1196 <fraction_to_double+0x66>
lea    -0x19(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x2,%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
lea    -0x19(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11ac <fraction_to_double+0x7c>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtod@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fraction_to_double>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1179 <fraction_to_double+0x49>
add    $0x2,%rbx
lea    0xf(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <strtod@plt>
lea    0x1(%rax),%ecx
cmp    $0x3,%ecx
cmovb  %eax,%ebx
jmp    1185 <fraction_to_double+0x55>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <strtod@plt>
mov    %eax,%ebx
cvtsi2sd %ebx,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define double @fraction_to_double(i8* %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca [9 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strstr(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i64 2
%14 = call i32 @strncpy(i8* %11, i8* %13, i32 5)
%15 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%16 = call i32 @strtod(i8* %15, i32* null)
%17 = sdiv i32 1, %16
%18 = sitofp i32 %17 to double
store double %18, double* %3
br label %23
19: ; preds = %1
%20 = load i8*, i8** %2
%21 = call i32 @strtod(i8* %20, i32* null)
%22 = sitofp i32 %21 to double
store double %22, double* %3
br label %23
23: ; preds = %19, %10
%24 = load double, double* %3
ret double %24
}

LLVM IR (-O2):
define double @fraction_to_double(i8* %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 2
%8 = call i32 @strncpy(i8* %3, i8* %7, i32 5)
%9 = call i32 @strtod(i8* nocapture %3, i32* null)
%10 = add i32 %9, 1
%11 = icmp ult i32 %10, 3
%12 = select i1 %11, i32 %9, i32 0
br label %15
13: ; preds = %1
%14 = tail call i32 @strtod(i8* nocapture %0, i32* null)
br label %15
15: ; preds = %13, %6
%16 = phi i32 [ %12, %6 ], [ %14, %13 ]
%17 = sitofp i32 %16 to double
ret double %17
}